LoadInfo.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class LoadInfo
  6. {
  7. public AsyncOperation asyncOperation;
  8. //
  9. // 摘要:
  10. // Has the operation finished? (Read Only)
  11. public bool isDone;
  12. //
  13. // 摘要:
  14. // What's the operation's progress. (Read Only)
  15. public float progress;
  16. public UnityEngine.Object asset;
  17. public System.Object[] allAssets;
  18. /// <summary>
  19. /// 封装系统自带的加载完成通知事件
  20. /// </summary>
  21. /// <param name="initOp"></param>
  22. public void InitLoadInfo(AsyncOperation initOp)
  23. {
  24. this.asyncOperation = initOp;
  25. if (this.asyncOperation != null)
  26. {
  27. this.asyncOperation.completed += OnCompleted;
  28. }
  29. }
  30. private void OnCompleted(AsyncOperation operation)
  31. {
  32. isDone = true;
  33. progress = 1;
  34. if (operation is ResourceRequest)
  35. {
  36. asset = (operation as ResourceRequest).asset;
  37. }
  38. else if (operation is AssetBundleRequest)
  39. {
  40. asset = (operation as AssetBundleRequest).asset;
  41. allAssets = (operation as AssetBundleRequest).allAssets;
  42. }
  43. else if (operation is DataAsyncOperation)
  44. {
  45. asset = (operation as DataAsyncOperation).asset;
  46. }
  47. }
  48. }