VersionCheck.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using SC.InputSystem;
  5. public class VersionCheck : MonoBehaviour
  6. {
  7. [SerializeField]
  8. private UnityEngine.UI.Text MText;
  9. [SerializeField]
  10. private Slider3D MSlider;
  11. [SerializeField]
  12. private PopBase pop;
  13. [SerializeField]
  14. private SCButton DebugMark;//是否是测试服的标记
  15. private bool isSending;
  16. [SerializeField]
  17. private SecretPwdModule mSecretPwdModule;//解锁的模块
  18. [SerializeField]
  19. private DownClient mDownClient;
  20. void Start()
  21. {
  22. DebugMark.onClick.AddListener(SendCheckMsg);
  23. CDebug.Log("当前版本 " + Application.version);
  24. Engine.Http.HttpManager.GetInstance().AddHttpMessageEvent(HandleHttpMessage);
  25. SendCheckMsg();
  26. mDownClient.SetUI(MText, MSlider);
  27. mSecretPwdModule.changeAction += UnLockChangeAction;
  28. UnLockChangeAction();
  29. }
  30. void OnDestroy()
  31. {
  32. DebugMark.onClick.RemoveListener(SendCheckMsg);
  33. Engine.Http.HttpManager.GetInstance().DelHttMessageEvent(HandleHttpMessage);
  34. }
  35. private void UnLockChangeAction()
  36. {
  37. DebugMark.gameObject.SetActive(mSecretPwdModule.UnLock);
  38. if(mSecretPwdModule.UnLock)
  39. {
  40. StopCoroutine("ChangeScene");
  41. }
  42. else
  43. {
  44. CDebug.Log("重新发送默认的");
  45. SendCheckMsg();
  46. }
  47. }
  48. private void SendCheckMsg()
  49. {
  50. if(isSending)
  51. {
  52. return;
  53. }
  54. pop.Hide();
  55. isSending = true;
  56. HttpStaticMessage.AutoSendHttpVerson(Application.version, mSecretPwdModule.UnLock);
  57. }
  58. void LateUpdate()
  59. {
  60. OnUpdate(CStaticMethod.SystemFrameTime());
  61. }
  62. void FixedUpdate()
  63. {
  64. OnFixedUpdate(CStaticMethod.SystemFrameTime());
  65. }
  66. public void OnUpdate(int nTime)
  67. {
  68. Engine.Http.HttpManager.GetInstance().OnUpdate(nTime);
  69. }
  70. public void OnFixedUpdate(int nTime)
  71. {
  72. //Http请求
  73. Engine.Http.HttpManager.GetInstance().OnFixedUpdate(nTime);
  74. }
  75. private bool HandleHttpMessage(Engine.Http.HttpResponse httpResponse)
  76. {
  77. if (httpResponse == null)
  78. {
  79. return false;
  80. }
  81. if (!httpResponse.isSuccess)
  82. {
  83. if (httpResponse.ResponseStatu == -99999)
  84. {
  85. MText.text = httpResponse.ResponseMsg;
  86. }
  87. return false;
  88. }
  89. CDebug.Log("接受消息" + httpResponse.Code);
  90. switch (httpResponse.Code)
  91. {
  92. //获取角色信息
  93. case MsgConst.HTTP_MSG_VERSION:
  94. CheckRes(httpResponse);
  95. break;
  96. }
  97. return false;
  98. }
  99. private UpdataData mUpdataData;
  100. private void CheckRes(Engine.Http.HttpResponse httpResponse)
  101. {
  102. isSending = false;
  103. mUpdataData = new UpdataData();
  104. mUpdataData.state = httpResponse.ReadBool("state");
  105. mUpdataData.debug_desc = httpResponse.ReadString("debug_desc");
  106. mUpdataData.debug_url = httpResponse.ReadString("debug_url");
  107. mUpdataData.debug_ver = httpResponse.ReadString("debug_ver");
  108. mUpdataData.url = httpResponse.ReadString("url");
  109. mUpdataData.desc = httpResponse.ReadString("desc");
  110. mUpdataData.online_ver = httpResponse.ReadString("online_ver");
  111. mUpdataData.debug = mSecretPwdModule.UnLock;
  112. GamePlayerData.Instance.isDebugAccount = mSecretPwdModule.UnLock;
  113. if (mUpdataData.state)
  114. {
  115. StopCoroutine("ChangeScene");
  116. if (mSecretPwdModule.UnLock)
  117. {
  118. mDownClient.SetLink(mUpdataData.debug_url);
  119. }
  120. else
  121. {
  122. mDownClient.SetLink(mUpdataData.url);
  123. }
  124. MText.text = "";
  125. MSlider.gameObject.SetActive(false);
  126. pop.Show(mUpdataData);
  127. }
  128. else
  129. {
  130. pop.Hide();
  131. MSlider.gameObject.SetActive(false);
  132. CDebug.Log("StartCoroutine ChangeScene");
  133. StartCoroutine("ChangeScene");
  134. mDownClient.DeleteOldFile(mUpdataData.debug_url);
  135. mDownClient.DeleteOldFile(mUpdataData.url);
  136. }
  137. }
  138. private IEnumerator ChangeScene()
  139. {
  140. yield return new WaitForSeconds(5f);
  141. CDebug.Log("五秒后尝试切换");
  142. while (isSending || mSecretPwdModule.IsChecking)
  143. {
  144. yield return new WaitForSeconds(3.0f);//没有解锁正在解锁的时候 才会等待
  145. }
  146. CDebug.Log("开始切换场景");
  147. UnityEngine.SceneManagement.SceneManager.LoadScene("GameStart3D_beauty");
  148. }
  149. }
  150. public struct UpdataData
  151. {
  152. public string url;
  153. public string debug_url;
  154. public string debug_ver;
  155. public string online_ver;
  156. public string debug_desc;
  157. public string desc;
  158. public bool state;
  159. public bool debug;
  160. }