UserSystem.cs 5.7 KB

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