//-------------------------------------------------------- 
 | 
//    [Author]:           玩个游戏 
 | 
//    [  Date ]:           Tuesday, January 09, 2018 
 | 
//-------------------------------------------------------- 
 | 
  
 | 
using System; 
 | 
using System.Collections; 
 | 
using System.Collections.Generic; 
 | 
using UnityEngine; 
 | 
using UnityEngine.UI; 
 | 
  
 | 
public class DownLoadWin : UIBase 
 | 
{ 
 | 
    [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; 
 | 
  
 | 
    float timer = 1f; 
 | 
  
 | 
    protected override void InitComponent() 
 | 
    { 
 | 
        m_Confirm.AddListener(Confirm); 
 | 
        m_Cancel.AddListener(Cancel); 
 | 
    } 
 | 
  
 | 
    protected override void OnPreOpen() 
 | 
    { 
 | 
        timer = 1f; 
 | 
        if (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork) 
 | 
        { 
 | 
            DownLoadAndDiscompressHotTask.Instance.StartDownLoad(); 
 | 
        } 
 | 
  
 | 
        OnDownLoadStepChange(DownLoadAndDiscompressHotTask.Instance.step); 
 | 
  
 | 
    } 
 | 
  
 | 
    protected override void OnOpen() 
 | 
    { 
 | 
        DownLoadAndDiscompressHotTask.Instance.downLoadStepChangeEvent += OnDownLoadStepChange; 
 | 
    } 
 | 
  
 | 
    protected override void OnPreClose() 
 | 
    { 
 | 
        DownLoadAndDiscompressHotTask.Instance.downLoadStepChangeEvent -= OnDownLoadStepChange; 
 | 
    } 
 | 
  
 | 
    protected override void OnClose() 
 | 
    { 
 | 
    } 
 | 
  
 | 
    private void OnDownLoadStepChange(DownLoadAndDiscompressHotTask.Step _step) 
 | 
    { 
 | 
        switch (_step) 
 | 
        { 
 | 
            case DownLoadAndDiscompressHotTask.Step.DownLoadPrepared: 
 | 
                m_ContainerHint.SetActive(true); 
 | 
                m_ContainerProgress.SetActive(false); 
 | 
                DisplayHintContent(); 
 | 
                break; 
 | 
            case DownLoadAndDiscompressHotTask.Step.DownLoad: 
 | 
                m_ContainerHint.SetActive(false); 
 | 
                m_ContainerProgress.SetActive(true); 
 | 
                DisplayHintContent(); 
 | 
                break; 
 | 
        } 
 | 
    } 
 | 
  
 | 
    protected void LateUpdate() 
 | 
    { 
 | 
        var step = DownLoadAndDiscompressHotTask.Instance.step; 
 | 
        if (step == DownLoadAndDiscompressHotTask.Step.DownLoad) 
 | 
        { 
 | 
            timer += Time.deltaTime; 
 | 
            if (timer > 1f) 
 | 
            { 
 | 
                timer -= 1f; 
 | 
                m_ProgressSlider.value = DownLoadAndDiscompressHotTask.Instance.progress; 
 | 
                var totalSizeString = ((float)DownLoadAndDiscompressHotTask.Instance.totalSize / DownLoadAndDiscompressHotTask.BYTE_PER_MILLIONBYTE).ToString("f1"); 
 | 
                var downLoadedSize = Mathf.Clamp(DownloadHotMgr.Instance.DownloadedBytes, 0, DownLoadAndDiscompressHotTask.Instance.totalSize - 1); 
 | 
                var downLoadedSizeString = ((float)downLoadedSize / DownLoadAndDiscompressHotTask.BYTE_PER_MILLIONBYTE).ToString("f1"); 
 | 
  
 | 
                m_Progress.text = Language.GetFromLocal(13, StringUtility.Contact(downLoadedSizeString, "M", "/", totalSizeString, "M")); 
 | 
  
 | 
                if (downLoadedSize >= DownLoadAndDiscompressHotTask.Instance.totalSize) 
 | 
                { 
 | 
                    m_DownLoadSpeed.text = StringUtility.Contact(UnityEngine.Random.Range(5, 10), "KB/S"); 
 | 
                } 
 | 
                else 
 | 
                { 
 | 
                    m_DownLoadSpeed.text = DownloadHotMgr.Instance.SpeedFormat; 
 | 
                } 
 | 
            } 
 | 
        } 
 | 
    } 
 | 
  
 | 
    private void DisplayHintContent() 
 | 
    { 
 | 
        var step = DownLoadAndDiscompressHotTask.Instance.step; 
 | 
  
 | 
        switch (step) 
 | 
        { 
 | 
            case DownLoadAndDiscompressHotTask.Step.DownLoadPrepared: 
 | 
                var totalCount = DownLoadAndDiscompressHotTask.Instance.totalCount; 
 | 
                var totalSize = DownLoadAndDiscompressHotTask.Instance.totalSize; 
 | 
  
 | 
                if (totalSize > DownLoadAndDiscompressHotTask.BYTE_PER_MILLIONBYTE) 
 | 
                { 
 | 
                    var sizeDescription = ((float)totalSize / DownLoadAndDiscompressHotTask.BYTE_PER_MILLIONBYTE).ToString("f1"); 
 | 
                    m_Content.text = Language.GetFromLocal(DownLoadAndDiscompressHotTask.Instance.restartApp ? 1 : 2, totalCount, sizeDescription); 
 | 
                } 
 | 
                else 
 | 
                { 
 | 
                    var sizeDescription = ((float)totalSize / DownLoadAndDiscompressHotTask.BYTE_PER_KILOBYTE).ToString("f1"); 
 | 
                    m_Content.text = Language.GetFromLocal(DownLoadAndDiscompressHotTask.Instance.restartApp ? 11 : 12, totalCount, sizeDescription); 
 | 
                } 
 | 
                break; 
 | 
            case DownLoadAndDiscompressHotTask.Step.DownLoad: 
 | 
                m_Content.text = Language.GetFromLocal(3); 
 | 
                break; 
 | 
        } 
 | 
    } 
 | 
  
 | 
    private void Confirm() 
 | 
    { 
 | 
        timer = 1f; 
 | 
        var step = DownLoadAndDiscompressHotTask.Instance.step; 
 | 
  
 | 
        switch (step) 
 | 
        { 
 | 
            case DownLoadAndDiscompressHotTask.Step.DownLoadPrepared: 
 | 
                DownLoadAndDiscompressHotTask.Instance.StartDownLoad(); 
 | 
                break; 
 | 
        } 
 | 
    } 
 | 
  
 | 
    private void Cancel() 
 | 
    { 
 | 
        Application.Quit(); 
 | 
    } 
 | 
  
 | 
} 
 |