//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Wednesday, May 23, 2018
|
//--------------------------------------------------------
|
using UnityEngine;
|
using System.Collections;
|
using UnityEngine.UI;
|
using vnxbqy.UI;
|
|
namespace vnxbqy.UI
|
{
|
|
public class InGameDownLoadProgress : MonoBehaviour
|
{
|
[SerializeField] Image m_ProgressSlider;
|
[SerializeField] Text m_ProgressText;
|
[SerializeField] Button m_ViewDownLoad;
|
|
private void Awake()
|
{
|
if (!InGameDownLoad.Instance.hasReward
|
&& InGameDownLoad.Instance.completeDownLoadAccount == PlayerDatas.Instance.baseData.AccID)
|
{
|
m_ProgressText.SetActive(true);
|
m_ProgressText.text = "100%";
|
this.SetActive(true);
|
}
|
else if (InGameDownLoad.Instance.dominantState != InGameDownLoad.Dominant.None)
|
{
|
this.SetActive(true);
|
m_ProgressText.SetActive(true);
|
if (InGameDownLoad.Instance.state != InGameDownLoad.State.Completed)
|
{
|
m_ProgressText.text = "100%";
|
}
|
else
|
{
|
var progress = Mathf.RoundToInt(InGameDownLoad.Instance.progress * 100);
|
m_ProgressText.text = StringUtility.Contact(progress, "%");
|
}
|
}
|
else
|
{
|
this.SetActive(false);
|
}
|
|
InGameDownLoad.Instance.downLoadStateChangeEvent += OnDownLoadStateChange;
|
InGameDownLoad.Instance.dominantDownLoadEvent += OnDownLoadDominantStateChange;
|
m_ViewDownLoad.AddListener(OpenInGameDownloadWin);
|
}
|
|
private void OnEnable()
|
{
|
UpdateDownLoadProgress();
|
GlobalTimeEvent.Instance.secondEvent += OnPerSecond;
|
}
|
|
private void OnDisable()
|
{
|
GlobalTimeEvent.Instance.secondEvent -= OnPerSecond;
|
}
|
|
private void OnDestroy()
|
{
|
m_ViewDownLoad.RemoveAllListeners();
|
}
|
|
private void OnDownLoadDominantStateChange(InGameDownLoad.Dominant _dominant)
|
{
|
UpdateDownLoadProgress();
|
this.SetActive(InGameDownLoad.Instance.dominantState != InGameDownLoad.Dominant.None);
|
}
|
|
private void OnDownLoadStateChange(InGameDownLoad.State _step)
|
{
|
switch (_step)
|
{
|
case InGameDownLoad.State.Completed:
|
this.SetActive(false);
|
break;
|
case InGameDownLoad.State.None:
|
case InGameDownLoad.State.Prepared:
|
case InGameDownLoad.State.DownLoad:
|
if (InGameDownLoad.Instance.dominantState != InGameDownLoad.Dominant.None)
|
{
|
UpdateDownLoadProgress();
|
this.SetActive(true);
|
}
|
else
|
{
|
this.SetActive(false);
|
}
|
|
m_ProgressText.SetActive(true);
|
break;
|
case InGameDownLoad.State.Award:
|
this.SetActive(true);
|
m_ProgressText.SetActive(true);
|
m_ProgressText.text = "100%";
|
break;
|
}
|
}
|
|
private void OnPerSecond()
|
{
|
UpdateDownLoadProgress();
|
}
|
|
private void UpdateDownLoadProgress()
|
{
|
m_ProgressSlider.fillAmount = InGameDownLoad.Instance.progress;
|
if (m_ProgressText != null)
|
{
|
if (InGameDownLoad.Instance.state == InGameDownLoad.State.Award)
|
{
|
m_ProgressText.text = "100%";
|
}
|
else
|
{
|
var progress = Mathf.RoundToInt(InGameDownLoad.Instance.progress * 100);
|
m_ProgressText.text = StringUtility.Contact(Mathf.Clamp(progress, 0, 99), "%");
|
}
|
}
|
}
|
|
private void OpenInGameDownloadWin()
|
{
|
switch (InGameDownLoad.Instance.state)
|
{
|
case InGameDownLoad.State.DownLoad:
|
case InGameDownLoad.State.None:
|
case InGameDownLoad.State.Pause:
|
case InGameDownLoad.State.Prepared:
|
WindowCenter.Instance.Open<InGameDownLoadWin>();
|
break;
|
case InGameDownLoad.State.Award:
|
WindowCenter.Instance.Open<InGameDownLoadWin>();
|
break;
|
case InGameDownLoad.State.Completed:
|
break;
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|