AboutMeDlg.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. using Newtonsoft.Json;
  2. using ShadowStudio.Mgr;
  3. using Studio.Scripts;
  4. using Studio.Scripts.HttpMessage;
  5. using System;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using UnityEngine;
  9. using UnityEngine.UI;
  10. using XRTool.Util;
  11. using XRTool.WorldUI;
  12. namespace ShadowStudio.UI
  13. {
  14. [RequireComponent(typeof(WorldDlg))]
  15. public class AboutMeDlg : UnitySingleton<AboutMeDlg>
  16. {
  17. WorldDlg dlg;
  18. private XRIcon avatar;
  19. private TextMesh userNameText;
  20. private Toggle cameraToggle_Switch;
  21. private Toggle micToggle_Switch;
  22. private Transform toggleGroupTran;
  23. private Transform framerateToggleGroup;
  24. private Button loginoutBtn;
  25. private Button closeBtn;
  26. void Start()
  27. {
  28. dlg = GetComponent<WorldDlg>();
  29. avatar = dlg.GetBreadthChild<XRIcon>("Avatar");
  30. for (int i = 0; i < CommonMethod.UserAvatarsList.Count; i++)
  31. {
  32. if (UserInfoMgr.Instance.userConfig.Avatar == CommonMethod.UserAvatarsList[i].Url)
  33. {
  34. string path = "Avatar/" + CommonMethod.UserAvatarsList[i].Id + "Avatar";
  35. avatar.icon = Resources.Load(path) as Texture2D;
  36. avatar.AutoSetSprite();
  37. }
  38. }
  39. userNameText = dlg.GetBreadthChild<TextMesh>("UserNameText");
  40. userNameText.text = UserInfoMgr.Instance.userConfig.Nick_name;
  41. cameraToggle_Switch = dlg.GetBreadthChild<Toggle>("CameraXRToggle_Switch");
  42. micToggle_Switch = dlg.GetBreadthChild<Toggle>("MicXRToggle_Switch");
  43. toggleGroupTran = dlg.GetBreadthChild<Transform>("ResolutionToggleGroup");
  44. framerateToggleGroup = dlg.GetBreadthChild<Transform>("FramerateToggleGroup");
  45. closeBtn = dlg.GetBreadthChild<Button>("CloseBtn");
  46. closeBtn.onClick.AddListener(OnClickClose);
  47. loginoutBtn = dlg.GetBreadthChild<Button>("LoginOutBtn");
  48. loginoutBtn.onClick.AddListener(OnClickLoginout);
  49. cameraToggle_Switch.onValueChanged.AddListener(ClickCamearaToggle);
  50. micToggle_Switch.onValueChanged.AddListener(ClickMicToggle);
  51. XRToggle[] toggles = toggleGroupTran.GetComponentsInChildren<XRToggle>(true);
  52. for (int i = 0; i < toggles.Length; i++)
  53. {
  54. XRToggle toggle = toggles[i];
  55. toggles[i].onValueChanged.AddListener((bool isOn) => { OnToggle(isOn, toggle); });
  56. if (i == CommonMethod.mySetting.Ratio - 1)
  57. {
  58. toggles[i].isOn = true;
  59. OnToggle(true, toggles[i]);//记得初始化
  60. }
  61. }
  62. XRToggle[] togglegroup = framerateToggleGroup.GetComponentsInChildren<XRToggle>(true);
  63. for (int i = 0; i < togglegroup.Length; i++)
  64. {
  65. XRToggle toggle = togglegroup[i];
  66. togglegroup[i].onValueChanged.AddListener((bool isOn) => { OnFrameToggle(isOn, toggle); });
  67. if (i == CommonMethod.mySetting.Fps - 1)
  68. {
  69. togglegroup[i].isOn = true;
  70. OnFrameToggle(true, togglegroup[i]);
  71. }
  72. }
  73. if (CommonMethod.mySetting.Camera)
  74. {
  75. cameraToggle_Switch.isOn = true;
  76. }
  77. else
  78. {
  79. cameraToggle_Switch.isOn = false;
  80. }
  81. if (CommonMethod.mySetting.Mic)
  82. {
  83. micToggle_Switch.isOn = true;
  84. }
  85. else
  86. {
  87. micToggle_Switch.isOn = false;
  88. }
  89. CustomInfo.isSendVideo = cameraToggle_Switch.isOn;
  90. CustomInfo.isSendAudio = micToggle_Switch.isOn;
  91. }
  92. private void ClickCamearaToggle(bool isOn)
  93. {
  94. CommonMethod.mySetting.Camera = isOn;
  95. CustomInfo.isSendVideo = isOn;
  96. //Debug.Log(CommonMethod.mySetting.Camera + "Camera" + isOn);
  97. SystemDatas data = new SystemDatas();
  98. data.Camera = CustomInfo.isSendVideo ? 1 : 0;
  99. data.Mic = CustomInfo.isSendAudio ? 1 : 0;
  100. SaveSystemData(data);
  101. }
  102. private void ClickMicToggle(bool isOn)
  103. {
  104. CommonMethod.mySetting.Mic = isOn;
  105. CustomInfo.isSendAudio = isOn;
  106. //Debug.Log(CommonMethod.mySetting.Mic + "Mic" + isOn);
  107. SystemDatas data = new SystemDatas();
  108. data.Camera = CustomInfo.isSendVideo ? 1 : 0;
  109. data.Mic = CustomInfo.isSendAudio ? 1 : 0;
  110. SaveSystemData(data);
  111. }
  112. private void SaveSystemData(SystemDatas data)
  113. {
  114. UserInfo.systemDatas = data;
  115. string saveData = JsonConvert.SerializeObject(data);
  116. Debug.Log(saveData);
  117. PlayerPrefs.SetString(UserInfo.Account + "_SystemSetting", saveData);
  118. }
  119. private void OnToggle(bool isOn, XRToggle toggle)
  120. {
  121. if (isOn)
  122. {
  123. switch (toggle.name)
  124. {
  125. case "HighXRToggle_CheckBox":
  126. CommonMethod.mySetting.Ratio = 1;
  127. //Debug.Log("HighResolutionBtn");
  128. break;
  129. case "MidXRToggle_CheckBox":
  130. CommonMethod.mySetting.Ratio = 2;
  131. //Debug.Log("MidResolutionBtn");
  132. break;
  133. case "LowXRToggle_CheckBox":
  134. CommonMethod.mySetting.Ratio = 3;
  135. //Debug.Log("LowResolutionBtn");
  136. break;
  137. }
  138. }
  139. }
  140. private void OnFrameToggle(bool isOn, XRToggle toggle)
  141. {
  142. if (isOn)
  143. {
  144. switch (toggle.name)
  145. {
  146. case "15XRToggle_CheckBox":
  147. CommonMethod.mySetting.Fps = 3;
  148. break;
  149. case "30XRToggle_CheckBox":
  150. CommonMethod.mySetting.Fps = 2;
  151. break;
  152. case "60XRToggle_CheckBox":
  153. CommonMethod.mySetting.Fps = 1;
  154. break;
  155. }
  156. }
  157. }
  158. private void OnClickClose()
  159. {
  160. dlg.hideDlg(() => {
  161. //被zby替换的代码
  162. //RoomListModel.Instance.UpdateList(RoomListDlg.Instance.roomlist);
  163. //HomeViewMgr.Instance.ShowView(HomeViewMgr.CREATESEARCHRROOMDLG);
  164. //HomeViewMgr.Instance.roomListDlg.SetActive(true);
  165. MenuListDlg.Instance.UpdateData();
  166. HomeMgr.Instance.ShowView(HomeMgr.CREATESEARCHRROOMDLG);
  167. HomeMgr.Instance.roomListDlg.SetActive(true);
  168. });
  169. HomeProxy.Instance.RequestUpdateSettings(CommonMethod.mySetting.Camera,
  170. CommonMethod.mySetting.Mic,
  171. (RatioType)CommonMethod.mySetting.Ratio,
  172. (FpsType)CommonMethod.mySetting.Fps);
  173. }
  174. private void OnClickLoginout()
  175. {
  176. WSHandler.clientClosed();
  177. //被zby替换的代码
  178. //HomeViewMgr.Instance.LoadLoginSence();
  179. HomeMgr.Instance.LoadLoginSence();
  180. HomeProxy.Instance.RequestUpdateSettings(CommonMethod.mySetting.Camera,
  181. CommonMethod.mySetting.Mic,
  182. (RatioType)CommonMethod.mySetting.Ratio,
  183. (FpsType)CommonMethod.mySetting.Fps);
  184. }
  185. }
  186. }