static GenericMenu BuildPopupList(Object target, UnityEventBaseEx dummyEvent, SerializedProperty listener) { //special case for components... we want all the game objects targets there! var targetToUse = target; if (targetToUse is Component) { targetToUse = (target as Component).gameObject; } // find the current event target... var methodName = listener.FindPropertyRelative(kMethodNamePath); var menu = new GenericMenu(); menu.AddItem(new GUIContent(kNoFunctionString), string.IsNullOrEmpty(methodName.stringValue), ClearEventFunction, new UnityEventFunction(listener, null, null, UnityEngine.Events.PersistentListenerMode.EventDefined)); if (targetToUse == null) { return(menu); } menu.AddSeparator(""); // figure out the signature of this delegate... // The property at this stage points to the 'container' and has the field name Type delegateType = dummyEvent.GetType(); // check out the signature of invoke as this is the callback! MethodInfo delegateMethod = delegateType.GetMethod("Invoke"); var delegateArgumentsTypes = delegateMethod.GetParameters().Select(x => x.ParameterType).ToArray(); GeneratePopUpForType(menu, targetToUse, false, listener, delegateArgumentsTypes); if (targetToUse is GameObject) { Component[] comps = (targetToUse as GameObject).GetComponents <Component>(); var duplicateNames = comps.Where(c => c != null).Select(c => c.GetType().Name).GroupBy(x => x).Where(g => g.Count() > 1).Select(g => g.Key).ToList(); foreach (Component comp in comps) { if (comp == null) { continue; } GeneratePopUpForType(menu, comp, duplicateNames.Contains(comp.GetType().Name), listener, delegateArgumentsTypes); } } return(menu); }
static string GetEventParams(UnityEventBaseEx evt) { var methodInfo = evt.FindMethod("Invoke", evt.GetType(), UnityEngine.Events.PersistentListenerMode.EventDefined, null); var sb = new StringBuilder(); sb.Append(" ("); var types = methodInfo.GetParameters().Select(x => x.ParameterType).ToArray(); for (int i = 0; i < types.Length; i++) { sb.Append(types[i].Name); if (i < types.Length - 1) { sb.Append(", "); } } sb.Append(")"); return(sb.ToString()); }