using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace Sog { public class ServerDataObjMgr : Singleton { private IServerDataObj[] m_serverDataObjTable; public ServerDataObjMgr() { m_serverDataObjTable = new IServerDataObj[(int)ServerDataObjType.MaxTypeID]; } //注册 public void RegisterDataObj(IServerDataObj dataObj) { int dataObjType = dataObj.GetDataType(); if (dataObjType > 0 && dataObjType < (int)ServerDataObjType.MaxTypeID) { if (m_serverDataObjTable[dataObjType] != null) { TraceLog.Assert("dataObj {0} already registed when register type {1} !", dataObjType, dataObj.GetType().FullName); } TraceLog.Debug("dataObj {0} register type {1} success", dataObjType, dataObj.GetType().FullName); m_serverDataObjTable[dataObjType] = dataObj; } else { TraceLog.Assert("dataObj {0} invalid id register type {1} !", dataObjType, dataObj.GetType().FullName); } } //根据类型返回一个DataObj public static T GetDataObj(int dataObjType) where T : IServerDataObj { if (dataObjType > 0 && dataObjType < (int)ServerDataObjType.MaxTypeID) { return (T)Instance.m_serverDataObjTable[dataObjType]; } return default(T); } } }