using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
using Engine.CLoader;
namespace Engine.Data
{
/// 静态数据管理对象基类
public class ByteManagerBase
{
/// 数据字典
protected Dictionary DictData = new Dictionary();
/// 数据列表
protected List ListData = new List();
/// 读取角色数据
public void ReadInfo(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);
}
}
/// 添加数据
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);
}
}
/// 查找一个静态数据对象
public T FindInfoByID(int id) where T : ByteDataBase
{
if(DictData.ContainsKey(id))
{
return DictData[id] as T;
}
else
{
return null;
}
}
/// 查找一个静态数据对象
public T FindInfoByIndex(int index) where T : ByteDataBase
{
return ListData[index] as T;
}
/// 获得全部数据
public List GetAllInfo()
{
return ListData;
}
/// 数据个数
public int InfoCount
{
get
{
return ListData.Count;
}
}
}
}