ActivityMgr.cs 5.0 KB

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