//--------------------------------------------------------
|
// [Author]: 玩个游戏
|
// [ Date ]: Wednesday, May 23, 2018
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
|
public class InGameDownLoadWin : UIBase
|
{
|
[SerializeField] RectTransform m_RewardGotSign;
|
// [SerializeField] RewardPreviewGroup m_RewardGroup;
|
[SerializeField] RectTransform m_ContainerHint;
|
[SerializeField] RichText m_Content;
|
[SerializeField] Button m_StartDownLoad;
|
[SerializeField] Button m_PauseDownLoad;
|
[SerializeField] Button m_Award;
|
[SerializeField] Button m_Close;
|
|
[SerializeField] Transform m_ContainerProgress;
|
[SerializeField] SmoothSlider m_ProgressSlider;
|
[SerializeField] Text m_Progress;
|
[SerializeField] Text m_DownLoadSpeed;
|
[SerializeField] ToggleButton downLoadGo; //加速下载
|
float timer = 1f;
|
|
#region Built-in
|
|
protected override void InitComponent()
|
{
|
m_StartDownLoad.AddListener(StartDownLoad);
|
m_PauseDownLoad.AddListener(PauseDownLoad);
|
m_Award.AddListener(Award);
|
m_Close.AddListener(CloseWindow);
|
downLoadGo.SetListener(() => {
|
downLoadGo.isOn = !downLoadGo.isOn;
|
InGameDownLoad.Instance.downLoadGo = downLoadGo.isOn;
|
DownloadMgr.MaxDownLoadTask = InGameDownLoad.Instance.GetMaxTask();
|
});
|
}
|
|
protected override void OnPreOpen()
|
{
|
timer = 1f;
|
m_RewardGotSign.SetActive(InGameDownLoad.Instance.hasReward);
|
|
// var items = new List<Item>();
|
// foreach (var reward in InGameDownLoad.Instance.rewards)
|
// {
|
// items.Add(new Item(reward.id, reward.count));
|
// }
|
|
// m_RewardGroup.Display(items);
|
OnDownLoadStepChange(InGameDownLoad.Instance.state);
|
downLoadGo.isOn = InGameDownLoad.Instance.downLoadGo;
|
}
|
|
protected override void OnOpen()
|
{
|
InGameDownLoad.Instance.downLoadStateChangeEvent += OnDownLoadStepChange;
|
}
|
|
protected override void OnPreClose()
|
{
|
InGameDownLoad.Instance.downLoadStateChangeEvent -= OnDownLoadStepChange;
|
}
|
|
protected override void OnClose()
|
{
|
}
|
#endregion
|
|
private void OnDownLoadStepChange(InGameDownLoad.State _step)
|
{
|
m_Award.SetActive(_step == InGameDownLoad.State.Award);
|
m_PauseDownLoad.SetActive(_step == InGameDownLoad.State.DownLoad);
|
m_StartDownLoad.SetActive(_step == InGameDownLoad.State.Prepared || _step == InGameDownLoad.State.Pause);
|
m_ContainerProgress.SetActive(_step == InGameDownLoad.State.DownLoad || _step == InGameDownLoad.State.Pause);
|
|
if (_step != InGameDownLoad.State.DownLoad)
|
{
|
m_DownLoadSpeed.text = string.Empty;
|
}
|
|
if (_step == InGameDownLoad.State.Prepared || _step == InGameDownLoad.State.Award)
|
{
|
m_ContainerHint.SetActive(true);
|
DisplayHintContent();
|
}
|
else
|
{
|
m_ContainerHint.SetActive(false);
|
}
|
}
|
|
protected void LateUpdate()
|
{
|
var step = InGameDownLoad.Instance.state;
|
if (step == InGameDownLoad.State.DownLoad)
|
{
|
timer += Time.deltaTime;
|
if (timer > 1f)
|
{
|
timer -= 1f;
|
m_ProgressSlider.value = InGameDownLoad.Instance.progress;
|
var totalSizeString = ((float)InGameDownLoad.Instance.showTotalSize / InGameDownLoad.BYTE_PER_MILLIONBYTE).ToString("f1");
|
var downLoadedSize = Mathf.Clamp(InGameDownLoad.Instance.showDownLoadedSize, 0, InGameDownLoad.Instance.showTotalSize - 1);
|
var downLoadedSizeString = ((float)downLoadedSize / InGameDownLoad.BYTE_PER_MILLIONBYTE).ToString("f1");
|
m_Progress.text = Language.GetFromLocal(13, StringUtility.Contact(downLoadedSizeString, "M", "/", totalSizeString, "M"));
|
|
if (InGameDownLoad.Instance.showDownLoadedSize >= InGameDownLoad.Instance.showTotalSize)
|
{
|
m_DownLoadSpeed.text = StringUtility.Contact(UnityEngine.Random.Range(5, 10), "KB/S");
|
}
|
else
|
{
|
m_DownLoadSpeed.text = DownloadMgr.Instance.SpeedFormat;
|
}
|
}
|
}
|
}
|
|
private void DisplayHintContent()
|
{
|
var step = InGameDownLoad.Instance.state;
|
|
switch (step)
|
{
|
case InGameDownLoad.State.Prepared:
|
var totalCount = InGameDownLoad.Instance.showTotalCount;
|
var totalSize = InGameDownLoad.Instance.showTotalSize;
|
if (totalSize > InGameDownLoad.BYTE_PER_MILLIONBYTE)
|
{
|
var sizeDescription = ((float)totalSize / InGameDownLoad.BYTE_PER_MILLIONBYTE).ToString("f1");
|
m_Content.text = Language.GetFromLocal(19, sizeDescription);
|
}
|
else
|
{
|
var sizeDescription = ((float)totalSize / InGameDownLoad.BYTE_PER_KILOBYTE).ToString("f1");
|
m_Content.text = Language.GetFromLocal(20, sizeDescription);
|
}
|
break;
|
case InGameDownLoad.State.DownLoad:
|
m_Content.text = Language.GetFromLocal(3);
|
break;
|
case InGameDownLoad.State.Pause:
|
m_Content.text = Language.GetFromLocal(21);
|
break;
|
case InGameDownLoad.State.Award:
|
m_Content.text = Language.GetFromLocal(25);
|
break;
|
}
|
}
|
|
private void StartDownLoad()
|
{
|
timer = 1f;
|
switch (InGameDownLoad.Instance.state)
|
{
|
case InGameDownLoad.State.Prepared:
|
case InGameDownLoad.State.Pause:
|
if (Application.internetReachability == NetworkReachability.NotReachable)
|
{
|
ServerTipDetails.DisplayNormalTip(Language.GetFromLocal(24));
|
}
|
else
|
{
|
InGameDownLoad.Instance.StartDownLoad();
|
CloseWindow();
|
}
|
break;
|
default:
|
CloseWindow();
|
break;
|
}
|
}
|
|
private void PauseDownLoad()
|
{
|
timer = 1f;
|
switch (InGameDownLoad.Instance.state)
|
{
|
case InGameDownLoad.State.DownLoad:
|
InGameDownLoad.Instance.Pause();
|
break;
|
default:
|
break;
|
}
|
}
|
|
private void Award()
|
{
|
InGameDownLoad.Instance.RequestDownLoadReward(true);
|
UIManager.Instance.CloseWindow<InGameDownLoadWin>();
|
}
|
|
}
|