| | |
| | | //-------------------------------------------------------- |
| | | // [Author]: 第二世界 |
| | | // [ Date ]: Wednesday, March 28, 2018 |
| | | //-------------------------------------------------------- |
| | | |
| | | using System; |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using UnityEngine; |
| | | using UnityEngine.UI; |
| | | using System.IO; |
| | | |
| | | namespace Snxxz.UI |
| | | { |
| | | |
| | | public class VersionUpdateWin : Window |
| | | { |
| | | [SerializeField] RectTransform m_ContainerHint; |
| | | [SerializeField] RichText m_Content; |
| | | [SerializeField] Button m_Confirm; |
| | | |
| | | [SerializeField] Transform m_ContainerProgress; |
| | | [SerializeField] SmoothSlider m_ProgressSlider; |
| | | [SerializeField] Text m_Progress; |
| | | [SerializeField] Text m_DownLoadSpeed; |
| | | |
| | | float timer = 1f; |
| | | |
| | | #region Built-in |
| | | |
| | | protected override void BindController() |
| | | { |
| | | m_Confirm.AddListener(Confirm); |
| | | } |
| | | |
| | | protected override void AddListeners() |
| | | { |
| | | } |
| | | |
| | | protected override void OnPreOpen() |
| | | { |
| | | OnDownLoadStepChange(VersionUtility.Instance.step); |
| | | } |
| | | |
| | | protected override void OnAfterOpen() |
| | | { |
| | | VersionUtility.Instance.downLoadStepChangeEvent += OnDownLoadStepChange; |
| | | } |
| | | |
| | | protected override void OnPreClose() |
| | | { |
| | | VersionUtility.Instance.downLoadStepChangeEvent -= OnDownLoadStepChange; |
| | | } |
| | | |
| | | protected override void OnAfterClose() |
| | | { |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | private void OnDownLoadStepChange(VersionUtility.Step _step) |
| | | { |
| | | switch (_step) |
| | | { |
| | | case VersionUtility.Step.None: |
| | | break; |
| | | case VersionUtility.Step.ApkExist: |
| | | m_ContainerHint.gameObject.SetActive(true); |
| | | m_ContainerProgress.gameObject.SetActive(false); |
| | | DisplayHintContent(); |
| | | break; |
| | | case VersionUtility.Step.DownLoadPrepared: |
| | | case VersionUtility.Step.DownLoadFailed: |
| | | m_ContainerHint.gameObject.SetActive(true); |
| | | m_ContainerProgress.gameObject.SetActive(false); |
| | | DisplayHintContent(); |
| | | break; |
| | | case VersionUtility.Step.DownLoad: |
| | | m_ContainerHint.gameObject.SetActive(false); |
| | | m_ContainerProgress.gameObject.SetActive(true); |
| | | DisplayHintContent(); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | protected override void LateUpdate() |
| | | { |
| | | base.LateUpdate(); |
| | | |
| | | var step = VersionUtility.Instance.step; |
| | | if (step == VersionUtility.Step.DownLoad) |
| | | { |
| | | timer += Time.deltaTime; |
| | | if (timer > 1f) |
| | | { |
| | | timer -= 1f; |
| | | m_ProgressSlider.value = VersionUtility.Instance.progress; |
| | | m_Progress.text = StringUtility.Contact((VersionUtility.Instance.progress * 100).ToString("f0"), "%"); |
| | | } |
| | | |
| | | if (Time.frameCount % 2 == 0) |
| | | { |
| | | m_DownLoadSpeed.text = RemoteFile.DownloadSpeed; |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void DisplayHintContent() |
| | | { |
| | | var step = VersionUtility.Instance.step; |
| | | |
| | | switch (step) |
| | | { |
| | | case VersionUtility.Step.None: |
| | | m_Content.text = Language.GetFromLocal(4); |
| | | break; |
| | | case VersionUtility.Step.ApkExist: |
| | | m_Content.text = Language.GetFromLocal(5); |
| | | break; |
| | | case VersionUtility.Step.DownLoadPrepared: |
| | | if (Application.platform == RuntimePlatform.Android) |
| | | { |
| | | var totalSize = VersionUtility.Instance.versionInfo.GetLatestVersion().file_size; |
| | | var sizeDescription = ((float)totalSize / DownLoadAndDiscompressTask.BYTE_PER_KILOBYTE).ToString("f1"); |
| | | switch (Application.internetReachability) |
| | | { |
| | | case NetworkReachability.NotReachable: |
| | | m_Content.text = Language.GetFromLocal(6, sizeDescription); |
| | | break; |
| | | case NetworkReachability.ReachableViaCarrierDataNetwork: |
| | | m_Content.text = Language.GetFromLocal(7, sizeDescription); |
| | | break; |
| | | case NetworkReachability.ReachableViaLocalAreaNetwork: |
| | | m_Content.text = Language.GetFromLocal(8, sizeDescription); |
| | | break; |
| | | } |
| | | } |
| | | else if (Application.platform == RuntimePlatform.IPhonePlayer) |
| | | { |
| | | m_Content.text = Language.GetFromLocal(9); |
| | | } |
| | | break; |
| | | case VersionUtility.Step.DownLoad: |
| | | m_Content.text = Language.GetFromLocal(3); |
| | | break; |
| | | case VersionUtility.Step.DownLoadFailed: |
| | | m_Content.text = Language.GetFromLocal(10); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | private void Confirm() |
| | | { |
| | | timer = 1f; |
| | | var step = VersionUtility.Instance.step; |
| | | |
| | | switch (step) |
| | | { |
| | | case VersionUtility.Step.None: |
| | | VersionUtility.Instance.RequestVersionCheck(); |
| | | break; |
| | | case VersionUtility.Step.ApkExist: |
| | | var version = VersionUtility.Instance.versionInfo.GetLatestVersion(); |
| | | var remoteURL = version.download_url; |
| | | var fileName = Path.GetFileName(remoteURL); |
| | | var apkLocalURL = StringUtility.Contact(VersionUtility.Instance.androidRoot, "/", fileName); |
| | | SDKUtility.Instance.InstallAPK(apkLocalURL); |
| | | break; |
| | | case VersionUtility.Step.DownLoadPrepared: |
| | | if (Application.platform == RuntimePlatform.Android) |
| | | { |
| | | VersionUtility.Instance.StartDownLoad(); |
| | | } |
| | | else if (Application.platform == RuntimePlatform.IPhonePlayer) |
| | | { |
| | | Application.OpenURL(VersionUtility.Instance.versionInfo.GetLatestVersion().download_url); |
| | | //打开应用商店链接 |
| | | } |
| | | break; |
| | | case VersionUtility.Step.DownLoadFailed: |
| | | VersionUtility.Instance.StartDownLoad(); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | //--------------------------------------------------------
|
| | | // [Author]: 第二世界
|
| | | // [ Date ]: Wednesday, March 28, 2018
|
| | | //--------------------------------------------------------
|
| | |
|
| | | using System;
|
| | | using System.Collections;
|
| | | using System.Collections.Generic;
|
| | | using UnityEngine;
|
| | | using UnityEngine.UI;
|
| | | using System.IO;
|
| | |
|
| | | namespace Snxxz.UI
|
| | | {
|
| | |
|
| | | public class VersionUpdateWin : Window
|
| | | {
|
| | | [SerializeField] RectTransform m_ContainerHint;
|
| | | [SerializeField] RichText m_Content;
|
| | | [SerializeField] Button m_Confirm;
|
| | |
|
| | | [SerializeField] Transform m_ContainerProgress;
|
| | | [SerializeField] SmoothSlider m_ProgressSlider;
|
| | | [SerializeField] Text m_Progress;
|
| | | [SerializeField] Text m_DownLoadSpeed;
|
| | |
|
| | | float timer = 1f;
|
| | |
|
| | | #region Built-in
|
| | |
|
| | | protected override void BindController()
|
| | | {
|
| | | m_Confirm.AddListener(Confirm);
|
| | | }
|
| | |
|
| | | protected override void AddListeners()
|
| | | {
|
| | | }
|
| | |
|
| | | protected override void OnPreOpen()
|
| | | {
|
| | | OnDownLoadStepChange(VersionUtility.Instance.step);
|
| | | }
|
| | |
|
| | | protected override void OnAfterOpen()
|
| | | {
|
| | | VersionUtility.Instance.downLoadStepChangeEvent += OnDownLoadStepChange;
|
| | | }
|
| | |
|
| | | protected override void OnPreClose()
|
| | | {
|
| | | VersionUtility.Instance.downLoadStepChangeEvent -= OnDownLoadStepChange;
|
| | | }
|
| | |
|
| | | protected override void OnAfterClose()
|
| | | {
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | private void OnDownLoadStepChange(VersionUtility.Step _step)
|
| | | {
|
| | | switch (_step)
|
| | | {
|
| | | case VersionUtility.Step.None:
|
| | | break;
|
| | | case VersionUtility.Step.ApkExist:
|
| | | m_ContainerHint.gameObject.SetActive(true);
|
| | | m_ContainerProgress.gameObject.SetActive(false);
|
| | | DisplayHintContent();
|
| | | break;
|
| | | case VersionUtility.Step.DownLoadPrepared:
|
| | | case VersionUtility.Step.DownLoadFailed:
|
| | | m_ContainerHint.gameObject.SetActive(true);
|
| | | m_ContainerProgress.gameObject.SetActive(false);
|
| | | DisplayHintContent();
|
| | | break;
|
| | | case VersionUtility.Step.DownLoad:
|
| | | m_ContainerHint.gameObject.SetActive(false);
|
| | | m_ContainerProgress.gameObject.SetActive(true);
|
| | | DisplayHintContent();
|
| | | break;
|
| | | }
|
| | | }
|
| | |
|
| | | protected override void LateUpdate()
|
| | | {
|
| | | base.LateUpdate();
|
| | |
|
| | | var step = VersionUtility.Instance.step;
|
| | | if (step == VersionUtility.Step.DownLoad)
|
| | | {
|
| | | timer += Time.deltaTime;
|
| | | if (timer > 1f)
|
| | | {
|
| | | timer -= 1f;
|
| | | m_ProgressSlider.value = VersionUtility.Instance.progress;
|
| | | m_Progress.text = StringUtility.Contact((VersionUtility.Instance.progress * 100).ToString("f0"), "%");
|
| | | }
|
| | |
|
| | | if (Time.frameCount % 2 == 0)
|
| | | {
|
| | | m_DownLoadSpeed.text = RemoteFile.DownloadSpeed;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | private void DisplayHintContent()
|
| | | {
|
| | | var step = VersionUtility.Instance.step;
|
| | |
|
| | | switch (step)
|
| | | {
|
| | | case VersionUtility.Step.None:
|
| | | m_Content.text = Language.GetFromLocal(4);
|
| | | break;
|
| | | case VersionUtility.Step.ApkExist:
|
| | | m_Content.text = Language.GetFromLocal(5);
|
| | | break;
|
| | | case VersionUtility.Step.DownLoadPrepared:
|
| | | if (Application.platform == RuntimePlatform.Android)
|
| | | {
|
| | | var totalSize = VersionUtility.Instance.versionInfo.GetLatestVersion().file_size;
|
| | | var sizeDescription = ((float)totalSize / DownLoadAndDiscompressTask.BYTE_PER_KILOBYTE).ToString("f1");
|
| | | switch (Application.internetReachability)
|
| | | {
|
| | | case NetworkReachability.NotReachable:
|
| | | m_Content.text = Language.GetFromLocal(6, sizeDescription);
|
| | | break;
|
| | | case NetworkReachability.ReachableViaCarrierDataNetwork:
|
| | | m_Content.text = Language.GetFromLocal(7, sizeDescription);
|
| | | break;
|
| | | case NetworkReachability.ReachableViaLocalAreaNetwork:
|
| | | m_Content.text = Language.GetFromLocal(8, sizeDescription);
|
| | | break;
|
| | | }
|
| | | }
|
| | | else if (Application.platform == RuntimePlatform.IPhonePlayer)
|
| | | {
|
| | | m_Content.text = Language.GetFromLocal(9);
|
| | | }
|
| | | break;
|
| | | case VersionUtility.Step.DownLoad:
|
| | | m_Content.text = Language.GetFromLocal(3);
|
| | | break;
|
| | | case VersionUtility.Step.DownLoadFailed:
|
| | | m_Content.text = Language.GetFromLocal(10);
|
| | | break;
|
| | | }
|
| | | }
|
| | |
|
| | | private void Confirm()
|
| | | {
|
| | | timer = 1f;
|
| | | var step = VersionUtility.Instance.step;
|
| | |
|
| | | switch (step)
|
| | | {
|
| | | case VersionUtility.Step.None:
|
| | | VersionUtility.Instance.RequestVersionCheck();
|
| | | break;
|
| | | case VersionUtility.Step.ApkExist:
|
| | | var version = VersionUtility.Instance.versionInfo.GetLatestVersion();
|
| | | var remoteURL = version.download_url;
|
| | | var fileName = Path.GetFileName(remoteURL);
|
| | | var apkLocalURL = StringUtility.Contact(VersionUtility.Instance.androidRoot, "/", fileName);
|
| | | SDKUtility.Instance.InstallAPK(apkLocalURL);
|
| | | break;
|
| | | case VersionUtility.Step.DownLoadPrepared:
|
| | | if (Application.platform == RuntimePlatform.Android)
|
| | | {
|
| | | VersionUtility.Instance.StartDownLoad();
|
| | | }
|
| | | else if (Application.platform == RuntimePlatform.IPhonePlayer)
|
| | | {
|
| | | Application.OpenURL(VersionUtility.Instance.versionInfo.GetLatestVersion().download_url);
|
| | | //打开应用商店链接
|
| | | }
|
| | | break;
|
| | | case VersionUtility.Step.DownLoadFailed:
|
| | | VersionUtility.Instance.StartDownLoad();
|
| | | break;
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | |
|