SettingPanel.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using Serenegiant.UVC;
  6. public class SettingPanel : MonoBehaviour
  7. {
  8. public Dropdown dropdown;
  9. public UVCManager uVCManager;
  10. public UVCDrawer uVCDrawer;
  11. int selectIndex = 0;
  12. //void Awake()
  13. //{
  14. //}
  15. public void onSettingPanel_Init() {
  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. uVCManager.DefaultWidth = width;
  58. uVCManager.DefaultHeight = height;
  59. uVCDrawer.DefaultWidth = width;
  60. uVCDrawer.DefaultHeight = height;
  61. }
  62. public void openSettingPanel() {
  63. gameObject.SetActive(true);
  64. }
  65. public void backEvent() {
  66. gameObject.SetActive(false);
  67. }
  68. public void restartEvent() {
  69. PlayerPrefs.SetInt("resolutionSelectIndex", selectIndex);
  70. PlayerPrefs.Save();
  71. Debug.Log("restartEvent:"+selectIndex);
  72. if (!Application.isEditor) {
  73. StartCoroutine(RestartOrKillApp());
  74. };
  75. }
  76. IEnumerator RestartOrKillApp()
  77. {
  78. yield return new WaitForSeconds(0.3f);
  79. if (Application.platform == RuntimePlatform.Android)
  80. {
  81. using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
  82. {
  83. const int kIntent_FLAG_ACTIVITY_CLEAR_TASK = 0x00008000;
  84. const int kIntent_FLAG_ACTIVITY_NEW_TASK = 0x10000000;
  85. var currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
  86. var pm = currentActivity.Call<AndroidJavaObject>("getPackageManager");
  87. var intent = pm.Call<AndroidJavaObject>("getLaunchIntentForPackage", Application.identifier);
  88. intent.Call<AndroidJavaObject>("setFlags", kIntent_FLAG_ACTIVITY_NEW_TASK | kIntent_FLAG_ACTIVITY_CLEAR_TASK);
  89. currentActivity.Call("startActivity", intent);
  90. currentActivity.Call("finish");
  91. var process = new AndroidJavaClass("android.os.Process");
  92. int pid = process.CallStatic<int>("myPid");
  93. process.CallStatic("killProcess", pid);
  94. }
  95. }
  96. else
  97. {
  98. Application.Quit();
  99. }
  100. }
  101. }