Пример #1
0
        protected bool OnTrigger(IEntity sender, string message, EntityPool.TriggerFunction callback,
                                 Hashtable args)
        {
            int totalRules = SendReceiveRules.Count;
            MessageDispatchRule availableRule = null;

            for (int index = 0; index < totalRules; index++)
            {
                var rule = SendReceiveRules[index];
                if (rule.CheckCanDispatch(sender.EntityType(), message))
                {
                    availableRule = rule;
                    break;
                }
            }
            if (availableRule == null)
            {
                return(false);
            }
            int[] receiverTypes = availableRule.ReceiverTypes;
            if (receiverTypes == null)
            {
                return(false);
            }
            for (int rIndex = 0; rIndex < receiverTypes.Length; rIndex++)
            {
                int receiveType = receiverTypes[rIndex];
                // 参数可能会经由一个中间处理
                args = ProcessMessageArguments(availableRule.Message, args);
                callback(receiveType, message, args);
            }
            return(true);
        }
Пример #2
0
 protected void AddMessageDispatchRule(MessageDispatchRule rule)
 {
     _sendReceiveRules.Add(rule);
 }