123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using System;
- using Engine.CLoader;
- namespace Engine.Data
- {
- /// <summary>静态数据管理对象基类</summary>
- public class ByteManagerBase
- {
- /// <summary>数据字典</summary>
- protected Dictionary<int, ByteDataBase> DictData = new Dictionary<int, ByteDataBase>();
- /// <summary>数据列表</summary>
- protected List<ByteDataBase> ListData = new List<ByteDataBase>();
- /// <summary>读取角色数据</summary>
- public void ReadInfo<T>(UnityEngine.Object dataObj) where T : new()
- {
- UnityEngine.TextAsset textAsset = (UnityEngine.TextAsset)dataObj;
- ByteDataArray byteArr = new ByteDataArray(textAsset.bytes);
- int infoCount = byteArr.ReadInt();
- for (int i = 0; i < infoCount; i++)
- {
- //创建Info对象
- ByteDataBase infoBase = (new T()) as ByteDataBase;
- //读取数据
- infoBase.ReadInfo(byteArr);
- //添加数据
- AddInfo(infoBase);
- }
- }
- /// <summary>添加数据</summary>
- protected virtual void AddInfo(ByteDataBase infoBase)
- {
- if (!DictData.ContainsKey(infoBase.b_id))
- {
- DictData.Add(infoBase.b_id, infoBase);
- ListData.Add(infoBase);
- }
- else
- {
- CDebug.LogError("数据重复:type=" + infoBase.GetType().ToString() + " id=" + infoBase.b_id);
- }
- }
- /// <summary>查找一个静态数据对象</summary>
- public T FindInfoByID<T>(int id) where T : ByteDataBase
- {
- if(DictData.ContainsKey(id))
- {
- return DictData[id] as T;
- }
- else
- {
- return null;
- }
- }
- /// <summary>查找一个静态数据对象</summary>
- public T FindInfoByIndex<T>(int index) where T : ByteDataBase
- {
- return ListData[index] as T;
- }
- /// <summary>获得全部数据</summary>
- public List<ByteDataBase> GetAllInfo()
- {
- return ListData;
- }
- /// <summary>数据个数</summary>
- public int InfoCount
- {
- get
- {
- return ListData.Count;
- }
- }
- }
- }
|