ActivityMgr.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. using LitJson;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. public class ActivityMgr : MonoBehaviour
  8. {
  9. public InputField activityNumInputField;
  10. public Text activityRemind;
  11. public Image AcvicityInputKuangImage;
  12. public Button querenBtn;
  13. public Button cancelBtn;
  14. private bool isLock;
  15. public MyCenterForms centerForms;
  16. // Start is called before the first frame update
  17. void Awake()
  18. {
  19. activityNumInputField.onValueChanged.AddListener(OnValueChanged);
  20. activityNumInputField.onEndEdit.AddListener(OnValueEnd);
  21. querenBtn.onClick.AddListener(ClickQueren);
  22. cancelBtn.onClick.AddListener(ClickCancel);
  23. }
  24. public void Init()
  25. {
  26. if (activityNumInputField.text != "")
  27. {
  28. activityNumInputField.text = "";
  29. }
  30. activityRemind.gameObject.SetActive(false);
  31. ChangeOriginal();
  32. if (isLock)
  33. {
  34. isLock = false;
  35. }
  36. querenBtn.enabled = true;
  37. cancelBtn.enabled = true;
  38. }
  39. private void OnValueEnd(string content)
  40. {
  41. ChangeOriginal();
  42. }
  43. private void OnValueChanged(string content)
  44. {
  45. activityRemind.gameObject.SetActive(false);
  46. ChangeBlue();
  47. }
  48. public void ClickQueren()
  49. {
  50. if (activityNumInputField.text == "")
  51. {
  52. InputError(RtcStrConfig.activitynull);
  53. }
  54. else if(activityRemind.gameObject.activeSelf)
  55. {
  56. return;
  57. }
  58. else
  59. {
  60. if (activityNumInputField.text.Length != 8)
  61. {
  62. InputError(RtcStrConfig.activityError);
  63. }
  64. else
  65. {
  66. if (!isLock)
  67. {
  68. isLock = true;
  69. NetWorkHeaders.Activate(activityNumInputField.text, ActivitySucess, ActivityFail);
  70. }
  71. }
  72. }
  73. }
  74. public void InputError(string str)
  75. {
  76. activityRemind.gameObject.SetActive(true);
  77. ChangeRed();
  78. activityRemind.text = str;
  79. }
  80. private void ActivityFail(string str)
  81. {
  82. isLock = false;
  83. JsonData data = null;
  84. string code = "";
  85. try
  86. {
  87. data = JsonMapper.ToObject(str);
  88. code = data["code"].ToString();
  89. }
  90. catch (Exception e)
  91. {
  92. TipMgr.Instance.ShowTip(RtcStrConfig.serverError);
  93. return;
  94. }
  95. switch (code)
  96. {
  97. case "5001":
  98. InputError(RtcStrConfig.activityError);
  99. break;
  100. case "9002":
  101. InputError(RtcStrConfig.activityError);
  102. break;
  103. }
  104. }
  105. private void ActivitySucess(JsonData data)
  106. {
  107. if (data["code"].ToString() == "200")
  108. {
  109. isLock = false;
  110. querenBtn.enabled = false;
  111. cancelBtn.enabled = false;
  112. WSHandler.clientClosed();
  113. AcivtyGetUserInfo();
  114. }
  115. }
  116. public void ClickCancel()
  117. {
  118. this.gameObject.SetActive(false);
  119. }
  120. public void AcivtyGetUserInfo()
  121. {
  122. NetWorkHeaders.GetUserInfo((JsonData sData) => {
  123. UserInfo.phone = sData["data"]["phone"].ToString();
  124. UserInfo.userName = sData["data"]["nickName"].ToString();
  125. if (UserInfo.userName == "")
  126. {
  127. UserInfo.userName = "YCKJ" + UserInfo.Account.Substring(UserInfo.Account.Length - 4);
  128. }
  129. UserInfo.activateType = int.Parse(sData["data"]["activateType"].ToString());
  130. UserInfo.indate = double.Parse(sData["data"]["indate"].ToString());
  131. CustomInfo.isSendAudio = bool.Parse(sData["data"]["settings"]["mic"].ToString());
  132. CustomInfo.isSendVideo = bool.Parse(sData["data"]["settings"]["camera"].ToString());
  133. CustomInfo.camIndex = int.Parse(sData["data"]["settings"]["resolution"].ToString());
  134. WSHandler.Office.OnInit -= Init;
  135. WSHandler.Office.OnInit += Init;
  136. WSHandler.init();
  137. }, (string failStr) => {
  138. TipMgr.Instance.ShowTip(RtcStrConfig.serverFail);
  139. });
  140. }
  141. private void Init(JsonData data)
  142. {
  143. this.gameObject.SetActive(false);
  144. querenBtn.enabled = true;
  145. cancelBtn.enabled = true;
  146. switch (centerForms.activityBtnText.text)
  147. {
  148. case "激活":
  149. TipMgr.Instance.ShowTip("账号激活成功");
  150. break;
  151. case "续费":
  152. TipMgr.Instance.ShowTip("账号续费成功");
  153. break;
  154. }
  155. if (centerForms)
  156. {
  157. centerForms.Init();
  158. }
  159. WSHandler.Office.OnInit -= Init;
  160. }
  161. public void ChangeOriginal()
  162. {
  163. Color color = Color.white;
  164. color.r = 255 / 255f;
  165. color.g = 255 / 255f;
  166. color.b = 255 / 255f;
  167. color.a = 100 / 255f;
  168. AcvicityInputKuangImage.color = color;
  169. }
  170. public void ChangeBlue()
  171. {
  172. Color color = Color.white;
  173. color.r = 111 / 255f;
  174. color.g = 168 / 255f;
  175. color.b = 254 / 255f;
  176. color.a = 255 / 255f;
  177. AcvicityInputKuangImage.color = color;
  178. }
  179. public void ChangeRed()
  180. {
  181. Color color = Color.white;
  182. color.r = 254 / 255f;
  183. color.g = 1 / 255f;
  184. color.b = 7 / 255f;
  185. color.a = 255 / 255f;
  186. AcvicityInputKuangImage.color = color;
  187. }
  188. }