using rtc; using SC.XR.Unity; using System; using System.Text; using TMPro; using UnityEngine; using UnityEngine.UI; using static ScenesManager; using static ShowLogin; public class UserSystem : RemoteSingleton { public RawImage texIcon; public TextMeshProUGUI userSNName; public SCInputField userName; public TextMeshProUGUI userAccount; public TextMeshProUGUI accountManager; public GameObject AvatarListPop; // public SCInputField inputName; public static Action swithAvatarAction; public AvatarList avatarList; public TextMeshProUGUI nameRemind; public Image inputKuangImage; public GameObject AccountInfo; public GameObject LimitObj; public GameObject ActivityObj; public Button activityBtn; public TextMeshProUGUI activityText; public Button btnAccountNumber; public override void initShow() { base.initShow(); if (UserInfo.textIcon == null) { texIcon.texture = UserInfo.defaulttextIcon; } else { texIcon.texture = UserInfo.textIcon; } userAccount.text = "当前账号: " + UserInfo.Account; nameRemind.gameObject.SetActive(false); inputKuangImage.color = Color.white; if (UserInfo.userName=="") { userName.text = "YCKJ" + UserInfo.Account.Substring(UserInfo.Account.Length-4); } else { userName.text = UserInfo.userName; } if (UserInfo.isSN) { accountManager.text = "该账号为设备SN号"; userSNName.gameObject.SetActive(true); userName.gameObject.SetActive(false); userSNName.text = UserInfo.Account; activityBtn.gameObject.SetActive(false); } else { activityBtn.gameObject.SetActive(true); userSNName.gameObject.SetActive(false); userName.gameObject.SetActive(true); switch (UserInfo.activateType) { case 1: accountManager.text = "未激活账号"; activityText.text = "激活"; break; case 2: string indate = UserInfo.indate.ToString(); if (indate == "0") { accountManager.text = "未激活账号"; activityText.text = "激活"; } else { string ti = GetTime(UserInfo.indate); accountManager.text = "账号已激活 有效期至" + ti; activityText.text = "续费"; } break; case 3: accountManager.text = "账号永久激活"; activityBtn.gameObject.SetActive(false); break; } } LimitObj.SetActive(false); ActivityObj.SetActive(false); accountManager.gameObject.SetActive(false); btnAccountNumber.gameObject.SetActive(false); } public void showOffice() { SaveNameandAvatar(); ScenesManager.Instance.showOffice(SceneType.OfficeWindow); } public void gotoLogin() { SaveNameandAvatar(); WSHandler.clientClosed(); ShowLogin.Instance.loginType = LoginType.INIT; ScenesManager.Instance.showWindow(SceneType.ShowLogin); } private void SaveNameandAvatar() { if (!nameRemind.gameObject.activeSelf) { if (userName.text != "") { UserInfo.userName = userName.text; } } NetWorkHeaders.SetUserInfo(); } private Action loginOutAction; private void Start() { loginOutAction += gotoLogin; swithAvatarAction += OnSwithAvatar; avatarList.Init(); userName.onValueChanged.AddListener(NameValueChanged); userName.onEndEdit.AddListener(NameEndEdit); } private void NameEndEdit(string name) { int namecount = Encoding.GetEncoding("gb2312").GetByteCount(name); if (name == "" || name.Contains(" ") || namecount > 16) { nameRemind.gameObject.SetActive(true); nameRemind.text = RtcStrConfig.namenolegal; inputKuangImage.color = Color.red; } else { inputKuangImage.color = Color.white; } } private void NameValueChanged(string name) { nameRemind.gameObject.SetActive(false); inputKuangImage.color = Color.white; } private void OnSwithAvatar(Texture tex) { texIcon.texture = tex; } private void OnDestroy() { loginOutAction -= gotoLogin; swithAvatarAction -= OnSwithAvatar; } public void ShowLoginOutPop() { PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Pop, RtcStrConfig.outLoginmsg, "确定", loginOutAction); } public void ShowAvatarListPop() { if (!UserInfo.isSN) { AvatarListPop.SetActive(true); } } public void CloseAvatarListPop() { AvatarListPop.SetActive(false); } public void ShowLimitObj() { AccountInfo.SetActive(false); LimitObj.SetActive(true); } public void HeidLimitObj() { LimitObj.SetActive(false); AccountInfo.SetActive(true); } public void ShowActivityObj() { ActivityObj.SetActive(true); } public string GetTime(double timechu) { DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); DateTime dt = startTime.AddSeconds(timechu); string t = dt.ToString("yyyy-MM-dd HH:mm:ss"); string[] arr = t.Split(' '); return arr[0]; } private void OnDisable() { } }