You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

51 lines
1.6 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Sog
{
public class ServerDataObjMgr : Singleton<ServerDataObjMgr>
{
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<T>(int dataObjType) where T : IServerDataObj
{
if (dataObjType > 0 && dataObjType < (int)ServerDataObjType.MaxTypeID)
{
return (T)Instance.m_serverDataObjTable[dataObjType];
}
return default(T);
}
}
}