private void _dispatchEvent(SAEvent notifier, Object target = null, string type = "") { Dictionary <string, ArrayList> funs; if (events.ContainsKey(type)) { funs = events[type]; Dictionary <string, ArrayList> .Enumerator en = funs.GetEnumerator(); while (en.MoveNext()) { ArrayList list = en.Current.Value; string functionName = en.Current.Key; int length = list.Count; for (int i = 0; i < length; ++i) { if (target == null || list[i] == target) { Type t = list[i].GetType(); MethodInfo methodInfo = t.GetMethod(functionName, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public); if (methodInfo != null) { ParameterInfo[] paramsInfo = methodInfo.GetParameters(); //得到指定方法的参数列表 if (paramsInfo.Length == 1) { //参数数量 if (notifier.GetType().Equals(paramsInfo[0].ParameterType)) { try { methodInfo.Invoke(list[i], new Object[] { notifier }); } catch (Exception ex) { UnityEngine.Debug.LogError(ex.Message); } } } } } } } } }
/** * 消息广播 */ public void dispatchEvent(SAEvent notifier, Object target = null) { _dispatchEvent(notifier, target, notifier.Type); _dispatchEvent(notifier, target, notifier.LuaType); }