CheckResUpdate.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. }
  21. }, (onProcessUpdated) =>
  22. {
  23. string currentSizeMB = (onProcessUpdated.CurrentDownloadSizeBytes / 1048576f).ToString("f1");
  24. string totalSizeMB = (onProcessUpdated.TotalDownloadSizeBytes / 1048576f).ToString("f1");
  25. string text =
  26. $"更新资源中:{onProcessUpdated.CurrentDownloadCount}/{onProcessUpdated.TotalDownloadCount} {currentSizeMB}MB/{totalSizeMB}MB";
  27. txtProgress.text = text;
  28. progress.value = onProcessUpdated.CurrentDownloadSizeBytes * 1.0f /
  29. onProcessUpdated.TotalDownloadSizeBytes;
  30. });
  31. }
  32. }
  33. }