123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- using Newtonsoft.Json;
- using SUIFW;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class SystemSettingForms : BaseUIForms
- {
- public Toggle cameraToggle;
- public Toggle micToggle;
- public Transform ToggleGroupTran;
- private Toggle[] toggles;
- public Button confirmBtn;
- public Button returnBtn;
- private void Awake()
- {
-
- cameraToggle.onValueChanged.AddListener(ChangeCameraSet);
- micToggle.onValueChanged.AddListener(ChangeMicSet);
- toggles = ToggleGroupTran.GetComponentsInChildren<Toggle>(true);
- for (int i = 0; i < toggles.Length; i++)
- {
- Toggle toggle = toggles[i];
- toggles[i].onValueChanged.AddListener((bool isOn) => { OnToggle(isOn, toggle); });
- }
- confirmBtn.onClick.AddListener(CkickOnConfirm);
- returnBtn.onClick.AddListener(CkickOnReturn);
-
- }
- private void Start()
- {
- StartCoroutine(SettingSystemData());
- }
- #region 窗体生命周期
- public override void Display()
- {
- base.Display();
- Init();
- }
- public override void Redisplay()
- {
- base.Redisplay();
- }
- public override void Freeze()
- {
- base.Freeze();
- }
- public override void Hiding()
- {
- base.Hiding();
-
- }
- #endregion
- private bool tempSendVideo;
- private bool tempSendAideo;
- private int tempCamIndex;
- private void Init()
- {
- //cameraToggle.isOn = CustomInfo.isSendVideo;
- //micToggle.isOn = CustomInfo.isSendAudio;
- if (toggles != null)
- {
- switch (CustomInfo.camIndex)
- {
- case 1:
- toggles[0].isOn = true;
- break;
- case 2:
- toggles[1].isOn = true;
- break;
- case 3:
- toggles[2].isOn = true;
- break;
- }
- }
- tempSendVideo = CustomInfo.isSendVideo;
- tempSendAideo = CustomInfo.isSendAudio;
- tempCamIndex = CustomInfo.camIndex;
- }
- private void OnToggle(bool isOn, Toggle toggle)
- {
- if (isOn)
- {
- switch (toggle.name)
- {
- case "1080PToggle":
- CustomInfo.camIndex = 1;
- break;
- case "720PToggle":
- CustomInfo.camIndex = 2;
- break;
- case "480PToggle":
- CustomInfo.camIndex = 3;
- break;
- }
- toggle.isOn = isOn;
- }
- }
- private void ChangeCameraSet(bool isOn)
- {
- CustomInfo.isSendVideo = isOn;
- SystemDatas data = new SystemDatas();
- data.Camera = isOn ? 1 : 0;
- data.Mic = CustomInfo.isSendAudio ? 1 : 0;
- SaveSystemData(data);
-
- }
- private void ChangeMicSet(bool isOn)
- {
- CustomInfo.isSendAudio = isOn;
- SystemDatas data = new SystemDatas();
- data.Camera = CustomInfo.isSendVideo ? 1 : 0;
- data.Mic = isOn ? 1 : 0;
- SaveSystemData(data);
- }
- private void CkickOnReturn()
- {
- CustomInfo.isSendVideo = tempSendVideo;
- CustomInfo.isSendAudio = tempSendAideo;
- CustomInfo.camIndex = tempCamIndex;
- CloseOrReturnUIForms();
- ShowUIForms(SysConst.MainPanelForms);
- }
- private void CkickOnConfirm()
- {
- CloseOrReturnUIForms();
- ShowUIForms(SysConst.MainPanelForms);
- }
- private void SaveSystemData(SystemDatas data )
- {
- UserInfo.systemDatas = data;
- string saveData = JsonConvert.SerializeObject(data);
- Debug.Log(saveData);
- PlayerPrefs.SetString(UserInfo.Account + "_SystemSetting", saveData);
- }
- private IEnumerator SettingSystemData()
- {
- yield return new WaitForSeconds(0.1f);
- if (PlayerPrefs.HasKey(UserInfo.Account + "_SystemSetting"))
- {
- string SystemData = PlayerPrefs.GetString(UserInfo.Account + "_SystemSetting");
- Debug.Log(SystemData);
- SystemDatas data = JsonConvert.DeserializeObject<SystemDatas>(SystemData);
- cameraToggle.isOn = data.Camera == 1 ? true : false;
- micToggle.isOn = data.Mic == 1 ? true : false;
-
- }
- }
- }
|