| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using Serenegiant.UVC;
- public class SettingPanel : MonoBehaviour
- {
- public Dropdown dropdown;
- public UVCManager uVCManager;
- public UVCDrawer uVCDrawer;
- public Text sliderText;
- public Slider filterSlider;
- int selectIndex = 0;
- //void Awake()
- //{
-
- //}
- public void onSettingPanel_Init() {
- int tempIndex = PlayerPrefs.GetInt("resolutionSelectIndex", 0);
- selectIndex = tempIndex;
- Debug.Log("onSettingPanel_Init selectIndex:" + tempIndex);
- selectvalue(selectIndex);
- float filterValue = PlayerPrefs.GetFloat("filterSliderValue", 3.0f);
- Debug.Log("onSettingPanel_Init filterValue:" + filterValue);
- filterSlider.value = filterValue;
- setSliderText(filterValue);
- filterSlider.onValueChanged.AddListener(setFilterSliderValue);
- }
- void Start()
- {
- //宽屏 设置几个宽屏分辨率
- //List<string> temp = new List<string> { "1280x720", "1024x600", "800x480", "400x240" };
- //dropdown.AddOptions(temp);
- dropdown.options.Add(new Dropdown.OptionData("1280x720")); //WXGA
- dropdown.options.Add(new Dropdown.OptionData("640x480")); //VGA
- dropdown.options.Add(new Dropdown.OptionData("320x240")); //QVGA
- dropdown.value = selectIndex;
- //Debug.Log("dropdown.value:" + dropdown.value);
- dropdown.onValueChanged.AddListener(delegate
- {
- selectvalue(dropdown.value);
- });
- }
- private void selectvalue(int value)
- {
-
- switch (value)
- {
- case 0:
- setSize(1280, 720);
- break;
- case 1:
- setSize(640, 480);
- break;
- case 2:
- setSize(320, 240);
- break;
- default:
- setSize(1280, 720);
- break;
- }
- selectIndex = value;
- //Debug.Log(selectIndex);
- }
- void setSize(int width,int height) {
- uVCManager.DefaultWidth = width;
- uVCManager.DefaultHeight = height;
- uVCDrawer.DefaultWidth = width;
- uVCDrawer.DefaultHeight = height;
- }
- public void openSettingPanel() {
- gameObject.SetActive(true);
- }
- public void backEvent() {
- gameObject.SetActive(false);
- }
- public void restartEvent() {
- PlayerPrefs.SetInt("resolutionSelectIndex", selectIndex);
- PlayerPrefs.Save();
- Debug.Log("restartEvent:"+selectIndex);
- if (!Application.isEditor) {
- StartCoroutine(RestartOrKillApp());
- };
- }
- IEnumerator RestartOrKillApp()
- {
- yield return new WaitForSeconds(0.3f);
- if (Application.platform == RuntimePlatform.Android)
- {
- using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
- {
- const int kIntent_FLAG_ACTIVITY_CLEAR_TASK = 0x00008000;
- const int kIntent_FLAG_ACTIVITY_NEW_TASK = 0x10000000;
- var currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
- var pm = currentActivity.Call<AndroidJavaObject>("getPackageManager");
- var intent = pm.Call<AndroidJavaObject>("getLaunchIntentForPackage", Application.identifier);
- intent.Call<AndroidJavaObject>("setFlags", kIntent_FLAG_ACTIVITY_NEW_TASK | kIntent_FLAG_ACTIVITY_CLEAR_TASK);
- currentActivity.Call("startActivity", intent);
- currentActivity.Call("finish");
- var process = new AndroidJavaClass("android.os.Process");
- int pid = process.CallStatic<int>("myPid");
- process.CallStatic("killProcess", pid);
- }
- }
- else
- {
- Application.Quit();
- }
- }
- //过滤值
- public void setFilterSliderValue(float value) {
- Debug.Log("滑动进度条:" + value);
- setSliderText(value);
- PlayerPrefs.SetFloat("filterSliderValue", value);
- PlayerPrefs.Save();
- }
- void setSliderText(float value) {
- ScreenLocate.Main.filterDis = value;
- sliderText.text = value + "";
- Debug.Log("当前过滤阈值 filter dis:"+ ScreenLocate.Main.filterDis);
- }
- }
|