SystemSettingForms.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using Newtonsoft.Json;
  2. using SUIFW;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. public class SystemSettingForms : BaseUIForms
  9. {
  10. public Toggle cameraToggle;
  11. public Toggle micToggle;
  12. public Transform ToggleGroupTran;
  13. private Toggle[] toggles;
  14. public Button confirmBtn;
  15. public Button returnBtn;
  16. private void Awake()
  17. {
  18. cameraToggle.onValueChanged.AddListener(ChangeCameraSet);
  19. micToggle.onValueChanged.AddListener(ChangeMicSet);
  20. toggles = ToggleGroupTran.GetComponentsInChildren<Toggle>(true);
  21. for (int i = 0; i < toggles.Length; i++)
  22. {
  23. Toggle toggle = toggles[i];
  24. toggles[i].onValueChanged.AddListener((bool isOn) => { OnToggle(isOn, toggle); });
  25. }
  26. confirmBtn.onClick.AddListener(CkickOnConfirm);
  27. returnBtn.onClick.AddListener(CkickOnReturn);
  28. }
  29. private void Start()
  30. {
  31. StartCoroutine(SettingSystemData());
  32. }
  33. #region 窗体生命周期
  34. public override void Display()
  35. {
  36. base.Display();
  37. Init();
  38. }
  39. public override void Redisplay()
  40. {
  41. base.Redisplay();
  42. }
  43. public override void Freeze()
  44. {
  45. base.Freeze();
  46. }
  47. public override void Hiding()
  48. {
  49. base.Hiding();
  50. }
  51. #endregion
  52. private bool tempSendVideo;
  53. private bool tempSendAideo;
  54. private int tempCamIndex;
  55. private void Init()
  56. {
  57. //cameraToggle.isOn = CustomInfo.isSendVideo;
  58. //micToggle.isOn = CustomInfo.isSendAudio;
  59. if (toggles != null)
  60. {
  61. switch (CustomInfo.camIndex)
  62. {
  63. case 1:
  64. toggles[0].isOn = true;
  65. break;
  66. case 2:
  67. toggles[1].isOn = true;
  68. break;
  69. case 3:
  70. toggles[2].isOn = true;
  71. break;
  72. }
  73. }
  74. tempSendVideo = CustomInfo.isSendVideo;
  75. tempSendAideo = CustomInfo.isSendAudio;
  76. tempCamIndex = CustomInfo.camIndex;
  77. }
  78. private void OnToggle(bool isOn, Toggle toggle)
  79. {
  80. if (isOn)
  81. {
  82. switch (toggle.name)
  83. {
  84. case "1080PToggle":
  85. CustomInfo.camIndex = 1;
  86. break;
  87. case "720PToggle":
  88. CustomInfo.camIndex = 2;
  89. break;
  90. case "480PToggle":
  91. CustomInfo.camIndex = 3;
  92. break;
  93. }
  94. toggle.isOn = isOn;
  95. }
  96. }
  97. private void ChangeCameraSet(bool isOn)
  98. {
  99. CustomInfo.isSendVideo = isOn;
  100. SystemDatas data = new SystemDatas();
  101. data.Camera = isOn ? 1 : 0;
  102. data.Mic = CustomInfo.isSendAudio ? 1 : 0;
  103. SaveSystemData(data);
  104. }
  105. private void ChangeMicSet(bool isOn)
  106. {
  107. CustomInfo.isSendAudio = isOn;
  108. SystemDatas data = new SystemDatas();
  109. data.Camera = CustomInfo.isSendVideo ? 1 : 0;
  110. data.Mic = isOn ? 1 : 0;
  111. SaveSystemData(data);
  112. }
  113. private void CkickOnReturn()
  114. {
  115. CustomInfo.isSendVideo = tempSendVideo;
  116. CustomInfo.isSendAudio = tempSendAideo;
  117. CustomInfo.camIndex = tempCamIndex;
  118. CloseOrReturnUIForms();
  119. ShowUIForms(SysConst.MainPanelForms);
  120. }
  121. private void CkickOnConfirm()
  122. {
  123. CloseOrReturnUIForms();
  124. ShowUIForms(SysConst.MainPanelForms);
  125. }
  126. private void SaveSystemData(SystemDatas data )
  127. {
  128. UserInfo.systemDatas = data;
  129. string saveData = JsonConvert.SerializeObject(data);
  130. Debug.Log(saveData);
  131. PlayerPrefs.SetString(UserInfo.Account + "_SystemSetting", saveData);
  132. }
  133. private IEnumerator SettingSystemData()
  134. {
  135. yield return new WaitForSeconds(0.1f);
  136. if (PlayerPrefs.HasKey(UserInfo.Account + "_SystemSetting"))
  137. {
  138. string SystemData = PlayerPrefs.GetString(UserInfo.Account + "_SystemSetting");
  139. Debug.Log(SystemData);
  140. SystemDatas data = JsonConvert.DeserializeObject<SystemDatas>(SystemData);
  141. cameraToggle.isOn = data.Camera == 1 ? true : false;
  142. micToggle.isOn = data.Mic == 1 ? true : false;
  143. }
  144. }
  145. }