CheckResUpdate.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using FairyGUI;
  2. using UnityEngine;
  3. namespace ET
  4. {
  5. public class CheckResUpdate : MonoBehaviour
  6. {
  7. void Start()
  8. {
  9. var view = UIPackage.CreateObject("CheckForResUpdate", "CheckForResUpdate").asCom;
  10. GRoot.inst.AddChild(view);
  11. var progress = view.GetChild("processbar").asProgress;
  12. var txtProgress = view.GetChild("updateInfo");
  13. YooAssetProxy.InitHostCallbacks((onStateChanged) =>
  14. {
  15. txtProgress.text = onStateChanged.CurrentStates.ToString();
  16. if (onStateChanged.CurrentStates == EPatchStates.PatchDone)
  17. {
  18. progress.value = 1f;
  19. txtProgress.text = "加载游戏中……";
  20. GameObject.Destroy(this.gameObject);
  21. }
  22. }, (onProcessUpdated) =>
  23. {
  24. string currentSizeMB = (onProcessUpdated.CurrentDownloadSizeBytes / 1048576f).ToString("f1");
  25. string totalSizeMB = (onProcessUpdated.TotalDownloadSizeBytes / 1048576f).ToString("f1");
  26. string text =
  27. $"更新资源中:{onProcessUpdated.CurrentDownloadCount}/{onProcessUpdated.TotalDownloadCount} {currentSizeMB}MB/{totalSizeMB}MB";
  28. txtProgress.text = text;
  29. progress.value = onProcessUpdated.CurrentDownloadSizeBytes * 1.0f /
  30. onProcessUpdated.TotalDownloadSizeBytes;
  31. });
  32. }
  33. }
  34. }