CLoaderConfig.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. namespace Engine.CLoader
  5. {
  6. /// <summary>资源配置数据</summary>
  7. public class CLoaderConfig
  8. {
  9. #region 单利
  10. private static CLoaderConfig instance;
  11. /// <summary>单利对象</summary>
  12. public static CLoaderConfig GetInstance()
  13. {
  14. if (instance == null)
  15. {
  16. instance = new CLoaderConfig();
  17. }
  18. return instance;
  19. }
  20. #endregion
  21. /// <summary>全部资源的配置字典</summary>
  22. private Dictionary<string, CAssetsConfigInfo> dictAssetsConfigInfo = new Dictionary<string, CAssetsConfigInfo>();
  23. public void ReadConfig(UnityEngine.Object dataAssetsObj)
  24. {
  25. if (dataAssetsObj==null)
  26. {
  27. return;
  28. }
  29. UnityEngine.TextAsset textAsset = (UnityEngine.TextAsset)dataAssetsObj;
  30. CByteArray byteArr = new CByteArray(textAsset.bytes);
  31. int assetCount = byteArr.ReadInt();
  32. for (int i = 0; i < assetCount; i++)
  33. {
  34. CAssetsConfigInfo configInfo = new CAssetsConfigInfo();
  35. configInfo.assetsName = byteArr.ReadString() + CLoaderConst.AB_POSTFIX;
  36. configInfo.assetsVer = byteArr.ReadString();
  37. configInfo.assetsCatchLevel = (int)byteArr.ReadShort();
  38. configInfo.assetSize = byteArr.ReadLong();
  39. configInfo.assetDepCount = byteArr.ReadShort();
  40. for (short j = 0; j < configInfo.assetDepCount; j++)
  41. {
  42. string depName = byteArr.ReadString();
  43. if (!string.IsNullOrEmpty(depName))
  44. {
  45. configInfo.assetsDepNameList.Add(depName + CLoaderConst.AB_POSTFIX);
  46. }
  47. }
  48. if (!dictAssetsConfigInfo.ContainsKey(configInfo.assetsName))
  49. dictAssetsConfigInfo.Add(configInfo.assetsName, configInfo);
  50. }
  51. }
  52. /// <summary>得到某个资源的配置信息</summary>
  53. public CAssetsConfigInfo GetAssetsConfig(string assetsName)
  54. {
  55. if(dictAssetsConfigInfo.ContainsKey(assetsName))
  56. {
  57. return dictAssetsConfigInfo[assetsName];
  58. }
  59. else
  60. {
  61. #if UNITY_EDITOR
  62. CDebug.LogError("有资源的配置信息是null:" + assetsName);
  63. #endif
  64. return null;
  65. }
  66. }
  67. }
  68. }