ActivityMgr.cs 4.8 KB

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