using LitJson; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class ActivityMgr : MonoBehaviour { public InputField activityNumInputField; public Text activityRemind; public Image AcvicityInputKuangImage; public Button querenBtn; public Button cancelBtn; private bool isLock; public MyCenterForms centerForms; // Start is called before the first frame update void Awake() { activityNumInputField.onValueChanged.AddListener(OnValueChanged); activityNumInputField.onEndEdit.AddListener(OnValueEnd); querenBtn.onClick.AddListener(ClickQueren); cancelBtn.onClick.AddListener(ClickCancel); } public void Init() { if (activityNumInputField.text != "") { activityNumInputField.text = ""; } activityRemind.gameObject.SetActive(false); ChangeOriginal(); if (isLock) { isLock = false; } querenBtn.enabled = true; cancelBtn.enabled = true; } private void OnValueEnd(string content) { ChangeOriginal(); } private void OnValueChanged(string content) { activityRemind.gameObject.SetActive(false); ChangeBlue(); } public void ClickQueren() { if (activityNumInputField.text == "") { InputError(RtcStrConfig.activitynull); } else if(activityRemind.gameObject.activeSelf) { return; } else { if (activityNumInputField.text.Length != 8) { InputError(RtcStrConfig.activityError); } else { if (!isLock) { isLock = true; NetWorkHeaders.Activate(activityNumInputField.text, ActivitySucess, ActivityFail); } } } } public void InputError(string str) { activityRemind.gameObject.SetActive(true); ChangeRed(); 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) { TipMgr.Instance.ShowTip(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 = "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) => { TipMgr.Instance.ShowTip(RtcStrConfig.serverFail); }); } private void Init(JsonData data) { this.gameObject.SetActive(false); querenBtn.enabled = true; cancelBtn.enabled = true; switch (centerForms.activityBtnText.text) { case "激活": TipMgr.Instance.ShowTip("账号激活成功"); break; case "续费": TipMgr.Instance.ShowTip("账号续费成功"); break; } if (centerForms) { centerForms.Init(); } WSHandler.Office.OnInit -= Init; } public void ChangeOriginal() { Color color = Color.white; color.r = 255 / 255f; color.g = 255 / 255f; color.b = 255 / 255f; color.a = 100 / 255f; AcvicityInputKuangImage.color = color; } public void ChangeBlue() { Color color = Color.white; color.r = 111 / 255f; color.g = 168 / 255f; color.b = 254 / 255f; color.a = 255 / 255f; AcvicityInputKuangImage.color = color; } public void ChangeRed() { Color color = Color.white; color.r = 254 / 255f; color.g = 1 / 255f; color.b = 7 / 255f; color.a = 255 / 255f; AcvicityInputKuangImage.color = color; } }