public void Add <Action>(ActionHandler <Action> handler, int priority) { Type actionType = typeof(Action); ActionHandlerInfoCollection <Action> handlers = ActionHandlers[actionType] as ActionHandlerInfoCollection <Action>; if (handlers == null) { handlers = new ActionHandlerInfoCollection <Action>(); ActionHandlers.Add(actionType, handlers); } handlers.Add(new ActionHandlerInfo <Action>(handler, priority)); }
public static ActionHandlerResult Invoke <Action>(Action args) { ActionHandlerResult result = null; Type actionType = typeof(Action); foreach (PluginBase plugin in s_Plugins) { if (plugin.Enable == false) { continue; } ActionHandlerInfoCollection <Action> actionHandlerInfos = plugin.ActionHandlers[actionType] as ActionHandlerInfoCollection <Action>; if (actionHandlerInfos != null) { //处理器已经按优先级排序,优先级值低的先被调用 foreach (ActionHandlerInfo <Action> handlerInfo in actionHandlerInfos) { result = handlerInfo.Handler(args); //不冒泡就停止后续处理器的执行 if (result != null && result.Bubble == false) { return(result); } } } } if (result == null) { result = new ActionHandlerResult(); } return(result); }