CheckResUpdate.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. view.name = "CheckForResUpdate";
  11. GRoot.inst.AddChild(view);
  12. var progress = view.GetChild("processbar").asProgress;
  13. var txtProgress = view.GetChild("updateInfo");
  14. YooAssetProxy.InitHostCallbacks((onStateChanged) =>
  15. {
  16. txtProgress.text = onStateChanged.CurrentStates.ToString();
  17. if (onStateChanged.CurrentStates == EPatchStates.PatchDone)
  18. {
  19. progress.value = 1f;
  20. txtProgress.text = "加载游戏中……";
  21. GameObject.Destroy(this.gameObject);
  22. }
  23. }, (onProcessUpdated) =>
  24. {
  25. string currentSizeMB = (onProcessUpdated.CurrentDownloadSizeBytes / 1048576f).ToString("f1");
  26. string totalSizeMB = (onProcessUpdated.TotalDownloadSizeBytes / 1048576f).ToString("f1");
  27. string text =
  28. $"更新资源中:{onProcessUpdated.CurrentDownloadCount}/{onProcessUpdated.TotalDownloadCount} {currentSizeMB}MB/{totalSizeMB}MB";
  29. txtProgress.text = text;
  30. progress.value = onProcessUpdated.CurrentDownloadSizeBytes * 1.0f /
  31. onProcessUpdated.TotalDownloadSizeBytes;
  32. });
  33. }
  34. }
  35. }