UserSystem.cs 6.0 KB

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