UserSystem.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. using rtc;
  2. using SC.XR.Unity;
  3. using System;
  4. using System.Text;
  5. using TMPro;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. using static ScenesManager;
  9. using static ShowLogin;
  10. public class UserSystem : RemoteSingleton<UserSystem>
  11. {
  12. public RawImage texIcon;
  13. public TextMeshProUGUI userSNName;
  14. public SCInputField userName;
  15. public TextMeshProUGUI userAccount;
  16. public TextMeshProUGUI accountManager;
  17. public GameObject AvatarListPop;
  18. // public SCInputField inputName;
  19. public static Action<Texture> swithAvatarAction;
  20. public AvatarList avatarList;
  21. public TextMeshProUGUI nameRemind;
  22. public Image inputKuangImage;
  23. public GameObject AccountInfo;
  24. public GameObject LimitObj;
  25. public GameObject ActivityObj;
  26. public Button activityBtn;
  27. public TextMeshProUGUI activityText;
  28. public Button btnAccountNumber;
  29. public override void initShow()
  30. {
  31. base.initShow();
  32. if (UserInfo.textIcon == null)
  33. {
  34. texIcon.texture = UserInfo.defaulttextIcon;
  35. }
  36. else
  37. {
  38. texIcon.texture = UserInfo.textIcon;
  39. }
  40. userAccount.text = "当前账号: " + UserInfo.Account;
  41. nameRemind.gameObject.SetActive(false);
  42. inputKuangImage.color = Color.white;
  43. if (UserInfo.userName=="")
  44. {
  45. userName.text = "YCKJ" + UserInfo.Account.Substring(UserInfo.Account.Length-4);
  46. }
  47. else
  48. {
  49. userName.text = UserInfo.userName;
  50. }
  51. if (UserInfo.isSN)
  52. {
  53. accountManager.text = "该账号为设备SN号";
  54. userSNName.gameObject.SetActive(true);
  55. userName.gameObject.SetActive(false);
  56. userSNName.text = UserInfo.Account;
  57. activityBtn.gameObject.SetActive(false);
  58. }
  59. else
  60. {
  61. activityBtn.gameObject.SetActive(true);
  62. userSNName.gameObject.SetActive(false);
  63. userName.gameObject.SetActive(true);
  64. switch (UserInfo.activateType)
  65. {
  66. case 1:
  67. accountManager.text = "未激活账号";
  68. activityText.text = "激活";
  69. break;
  70. case 2:
  71. string indate = UserInfo.indate.ToString();
  72. if (indate == "0")
  73. {
  74. accountManager.text = "未激活账号";
  75. activityText.text = "激活";
  76. }
  77. else
  78. {
  79. string ti = GetTime(UserInfo.indate);
  80. accountManager.text = "账号已激活 有效期至" + ti;
  81. activityText.text = "续费";
  82. }
  83. break;
  84. case 3:
  85. accountManager.text = "账号永久激活";
  86. activityBtn.gameObject.SetActive(false);
  87. break;
  88. }
  89. }
  90. LimitObj.SetActive(false);
  91. ActivityObj.SetActive(false);
  92. accountManager.gameObject.SetActive(false);
  93. btnAccountNumber.gameObject.SetActive(false);
  94. }
  95. public void showOffice()
  96. {
  97. SaveNameandAvatar();
  98. ScenesManager.Instance.showOffice(SceneType.OfficeWindow);
  99. }
  100. public void gotoLogin()
  101. {
  102. SaveNameandAvatar();
  103. WSHandler.clientClosed();
  104. ShowLogin.Instance.loginType = LoginType.INIT;
  105. ScenesManager.Instance.showWindow(SceneType.ShowLogin);
  106. }
  107. private void SaveNameandAvatar()
  108. {
  109. if (!nameRemind.gameObject.activeSelf)
  110. {
  111. if (userName.text != "")
  112. {
  113. UserInfo.userName = userName.text;
  114. }
  115. }
  116. NetWorkHeaders.SetUserInfo();
  117. }
  118. private Action loginOutAction;
  119. private void Start()
  120. {
  121. loginOutAction += gotoLogin;
  122. swithAvatarAction += OnSwithAvatar;
  123. avatarList.Init();
  124. userName.onValueChanged.AddListener(NameValueChanged);
  125. userName.onEndEdit.AddListener(NameEndEdit);
  126. }
  127. private void NameEndEdit(string name)
  128. {
  129. int namecount = Encoding.GetEncoding("gb2312").GetByteCount(name);
  130. if (name == "" || name.Contains(" ") || namecount > 16)
  131. {
  132. nameRemind.gameObject.SetActive(true);
  133. nameRemind.text = RtcStrConfig.namenolegal;
  134. inputKuangImage.color = Color.red;
  135. }
  136. else
  137. {
  138. inputKuangImage.color = Color.white;
  139. }
  140. }
  141. private void NameValueChanged(string name)
  142. {
  143. nameRemind.gameObject.SetActive(false);
  144. inputKuangImage.color = Color.white;
  145. }
  146. private void OnSwithAvatar(Texture tex)
  147. {
  148. texIcon.texture = tex;
  149. }
  150. private void OnDestroy()
  151. {
  152. loginOutAction -= gotoLogin;
  153. swithAvatarAction -= OnSwithAvatar;
  154. }
  155. public void ShowLoginOutPop()
  156. {
  157. PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Pop, RtcStrConfig.outLoginmsg, "确定", loginOutAction);
  158. }
  159. public void ShowAvatarListPop()
  160. {
  161. if (!UserInfo.isSN)
  162. {
  163. AvatarListPop.SetActive(true);
  164. }
  165. }
  166. public void CloseAvatarListPop()
  167. {
  168. AvatarListPop.SetActive(false);
  169. }
  170. public void ShowLimitObj()
  171. {
  172. AccountInfo.SetActive(false);
  173. LimitObj.SetActive(true);
  174. }
  175. public void HeidLimitObj()
  176. {
  177. LimitObj.SetActive(false);
  178. AccountInfo.SetActive(true);
  179. }
  180. public void ShowActivityObj()
  181. {
  182. ActivityObj.SetActive(true);
  183. }
  184. public string GetTime(double timechu)
  185. {
  186. DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
  187. DateTime dt = startTime.AddSeconds(timechu);
  188. string t = dt.ToString("yyyy-MM-dd HH:mm:ss");
  189. string[] arr = t.Split(' ');
  190. return arr[0];
  191. }
  192. private void OnDisable()
  193. {
  194. }
  195. }