CLoaderAB.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using UnityEngine;
  2. using System.Collections;
  3. namespace Engine.CLoader
  4. {
  5. /// <summary>资源加载对象</summary>
  6. public class CLoaderAB
  7. {
  8. /// <summary>下载对象</summary>
  9. private WWW loader3W = null;
  10. /// <summary>是否下载完成</summary>
  11. public bool IsLoadComplete = false;
  12. /// <summary>下载进度,例如进度是10%返回值是10</summary>
  13. public int LoadProgress = 0;
  14. /// <summary>是否下载中</summary>
  15. public bool IsLoadIng = false;
  16. /// <summary>加载的资源名称</summary>
  17. public string assetsName = string.Empty;
  18. /// <summary>开始下载</summary>
  19. public CLoaderAB(){ }
  20. /// <summary>开始下载</summary>
  21. public void StartLoad(string path, string name)
  22. {
  23. assetsName = name;
  24. IsLoadIng = true;
  25. CDebug.Log(path);
  26. loader3W = new WWW(path);
  27. }
  28. public AssetBundle assetsBundle
  29. {
  30. get
  31. {
  32. return loader3W.assetBundle;
  33. }
  34. }
  35. /// <summary>帧函数</summary>
  36. public void OnUpdate()
  37. {
  38. if (loader3W == null)
  39. { return; }
  40. if(loader3W.isDone)
  41. {
  42. //下载完成后的第二帧修改完成 标记
  43. if (LoadProgress == 100)
  44. {
  45. IsLoadComplete = true;
  46. }
  47. LoadProgress = 100;
  48. }
  49. else
  50. {
  51. LoadProgress = (int)(loader3W.progress * 100);
  52. }
  53. }
  54. /// <summary>重置函数</summary>
  55. public void Reset()
  56. {
  57. loader3W = null;
  58. IsLoadComplete = false;
  59. LoadProgress = 0;
  60. IsLoadIng = false;
  61. }
  62. }
  63. }