SceneLoadAsync.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. 
  2. using XGame.Framework.Asyncs;
  3. namespace XGame.Framework.Asset
  4. {
  5. internal class SceneLoadAsync : Async, IAssetAsync
  6. {
  7. public string AddressableName { get; internal set; }
  8. /// <summary>
  9. /// async的Start标记
  10. /// </summary>
  11. private bool isStart;
  12. /// <summary>
  13. /// asyncGroup完成标记
  14. /// </summary>
  15. private bool groupCompleted;
  16. /// <summary>
  17. /// scene所依赖的bundle的AsyncGroup
  18. /// </summary>
  19. private AsyncGroup bundleAsyncGroup;
  20. internal AsyncGroup BundleAsyncGroup
  21. {
  22. get => bundleAsyncGroup;
  23. set
  24. {
  25. bundleAsyncGroup = value;
  26. bundleAsyncGroup?.On(OnGroupCompleted);
  27. }
  28. }
  29. public int AssetHash { get; set; }
  30. public override float Progress
  31. {
  32. get {
  33. float progress = bundleAsyncGroup?.Progress ?? 0;
  34. return progress / 2;
  35. }
  36. protected set => base.Progress = value;
  37. }
  38. public object GetResult()
  39. {
  40. return null;
  41. }
  42. public void Start()
  43. {
  44. isStart = true;
  45. if(bundleAsyncGroup == null || groupCompleted)
  46. {
  47. Completed();
  48. }
  49. }
  50. private void OnGroupCompleted(IAsync async)
  51. {
  52. groupCompleted = true;
  53. if (isStart)
  54. {
  55. Completed();
  56. }
  57. }
  58. private void Clear()
  59. {
  60. isStart = false;
  61. groupCompleted = false;
  62. bundleAsyncGroup = null;
  63. }
  64. }
  65. }