public IPacketFactory GetPacketFactory(PacketIdDefine id) { if (m_Packets.ContainsKey(id)) { return(m_Packets[id]); } LogModule.LogInfo("Can't find packet factory for id enum : {0}", id); return(null); }
public IPacketHandler GetPacketHandler(PacketIdDefine id) { if (m_Handlers.ContainsKey(id)) { IPacketHandler handler = m_Handlers[id]; return(handler); } LogModule.LogInfo("Can't find packet handler for id enum : {0}", id); return(null); }
public PacketBase <T> CreatePacket <T>(PacketIdDefine id) where T : new() { PacketIdDefine key = id; if (m_Packets.ContainsKey(key)) { IPacketFactory factory = m_Packets[key]; return(factory.CreatePacket() as PacketBase <T>); } LogModule.LogInfo("Can't find packet factory for type : {0}", key); return(null); }
private void Regist <T1, T2>(PacketIdDefine id) where T1 : new() where T2 : IPacketHandler, new() { PacketIdDefine key = id; if (m_Packets.ContainsKey(key)) { LogModule.LogError("Already contains key : {0}", key); return; } var factory = new PacketFactory <T1>(id); m_Packets.Add(key, factory); var handler = new T2(); m_Handlers.Add(key, handler); }
public PacketFactory(PacketIdDefine id) { m_PacketId = id; }