using System.Collections; using System.Collections.Generic; using UnityEngine; using SC.InputSystem; public class VersionCheck : MonoBehaviour { [SerializeField] private UnityEngine.UI.Text MText; [SerializeField] private Slider3D MSlider; [SerializeField] private PopBase pop; [SerializeField] private SCButton DebugMark;//是否是测试服的标记 private bool isSending; [SerializeField] private SecretPwdModule mSecretPwdModule;//解锁的模块 [SerializeField] private DownClient mDownClient; void Start() { DebugMark.onClick.AddListener(SendCheckMsg); CDebug.Log("当前版本 " + Application.version); Engine.Http.HttpManager.GetInstance().AddHttpMessageEvent(HandleHttpMessage); SendCheckMsg(); mDownClient.SetUI(MText, MSlider); mSecretPwdModule.changeAction += UnLockChangeAction; UnLockChangeAction(); } void OnDestroy() { DebugMark.onClick.RemoveListener(SendCheckMsg); Engine.Http.HttpManager.GetInstance().DelHttMessageEvent(HandleHttpMessage); } private void UnLockChangeAction() { DebugMark.gameObject.SetActive(mSecretPwdModule.UnLock); if(mSecretPwdModule.UnLock) { StopCoroutine("ChangeScene"); } else { CDebug.Log("重新发送默认的"); SendCheckMsg(); } } private void SendCheckMsg() { if(isSending) { return; } pop.Hide(); isSending = true; HttpStaticMessage.AutoSendHttpVerson(Application.version, mSecretPwdModule.UnLock); } void LateUpdate() { OnUpdate(CStaticMethod.SystemFrameTime()); } void FixedUpdate() { OnFixedUpdate(CStaticMethod.SystemFrameTime()); } public void OnUpdate(int nTime) { Engine.Http.HttpManager.GetInstance().OnUpdate(nTime); } public void OnFixedUpdate(int nTime) { //Http请求 Engine.Http.HttpManager.GetInstance().OnFixedUpdate(nTime); } private bool HandleHttpMessage(Engine.Http.HttpResponse httpResponse) { if (httpResponse == null) { return false; } if (!httpResponse.isSuccess) { if (httpResponse.ResponseStatu == -99999) { MText.text = httpResponse.ResponseMsg; } return false; } CDebug.Log("接受消息" + httpResponse.Code); switch (httpResponse.Code) { //获取角色信息 case MsgConst.HTTP_MSG_VERSION: CheckRes(httpResponse); break; } return false; } private UpdataData mUpdataData; private void CheckRes(Engine.Http.HttpResponse httpResponse) { isSending = false; mUpdataData = new UpdataData(); mUpdataData.state = httpResponse.ReadBool("state"); mUpdataData.debug_desc = httpResponse.ReadString("debug_desc"); mUpdataData.debug_url = httpResponse.ReadString("debug_url"); mUpdataData.debug_ver = httpResponse.ReadString("debug_ver"); mUpdataData.url = httpResponse.ReadString("url"); mUpdataData.desc = httpResponse.ReadString("desc"); mUpdataData.online_ver = httpResponse.ReadString("online_ver"); mUpdataData.debug = mSecretPwdModule.UnLock; GamePlayerData.Instance.isDebugAccount = mSecretPwdModule.UnLock; if (mUpdataData.state) { StopCoroutine("ChangeScene"); if (mSecretPwdModule.UnLock) { mDownClient.SetLink(mUpdataData.debug_url); } else { mDownClient.SetLink(mUpdataData.url); } MText.text = ""; MSlider.gameObject.SetActive(false); pop.Show(mUpdataData); } else { pop.Hide(); MSlider.gameObject.SetActive(false); CDebug.Log("StartCoroutine ChangeScene"); StartCoroutine("ChangeScene"); mDownClient.DeleteOldFile(mUpdataData.debug_url); mDownClient.DeleteOldFile(mUpdataData.url); } } private IEnumerator ChangeScene() { yield return new WaitForSeconds(5f); CDebug.Log("五秒后尝试切换"); while (isSending || mSecretPwdModule.IsChecking) { yield return new WaitForSeconds(3.0f);//没有解锁正在解锁的时候 才会等待 } CDebug.Log("开始切换场景"); UnityEngine.SceneManagement.SceneManager.LoadScene("GameStart3D_beauty"); } } public struct UpdataData { public string url; public string debug_url; public string debug_ver; public string online_ver; public string debug_desc; public string desc; public bool state; public bool debug; }