CheckResUpdate.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace ET
  6. {
  7. public class CheckResUpdate : MonoBehaviour
  8. {
  9. void Start()
  10. {
  11. var progress = this.gameObject.transform.Find("Img_bar").gameObject.GetComponent<Image>();
  12. var txtProgress = this.gameObject.transform.Find("Text_progress").gameObject.GetComponent<Text>();
  13. YooAssetProxy.InitHostCallbacks((onStateChanged) =>
  14. {
  15. txtProgress.text = onStateChanged.CurrentStates.ToString();
  16. if (onStateChanged.CurrentStates == EPatchStates.PatchDone)
  17. {
  18. txtProgress.text = "资源下载完毕,正在加载核心逻辑。。。";
  19. }
  20. }, (onProcessUpdated) =>
  21. {
  22. string currentSizeMB = (onProcessUpdated.CurrentDownloadSizeBytes / 1048576f).ToString("f1");
  23. string totalSizeMB = (onProcessUpdated.TotalDownloadSizeBytes / 1048576f).ToString("f1");
  24. string text =
  25. $"资源下载中:{onProcessUpdated.CurrentDownloadCount}/{onProcessUpdated.TotalDownloadCount} {currentSizeMB}MB/{totalSizeMB}MB";
  26. txtProgress.text = text;
  27. progress.fillAmount = onProcessUpdated.CurrentDownloadSizeBytes * 1.0f /
  28. onProcessUpdated.TotalDownloadSizeBytes;
  29. });
  30. }
  31. }
  32. }