SettingPanel.cs 4.3 KB

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