SettingPanel.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. public Text sliderText;
  12. public Slider filterSlider;
  13. public Text redSliderText;
  14. public Slider redFilterSlider;
  15. int selectIndex = 0;
  16. //void Awake()
  17. //{
  18. //}
  19. public void onSettingPanel_Init() {
  20. int tempIndex = PlayerPrefs.GetInt("resolutionSelectIndex", 0);
  21. selectIndex = tempIndex;
  22. Debug.Log("onSettingPanel_Init selectIndex:" + tempIndex);
  23. selectvalue(selectIndex);
  24. float filterValue = PlayerPrefs.GetFloat("filterSliderValue", 3.0f);
  25. Debug.Log("onSettingPanel_Init filterValue:" + filterValue);
  26. filterSlider.value = filterValue;
  27. setSliderText(filterValue);
  28. filterSlider.onValueChanged.AddListener(setFilterSliderValue);
  29. float redfilterValue = PlayerPrefs.GetFloat("redFilterSliderValue", 0.8f);
  30. Debug.Log("red filterValue:" + redfilterValue);
  31. redFilterSlider.value = redfilterValue;
  32. setRedSliderText(redfilterValue);
  33. redFilterSlider.onValueChanged.AddListener(setRedFilterSliderValue);
  34. }
  35. void Start()
  36. {
  37. //宽屏 设置几个宽屏分辨率
  38. //List<string> temp = new List<string> { "1280x720", "1024x600", "800x480", "400x240" };
  39. //dropdown.AddOptions(temp);
  40. dropdown.options.Add(new Dropdown.OptionData("1280x720")); //WXGA
  41. dropdown.options.Add(new Dropdown.OptionData("640x480")); //VGA
  42. dropdown.options.Add(new Dropdown.OptionData("320x240")); //QVGA
  43. dropdown.value = selectIndex;
  44. //Debug.Log("dropdown.value:" + dropdown.value);
  45. dropdown.onValueChanged.AddListener(delegate
  46. {
  47. selectvalue(dropdown.value);
  48. });
  49. }
  50. private void selectvalue(int value)
  51. {
  52. switch (value)
  53. {
  54. case 0:
  55. setSize(1280, 720);
  56. break;
  57. case 1:
  58. setSize(640, 480);
  59. break;
  60. case 2:
  61. setSize(320, 240);
  62. break;
  63. default:
  64. setSize(1280, 720);
  65. break;
  66. }
  67. selectIndex = value;
  68. //Debug.Log(selectIndex);
  69. }
  70. void setSize(int width,int height) {
  71. uVCManager.DefaultWidth = width;
  72. uVCManager.DefaultHeight = height;
  73. uVCDrawer.DefaultWidth = width;
  74. uVCDrawer.DefaultHeight = height;
  75. }
  76. public void openSettingPanel() {
  77. gameObject.SetActive(true);
  78. }
  79. public void backEvent() {
  80. gameObject.SetActive(false);
  81. }
  82. public void restartEvent() {
  83. PlayerPrefs.SetInt("resolutionSelectIndex", selectIndex);
  84. PlayerPrefs.Save();
  85. Debug.Log("restartEvent:"+selectIndex);
  86. if (!Application.isEditor) {
  87. StartCoroutine(RestartOrKillApp());
  88. };
  89. }
  90. IEnumerator RestartOrKillApp()
  91. {
  92. yield return new WaitForSeconds(0.3f);
  93. if (Application.platform == RuntimePlatform.Android)
  94. {
  95. using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
  96. {
  97. const int kIntent_FLAG_ACTIVITY_CLEAR_TASK = 0x00008000;
  98. const int kIntent_FLAG_ACTIVITY_NEW_TASK = 0x10000000;
  99. var currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
  100. var pm = currentActivity.Call<AndroidJavaObject>("getPackageManager");
  101. var intent = pm.Call<AndroidJavaObject>("getLaunchIntentForPackage", Application.identifier);
  102. intent.Call<AndroidJavaObject>("setFlags", kIntent_FLAG_ACTIVITY_NEW_TASK | kIntent_FLAG_ACTIVITY_CLEAR_TASK);
  103. currentActivity.Call("startActivity", intent);
  104. currentActivity.Call("finish");
  105. var process = new AndroidJavaClass("android.os.Process");
  106. int pid = process.CallStatic<int>("myPid");
  107. process.CallStatic("killProcess", pid);
  108. }
  109. }
  110. else
  111. {
  112. Application.Quit();
  113. }
  114. }
  115. //过滤值
  116. public void setFilterSliderValue(float value) {
  117. Debug.Log("滑动进度条:" + value);
  118. setSliderText(value);
  119. PlayerPrefs.SetFloat("filterSliderValue", value);
  120. PlayerPrefs.Save();
  121. }
  122. void setSliderText(float value) {
  123. ScreenLocate.Main.filterDis = value;
  124. sliderText.text = value + "";
  125. Debug.Log("当前过滤阈值 filter dis:"+ ScreenLocate.Main.filterDis);
  126. }
  127. public void setRedFilterSliderValue(float value)
  128. {
  129. Debug.Log("red滑动进度条:" + value);
  130. setRedSliderText(value);
  131. PlayerPrefs.SetFloat("redFilterSliderValue", value);
  132. PlayerPrefs.Save();
  133. }
  134. void setRedSliderText(float value)
  135. {
  136. ScreenLocate.Main.SetInfraredLocateBrightnessThreshold(value);
  137. redSliderText.text = value + "";
  138. Debug.Log("当前红外线阈值 BrightnessThreshold:" + value);
  139. }
  140. }