Example #1
0
 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);
 }
Example #2
0
 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);
 }
Example #3
0
        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);
        }
Example #4
0
        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);
        }
Example #5
0
 public PacketFactory(PacketIdDefine id)
 {
     m_PacketId = id;
 }