123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- 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;
- }
|