using System.Globalization; using UnityEngine; using UnityEngine.Events; namespace AssetUpdate { public class ProjectDownloadAction : AssetDownloadAction { public const string downloadWin = "Prefab/UpdateGameWin"; private AssetUpdateWin _updateWin; protected override void CreateConfirmUi(UnityAction callback) { LiteConfirmWin.Open("游戏更新", string.Format("需要下载 {0} 总大小的资源。", GetFileSizeDescription(totalSize)), new LiteConfirmButtonData("确定", () => callback(true))); } protected override void CreateDownloadUi() { var canvas = Object.FindObjectOfType(); var prefab = Resources.Load(downloadWin); var instance = Object.Instantiate(prefab, canvas.transform); _updateWin = instance.GetComponent(); _updateWin.downloadAction = this; } protected override void ShowComplete() { _updateWin.ShowComplete(); } protected override void RemoveDownloadUi() { if (_updateWin) Object.Destroy(_updateWin.gameObject); } private static string GetFileSizeDescription(long size) { string result; const int gSize = 1024 * 1024 * 1024; const int mSize = 1024 * 1024; const int kSize = 1024; // 暂时不整理ToString通用化的问题 if (size > gSize) result = ((double) size / gSize).ToString("#0.##", CultureInfo.InvariantCulture) + "G"; else if (size > mSize) result = ((double) size / mSize).ToString("#0.##", CultureInfo.InvariantCulture) + "M"; else if (size > kSize) result = ((double) size / kSize).ToString("#0.##", CultureInfo.InvariantCulture) + "K"; else result = size.ToString(CultureInfo.InvariantCulture) + "B"; return result; } } }