12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- namespace Engine.CLoader
- {
- /// <summary>资源配置数据</summary>
- public class CLoaderConfig
- {
- #region 单利
- private static CLoaderConfig instance;
- /// <summary>单利对象</summary>
- public static CLoaderConfig GetInstance()
- {
- if (instance == null)
- {
- instance = new CLoaderConfig();
- }
- return instance;
- }
- #endregion
- /// <summary>全部资源的配置字典</summary>
- private Dictionary<string, CAssetsConfigInfo> dictAssetsConfigInfo = new Dictionary<string, CAssetsConfigInfo>();
- 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);
- }
- }
- /// <summary>得到某个资源的配置信息</summary>
- public CAssetsConfigInfo GetAssetsConfig(string assetsName)
- {
- if(dictAssetsConfigInfo.ContainsKey(assetsName))
- {
- return dictAssetsConfigInfo[assetsName];
- }
- else
- {
- #if UNITY_EDITOR
- CDebug.LogError("有资源的配置信息是null:" + assetsName);
- #endif
- return null;
- }
- }
- }
- }
|