CAssetsInfo.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. namespace Engine.CLoader
  5. {
  6. /// <summary>内存中的资源对象</summary>
  7. internal class CAssetsInfo
  8. {
  9. /// <summary>资源的AssetBundle 对象</summary>
  10. public AssetBundle assetsBundle;
  11. /// <summary>资源包名称</summary>
  12. public string assetsName;
  13. /// <summary>资源依赖的资源包</summary>
  14. public List<CAssetsInfo> depAssetsList = new List<CAssetsInfo>();
  15. /// <summary>是否为空资源</summary>
  16. public bool isEmpty = true;
  17. /// <summary>资源使用计算</summary>
  18. private int useCount = 0;
  19. /// <summary>减少使用计数</summary>
  20. public void DelUseCount()
  21. {
  22. useCount--;
  23. //特出处理
  24. useCount = (useCount < 0) ? 0 : useCount;
  25. if(useCount==0)
  26. {
  27. this.Dispose();
  28. }
  29. }
  30. /// <summary>增加使用基数</summary>
  31. public void AddUseCount()
  32. {
  33. useCount++;
  34. }
  35. /// <summary>释放函数</summary>
  36. public void Dispose()
  37. {
  38. if (assetsBundle!=null)
  39. {
  40. assetsBundle.Unload(false);
  41. assetsBundle = null;
  42. }
  43. assetsName = string.Empty;
  44. for (int i = 0; i < depAssetsList.Count; i++)
  45. {
  46. depAssetsList[i].DelUseCount();
  47. }
  48. depAssetsList.Clear();
  49. isEmpty = true;
  50. }
  51. }
  52. }