using LitJson; using rtc; using SC.XR.Unity; using ShadowStudio.UI; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using static ScenesManager; public class ActivityMgr : MonoBehaviour { public SCInputField sCInputField; public Text activityRemind; public Image AcvicityInputKuangImage; public Button querenBtn; public Button cancelBtn; private bool isLock; // Start is called before the first frame update void Start() { sCInputField.onValueChanged.AddListener(OnValueChanged); querenBtn.onClick.AddListener(ClickQueren); cancelBtn.onClick.AddListener(ClickCancel); } public void Init() { if (sCInputField.text != "") { sCInputField.text = ""; } activityRemind.gameObject.SetActive(false); AcvicityInputKuangImage.color = Color.white; if (isLock) { isLock = false; } querenBtn.enabled = true; cancelBtn.enabled = true; } private void OnValueChanged(string content) { activityRemind.gameObject.SetActive(false); AcvicityInputKuangImage.color = Color.white; } public void ClickQueren() { if (sCInputField.text == "") { InputError(RtcStrConfig.activitynull); } else if(activityRemind.gameObject.activeSelf) { return; } else { if (sCInputField.text.Length != 8) { InputError(RtcStrConfig.activityError); } else { if (!isLock) { isLock = true; NetWorkHeaders.Activate(sCInputField.text, ActivitySucess, ActivityFail); } } } } public void InputError(string str) { activityRemind.gameObject.SetActive(true); AcvicityInputKuangImage.color = Color.red; activityRemind.text = str; } private void ActivityFail(string str) { isLock = false; JsonData data = null; string code = ""; try { data = JsonMapper.ToObject(str); code = data["code"].ToString(); } catch (Exception e) { PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Tip, RtcStrConfig.serverError); return; } switch (code) { case "5001": InputError(RtcStrConfig.activityError); break; case "9002": InputError(RtcStrConfig.activityError); break; } } private void ActivitySucess(JsonData data) { if (data["code"].ToString() == "200") { isLock = false; querenBtn.enabled = false; cancelBtn.enabled = false; WSHandler.clientClosed(); AcivtyGetUserInfo(); } } public void ClickCancel() { this.gameObject.SetActive(false); } public void AcivtyGetUserInfo() { NetWorkHeaders.GetUserInfo((JsonData sData) => { UserInfo.phone = sData["data"]["phone"].ToString(); UserInfo.userName = sData["data"]["nickName"].ToString(); if (UserInfo.userName == "") { UserInfo.userName = UserInfo.phone; //UserInfo.userName = "YCKJ" + UserInfo.Account.Substring(UserInfo.Account.Length - 4); } UserInfo.activateType = int.Parse(sData["data"]["activateType"].ToString()); UserInfo.indate = double.Parse(sData["data"]["indate"].ToString()); CustomInfo.isSendAudio = bool.Parse(sData["data"]["settings"]["mic"].ToString()); CustomInfo.isSendVideo = bool.Parse(sData["data"]["settings"]["camera"].ToString()); CustomInfo.camIndex = int.Parse(sData["data"]["settings"]["resolution"].ToString()); WSHandler.Office.OnInit -= Init; WSHandler.Office.OnInit += Init; WSHandler.init(); }, (string failStr) => { PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Tip, RtcStrConfig.serverFail); }); } private void Init(JsonData data) { this.gameObject.SetActive(false); querenBtn.enabled = true; cancelBtn.enabled = true; switch (UserSystem.Instance.activityText.text) { case "激活": PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Tip, "账号激活成功"); break; case "续费": PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Tip, "账号续费成功"); break; } ScenesManager.Instance.showOffice(SceneType.UserSystem); WSHandler.Office.OnInit -= Init; } }