//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Tuesday, January 09, 2018 //-------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace vnxbqy.UI { public class DownLoadWin : Window { [SerializeField] RectTransform m_ContainerHint; [SerializeField] RichText m_Content; [SerializeField] Button m_Confirm; [SerializeField] Button m_Cancel; [SerializeField] Transform m_ContainerProgress; [SerializeField] SmoothSlider m_ProgressSlider; [SerializeField] Text m_Progress; [SerializeField] Text m_DownLoadSpeed; [SerializeField] Transform awardObj; float timer = 1f; #region Built-in protected override void BindController() { } protected override void AddListeners() { m_Confirm.AddListener(Confirm); m_Cancel.AddListener(Cancel); } protected override void OnPreOpen() { timer = 1f; if (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork) { DownLoadAndDiscompressTask.Instance.StartDownLoad(); } OnDownLoadStepChange(DownLoadAndDiscompressTask.Instance.step); awardObj.SetActive(InGameDownLoad.Instance.IsShowDownloadAward()); } protected override void OnAfterOpen() { DownLoadAndDiscompressTask.Instance.downLoadStepChangeEvent += OnDownLoadStepChange; } protected override void OnPreClose() { DownLoadAndDiscompressTask.Instance.downLoadStepChangeEvent -= OnDownLoadStepChange; } protected override void OnAfterClose() { } #endregion private void OnDownLoadStepChange(DownLoadAndDiscompressTask.Step _step) { switch (_step) { case DownLoadAndDiscompressTask.Step.DownLoadPrepared: m_ContainerHint.SetActive(true); m_ContainerProgress.SetActive(false); DisplayHintContent(); break; case DownLoadAndDiscompressTask.Step.DownLoad: m_ContainerHint.SetActive(false); m_ContainerProgress.SetActive(true); DisplayHintContent(); break; } } protected override void LateUpdate() { base.LateUpdate(); var step = DownLoadAndDiscompressTask.Instance.step; if (step == DownLoadAndDiscompressTask.Step.DownLoad) { timer += Time.deltaTime; if (timer > 1f) { timer -= 1f; m_ProgressSlider.value = DownLoadAndDiscompressTask.Instance.progress; var totalSizeString = ((float)DownLoadAndDiscompressTask.Instance.totalSize / DownLoadAndDiscompressTask.BYTE_PER_MILLIONBYTE).ToString("f1"); var downLoadedSize = Mathf.Clamp(DownloadMgr.Instance.DownloadedBytes, 0, DownLoadAndDiscompressTask.Instance.totalSize - 1); var downLoadedSizeString = ((float)downLoadedSize / DownLoadAndDiscompressTask.BYTE_PER_MILLIONBYTE).ToString("f1"); m_Progress.text = Language.GetFromLocal(13, StringUtility.Contact(downLoadedSizeString, "M", "/", totalSizeString, "M")); if (downLoadedSize >= DownLoadAndDiscompressTask.Instance.totalSize) { m_DownLoadSpeed.text = StringUtility.Contact(UnityEngine.Random.Range(5, 10), "KB/S"); } else { m_DownLoadSpeed.text = DownloadMgr.Instance.SpeedFormat; } } } } private void DisplayHintContent() { var step = DownLoadAndDiscompressTask.Instance.step; switch (step) { case DownLoadAndDiscompressTask.Step.DownLoadPrepared: var totalCount = DownLoadAndDiscompressTask.Instance.totalCount; var totalSize = DownLoadAndDiscompressTask.Instance.totalSize; if (totalSize > DownLoadAndDiscompressTask.BYTE_PER_MILLIONBYTE) { var sizeDescription = ((float)totalSize / DownLoadAndDiscompressTask.BYTE_PER_MILLIONBYTE).ToString("f1"); m_Content.text = Language.GetFromLocal(DownLoadAndDiscompressTask.Instance.restartApp ? 1 : 2, totalCount, sizeDescription); } else { var sizeDescription = ((float)totalSize / DownLoadAndDiscompressTask.BYTE_PER_KILOBYTE).ToString("f1"); m_Content.text = Language.GetFromLocal(DownLoadAndDiscompressTask.Instance.restartApp ? 11 : 12, totalCount, sizeDescription); } break; case DownLoadAndDiscompressTask.Step.DownLoad: m_Content.text = Language.GetFromLocal(3); break; } } private void Confirm() { timer = 1f; var step = DownLoadAndDiscompressTask.Instance.step; switch (step) { case DownLoadAndDiscompressTask.Step.DownLoadPrepared: DownLoadAndDiscompressTask.Instance.StartDownLoad(); break; } } private void Cancel() { Application.Quit(); } } }