using UnityEngine; using System.Collections; using System.Collections.Generic; namespace Engine.CLoader { /// 资源配置数据 public class CLoaderConfig { #region 单利 private static CLoaderConfig instance; /// 单利对象 public static CLoaderConfig GetInstance() { if (instance == null) { instance = new CLoaderConfig(); } return instance; } #endregion /// 全部资源的配置字典 private Dictionary dictAssetsConfigInfo = new Dictionary(); public void ReadConfig(UnityEngine.Object dataAssetsObj) { if (dataAssetsObj==null) { return; } UnityEngine.TextAsset textAsset = (UnityEngine.TextAsset)dataAssetsObj; CByteArray byteArr = new CByteArray(textAsset.bytes); int assetCount = byteArr.ReadInt(); for (int i = 0; i < assetCount; i++) { CAssetsConfigInfo configInfo = new CAssetsConfigInfo(); configInfo.assetsName = byteArr.ReadString() + CLoaderConst.AB_POSTFIX; configInfo.assetsVer = byteArr.ReadString(); configInfo.assetsCatchLevel = (int)byteArr.ReadShort(); configInfo.assetSize = byteArr.ReadLong(); configInfo.assetDepCount = byteArr.ReadShort(); for (short j = 0; j < configInfo.assetDepCount; j++) { string depName = byteArr.ReadString(); if (!string.IsNullOrEmpty(depName)) { configInfo.assetsDepNameList.Add(depName + CLoaderConst.AB_POSTFIX); } } if (!dictAssetsConfigInfo.ContainsKey(configInfo.assetsName)) dictAssetsConfigInfo.Add(configInfo.assetsName, configInfo); } } /// 得到某个资源的配置信息 public CAssetsConfigInfo GetAssetsConfig(string assetsName) { if(dictAssetsConfigInfo.ContainsKey(assetsName)) { return dictAssetsConfigInfo[assetsName]; } else { #if UNITY_EDITOR CDebug.LogError("有资源的配置信息是null:" + assetsName); #endif return null; } } } }