private static void HandleMethods <T>(T mono, MethodInfo[] methodInfos) { methodInfos.Foreach <MethodInfo>((method) => { object[] attrs = method.GetCustomAttributes(typeof(GenEventable), true); if (attrs.Length == 0) { return; } GenEventable genEventAttr = attrs[0] as GenEventable; ParameterInfo[] paras = method.GetParameters(); switch (paras.Length) { case 0: { EventDispatcher.AddEventListener(genEventAttr.eventName, () => { method.Invoke(mono, new object[0]); }, mono); } break; case 1: { EventDispatcher.AddEventListener <object>(genEventAttr.eventName, (arg1) => { method.Invoke(mono, new object[] { arg1 }); }, mono); } break; case 2: { EventDispatcher.AddEventListener <object, object>(genEventAttr.eventName, (arg1, arg2) => { method.Invoke(mono, new object[] { arg1, arg2 }); }, mono); } break; case 3: { EventDispatcher.AddEventListener <object, object, object>(genEventAttr.eventName, (arg1, arg2, arg3) => { method.Invoke(mono, new object[] { arg1, arg2, arg3 }); }, mono); } break; case 4: { EventDispatcher.AddEventListener <object, object, object, object>(genEventAttr.eventName, (arg1, arg2, arg3, arg4) => { method.Invoke(mono, new object[] { arg1, arg2, arg3, arg4 }); }, mono); } break; default: { Debug.logger.LogError("Event Gen Error", "The method " + method.Name + " has too much para"); } break; } }); }
private static void HandleField <T>(T mono, FieldInfo fieldInfo) { object[] attrs = fieldInfo.GetCustomAttributes(typeof(GenEventable), true); if (attrs.Length == 0) { return; } GenEventable genEventAttr = attrs[0] as GenEventable; var eventNames = genEventAttr.eventName; if (eventNames == null || eventNames.Length == 0) { eventNames = new string[] { fieldInfo.Name }; } for (int i = 0; i < eventNames.Length; i++) { EventDispatcher.AddEventListener <object>(eventNames[i], (arg1) => { fieldInfo.SetValue(mono, arg1); }, mono); } }
private static void HandleMethod <T>(T mono, MethodInfo method) { object[] attrs = method.GetCustomAttributes(typeof(GenEventable), true); if (attrs.Length == 0) { return; } GenEventable genEventAttr = attrs[0] as GenEventable; ParameterInfo[] paras = method.GetParameters(); var eventNames = genEventAttr.eventName; if (eventNames == null || eventNames.Length == 0) { eventNames = new string[] { method.Name }; } for (int i = 0; i < eventNames.Length; i++) { switch (paras.Length) { case 0: { EventDispatcher.AddEventListener(eventNames[i], () => { method.Invoke(mono, new object[0]); }, mono); } break; case 1: { EventDispatcher.AddEventListener <object>(eventNames[i], (arg1) => { method.Invoke(mono, new object[] { arg1 }); }, mono); } break; case 2: { EventDispatcher.AddEventListener <object, object>(eventNames[i], (arg1, arg2) => { method.Invoke(mono, new object[] { arg1, arg2 }); }, mono); } break; case 3: { EventDispatcher.AddEventListener <object, object, object>(eventNames[i], (arg1, arg2, arg3) => { method.Invoke(mono, new object[] { arg1, arg2, arg3 }); }, mono); } break; case 4: { EventDispatcher.AddEventListener <object, object, object, object>(eventNames[i], (arg1, arg2, arg3, arg4) => { method.Invoke(mono, new object[] { arg1, arg2, arg3, arg4 }); }, mono); } break; default: { Debug.unityLogger.LogError("Event Gen Error", "The method " + method.Name + " has too much para"); } break; } } }