123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- 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;
- }
- }
|