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 temp = new List { "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("currentActivity"); var pm = currentActivity.Call("getPackageManager"); var intent = pm.Call("getLaunchIntentForPackage", Application.identifier); intent.Call("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("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); } }