//注册接收者 public static void RegisterMsg(this MsgReceiver self, int msgName, Condition condition, Action action, string TriggerName = "NoDefine") { if (msgName < 0) { Debug.Log("RegisterMsg: " + TriggerName + "'s "+ msgName + "is not define"); } if (null == condition) { Debug.Log("RegisterMsg: " + TriggerName + "'s condition" + "is null"); } if (null == action) { Debug.Log("RegisterMsg: " + TriggerName + "'s action" + "is null"); } if (!MsgHandlerDict.ContainsKey(msgName)) { MsgHandlerDict[msgName] = new List<MsgHandler>(); } var handlers = MsgHandlerDict[msgName]; handlers.Add(new MsgHandler(self, msgName, condition, action)); }
public TArmor(MsgReceiver _speller) { register = _speller; msgName = (int)MessageType.BP; condition = Condition; action = Action; }
public MsgHandler(MsgReceiver receiver, int msgName, Condition condition, Action action) { this.receiver = receiver; this.msgName = msgName; this.condition = condition; this.action = action; }
public THaste(MsgReceiver _speller) { register = _speller; msgName = (int)MessageType.Summon; condition = Condition; action = Action; }
public TAFMoveStrike(MsgReceiver _speller, GameUnit gameUnit) { curUnit = gameUnit; register = _speller; msgName = (int)MessageType.Aftermove; condition = Condition; action = Action; }
public TCuringWind(MsgReceiver _speller) { register = _speller; //响应时点是发动卡牌 msgName = (int)MessageType.CastCard; condition = Condition; action = Action; }
public TLianJi(MsgReceiver _speller) { register = _speller; //响应时点是被召唤时 msgName = (int)MessageType.Summon; condition = Condition; action = Action; }
public TArrowrain(MsgReceiver speller) { register = speller; //初始化响应时点,为卡片使用时 msgName = (int)MessageType.CastCard; //初始化条件函数和行为函数 condition = Condition; action = Action; }
public TRegeneration(MsgReceiver speller) { register = speller; //初始化响应时点 msgName = (int)MessageType.Dead; //初始化条件函数和行为函数 condition = Condition; action = Action; }
/// <summary> /// 发送消息 /// </summary> /// <param name="msgName"></param> /// <param name="targetReceiver">目标接收者,不填或null为广域广播</param> public static void SendMsg(int msgName, MsgReceiver targetReceiver = null) { if (msgName < 0) { Debug.Log("SendMsg: " + msgName + "is not define"); } if (!MsgHandlerDict.ContainsKey(msgName)) { Debug.Log("SendMsg: " + msgName + "had not been regeisted"); return; } var handlers = MsgHandlerDict[msgName]; var handlerCount = handlers.Count; for (int index = handlerCount - 1; index >= 0; index --) { var handler = handlers[index]; if ((MonoBehaviour)handler.receiver != null) { //单播 if (targetReceiver != null) { if (targetReceiver == handler.receiver) { handler.strike(); } } else { //广域广播 handler.strike(); } } else { //接收者已经不存在则从广播列表里删除 handlers.Remove(handler); Debug.Log("SendMsg: One " + msgName + "'s receiver had been destory"); } } }
/// <summary> /// 返回MsgReceiver /// </summary> /// <param name="self"></param> /// <returns></returns> public static MsgReceiver GetMsgReceiver(this MsgReceiver self) { return(self); }