Exemple #1
0
 public void RegisterGameMessageType(List <Type> gameMessageTypes)
 {
     if (gameMessageTypes == null)
     {
         return;
     }
     foreach (Type type in gameMessageTypes)
     {
         GameMessageHeader messageHeader = AbstractGameMessage.ReadGameMessageMeta(type);
         int key = AbstractGameMessage.CreateGameMessageUniqueId((int)messageHeader.ServerType, messageHeader.MessageId);
         gameMessageTypeMap.Add(key, type);
     }
 }
        /// <summary>
        /// 根据消息的唯一id,查找这个消息对应的Type,并创建这个消息的对象
        /// </summary>
        /// <param name="messageUniqueId"></param>
        /// <returns></returns>
        private IGameMessage NewGameMessage(int messageId, int serverType)
        {
            int key = AbstractGameMessage.CreateGameMessageUniqueId(serverType, messageId);

            Type messageType = gameMessageTypeMap[key];

            if (messageType == null)
            {
                Debug.Log("找不到消息对象,messageId:" + messageId + ",serverType:" + serverType + "对应的消息Type,可能是没有注册这个消息Type");
                return(null);
            }
            IGameMessage gameMessage = (IGameMessage)Activator.CreateInstance(messageType);

            return(gameMessage);
        }