FsmCreateDownloader.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using ET;
  4. using UnityEngine;
  5. using YooAsset;
  6. public class FsmCreateDownloader : IFsmNode
  7. {
  8. public string Name { private set; get; } = nameof(FsmCreateDownloader);
  9. void IFsmNode.OnEnter()
  10. {
  11. PatchEventDispatcher.SendPatchStepsChangeMsg(EPatchStates.CreateDownloader);
  12. CreateDownloader();
  13. }
  14. void IFsmNode.OnUpdate()
  15. {
  16. }
  17. void IFsmNode.OnExit()
  18. {
  19. }
  20. void CreateDownloader()
  21. {
  22. Debug.Log("创建补丁下载器.");
  23. int downloadingMaxNum = 10;
  24. int failedTryAgain = 3;
  25. PatchUpdater.Downloader = YooAssets.CreatePatchDownloader(downloadingMaxNum, failedTryAgain);
  26. if (PatchUpdater.Downloader.TotalDownloadCount == 0)
  27. {
  28. Debug.Log("没有发现需要下载的资源");
  29. FsmManager.Transition(nameof(FsmPatchDone));
  30. }
  31. else
  32. {
  33. Debug.Log($"一共发现了{PatchUpdater.Downloader.TotalDownloadCount}个资源需要更新下载。");
  34. // 发现新更新文件后,挂起流程系统
  35. // 注意:开发者需要在下载前检测磁盘空间不足
  36. int totalDownloadCount = PatchUpdater.Downloader.TotalDownloadCount;
  37. long totalDownloadBytes = PatchUpdater.Downloader.TotalDownloadBytes;
  38. PatchEventDispatcher.SendFoundUpdateFilesMsg(totalDownloadCount, totalDownloadBytes);
  39. }
  40. }
  41. }