Files
JJBB/Assets/Plugins/Script/AssetUpdate/AssetUpdateWin.cs
2024-08-23 15:49:34 +08:00

80 lines
2.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using AssetUpdate;
using UnityEngine;
using UnityEngine.UI;
public class AssetUpdateWin : MonoBehaviour
{
// private Slider _oneProcess;
private Slider _allProcess;
// private Text _oneText;
// private Text _allText;
// private Text _tip;
// public const string oneFormat = "当前文件:{0:P0}";
// public const string allFormat = "全部文件:{0} / {1}";
public ProjectDownloadAction downloadAction { get; set; }
private void Awake()
{
var root = transform;
// var oneRoot = root.Find("OneProgress");
var allRoot = root.Find("AllProgress");
// _oneProcess = oneRoot.Find("Slider").GetComponent<Slider>();
_allProcess = allRoot.Find("Slider").GetComponent<Slider>();
// _oneText = oneRoot.Find("Text").GetComponent<Text>();
// _allText = allRoot.Find("Text").GetComponent<Text>();
// _tip = root.Find("DownloadTip/Text").GetComponent<Text>();
}
private void Start()
{
FirstSceneBg.instance.SetTip("资源更新中...");
// _oneProcess.value = 0f;
_allProcess.value = 0f;
// _oneText.text = string.Empty;
// _allText.text = string.Empty;
}
public void ShowComplete()
{
if (downloadAction != null)
{
var totalSize = downloadAction.totalSize / 1024;
FirstSceneBg.instance.SetTip(string.Format("资源更新中({0}K / {1}K", totalSize, totalSize));
// _oneProcess.value = oneRate;
_allProcess.value = 1f;
}
}
private void Update()
{
if (downloadAction != null)
{
// var current = downloadAction.current;
// var total = downloadAction.downloadList.Count;
if (downloadAction.current < downloadAction.downloadList.Count)
{
var totalSize = downloadAction.totalSize / 1024;
var currentSize = downloadAction.GetCurrentBytes() / 1024;
// var oneRate = downloadAction.GetCurrentProgress();
FirstSceneBg.instance.SetTip(string.Format("资源更新中({0}K / {1}K", currentSize, totalSize));
// _oneProcess.value = oneRate;
_allProcess.value = (float) currentSize / totalSize;
// _oneText.text = string.Format(oneFormat, oneRate);
// _allText.text = string.Format(allFormat, current + 1, total);
}
// 更新完成的情况
else
{
var totalSize = downloadAction.totalSize / 1024;
downloadAction = null;
// _oneProcess.value = 1f;
FirstSceneBg.instance.SetTip(string.Format("资源更新完成({0}K / {1}K", totalSize, totalSize));
_allProcess.value = 1f;
// _oneText.text = string.Format(oneFormat, 1f);
// _allText.text = string.Format(allFormat, total, total);
}
}
}
}