SettingPanel.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace InfraredDLLManager
  6. {
  7. public class SettingPanel : MonoBehaviour
  8. {
  9. public Dropdown dropdown;
  10. int selectIndex = 0;
  11. //void Awake()
  12. //{
  13. //}
  14. public void onSettingPanel_Init()
  15. {
  16. int tempIndex = PlayerPrefs.GetInt("resolutionSelectIndex", 0);
  17. selectIndex = tempIndex;
  18. Debug.Log("selectIndex:" + tempIndex);
  19. selectvalue(selectIndex);
  20. }
  21. void Start()
  22. {
  23. //宽屏 设置几个宽屏分辨率
  24. //List<string> temp = new List<string> { "1280x720", "1024x600", "800x480", "400x240" };
  25. //dropdown.AddOptions(temp);
  26. dropdown.options.Add(new Dropdown.OptionData("1280x720")); //WXGA
  27. dropdown.options.Add(new Dropdown.OptionData("640x480")); //VGA
  28. dropdown.options.Add(new Dropdown.OptionData("320x240")); //QVGA
  29. dropdown.value = selectIndex;
  30. //Debug.Log("dropdown.value:" + dropdown.value);
  31. dropdown.onValueChanged.AddListener(delegate
  32. {
  33. selectvalue(dropdown.value);
  34. });
  35. }
  36. private void selectvalue(int value)
  37. {
  38. switch (value)
  39. {
  40. case 0:
  41. setSize(1280, 720);
  42. break;
  43. case 1:
  44. setSize(640, 480);
  45. break;
  46. case 2:
  47. setSize(320, 240);
  48. break;
  49. default:
  50. setSize(1280, 720);
  51. break;
  52. }
  53. selectIndex = value;
  54. //Debug.Log(selectIndex);
  55. }
  56. void setSize(int width, int height)
  57. {
  58. //uVCManager.DefaultWidth = width;
  59. //uVCManager.DefaultHeight = height;
  60. //uVCDrawer.DefaultWidth = width;
  61. //uVCDrawer.DefaultHeight = height;
  62. }
  63. public void openSettingPanel()
  64. {
  65. gameObject.SetActive(true);
  66. }
  67. public void backEvent()
  68. {
  69. gameObject.SetActive(false);
  70. }
  71. public void restartEvent()
  72. {
  73. PlayerPrefs.SetInt("resolutionSelectIndex", selectIndex);
  74. PlayerPrefs.Save();
  75. Debug.Log("restartEvent:" + selectIndex);
  76. if (!Application.isEditor)
  77. {
  78. StartCoroutine(RestartOrKillApp());
  79. };
  80. }
  81. IEnumerator RestartOrKillApp()
  82. {
  83. yield return new WaitForSeconds(0.3f);
  84. if (Application.platform == RuntimePlatform.Android)
  85. {
  86. using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
  87. {
  88. const int kIntent_FLAG_ACTIVITY_CLEAR_TASK = 0x00008000;
  89. const int kIntent_FLAG_ACTIVITY_NEW_TASK = 0x10000000;
  90. var currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
  91. var pm = currentActivity.Call<AndroidJavaObject>("getPackageManager");
  92. var intent = pm.Call<AndroidJavaObject>("getLaunchIntentForPackage", Application.identifier);
  93. intent.Call<AndroidJavaObject>("setFlags", kIntent_FLAG_ACTIVITY_NEW_TASK | kIntent_FLAG_ACTIVITY_CLEAR_TASK);
  94. currentActivity.Call("startActivity", intent);
  95. currentActivity.Call("finish");
  96. var process = new AndroidJavaClass("android.os.Process");
  97. int pid = process.CallStatic<int>("myPid");
  98. process.CallStatic("killProcess", pid);
  99. }
  100. }
  101. else
  102. {
  103. Application.Quit();
  104. }
  105. }
  106. }
  107. }