private void DrawAdvanced_CallMethodOnSelected(Rect area, SerializedProperty property) { //Draw Target var targRect = new Rect(area.xMin, area.yMin, area.width, EditorGUIUtility.singleLineHeight); var targProp = property.FindPropertyRelative(TriggerTargetProps.PROP_TRIGGERABLETARG); var targLabel = new GUIContent("Triggerable Target"); var targGo = GameObjectUtil.GetGameObjectFromSource(targProp.objectReferenceValue); var newTargGo = EditorGUI.ObjectField(targRect, targLabel, targGo, typeof(GameObject), true) as GameObject; if (newTargGo != targGo) { targGo = newTargGo; targProp.objectReferenceValue = (targGo != null) ? targGo.transform : null; } var targCompPopupRect = new Rect(area.xMin, targRect.yMax, area.width, EditorGUIUtility.singleLineHeight); if (targGo != null) { EditorGUI.BeginChangeCheck(); var selectedComp = SPEditorGUI.SelectComponentFromSourceField(targCompPopupRect, "Target Component", targGo, targProp.objectReferenceValue as Component); if (EditorGUI.EndChangeCheck()) { targProp.objectReferenceValue = selectedComp; } } else { EditorGUI.LabelField(targCompPopupRect, "Target Component", "(First Select a Target)"); } //Draw Method Name var methNameRect = new Rect(area.xMin, targCompPopupRect.yMax, area.width, EditorGUIUtility.singleLineHeight); System.Reflection.MemberInfo selectedMember = null; if (targProp.objectReferenceValue != null) { var methProp = property.FindPropertyRelative(TriggerTargetProps.PROP_METHODNAME); //var tp = targProp.objectReferenceValue.GetType(); //var members = GetAvailableMethods(tp).ToArray(); //var members = com.spacepuppy.Dynamic.DynamicUtil.GetEasilySerializedMembers(targProp.objectReferenceValue, System.Reflection.MemberTypes.Method).ToArray(); var members = com.spacepuppy.Dynamic.DynamicUtil.GetEasilySerializedMembers(targProp.objectReferenceValue, System.Reflection.MemberTypes.All, spacepuppy.Dynamic.DynamicMemberAccess.Write).ToArray(); System.Array.Sort(members, (a, b) => string.Compare(a.Name, b.Name, true)); var memberNames = members.Select((m) => m.Name).ToArray(); int index = System.Array.IndexOf(memberNames, methProp.stringValue); index = EditorGUI.Popup(methNameRect, new GUIContent("Method", "The method/prop on the target to call."), index, (from n in memberNames select new GUIContent(n)).ToArray()); methProp.stringValue = (index >= 0) ? memberNames[index] : null; selectedMember = (index >= 0) ? members[index] : null; } else { EditorGUI.Popup(methNameRect, new GUIContent("Method", "The method/prop on the target to call."), -1, new GUIContent[0]); } property.serializedObject.ApplyModifiedProperties(); //Draw Triggerable Arg var parr = (selectedMember != null) ? com.spacepuppy.Dynamic.DynamicUtil.GetDynamicParameterInfo(selectedMember) : null; if (parr == null || parr.Length == 0) { //NO PARAMETERS _callMethodModeExtraLines = 1; var argRect = new Rect(area.xMin, methNameRect.yMax, area.width, EditorGUIUtility.singleLineHeight); var argArrayProp = property.FindPropertyRelative(TriggerTargetProps.PROP_TRIGGERABLEARGS); if (argArrayProp.arraySize > 0) { argArrayProp.arraySize = 0; argArrayProp.serializedObject.ApplyModifiedProperties(); } var cache = SPGUI.Disable(); EditorGUI.LabelField(argRect, GUIContent.none, new GUIContent("*Zero Parameter Count*")); cache.Reset(); } else { //MULTIPLE PARAMETERS - special case, does not support trigger event arg _callMethodModeExtraLines = parr.Length; var argArrayProp = property.FindPropertyRelative(TriggerTargetProps.PROP_TRIGGERABLEARGS); if (argArrayProp.arraySize != parr.Length) { argArrayProp.arraySize = parr.Length; argArrayProp.serializedObject.ApplyModifiedProperties(); } EditorGUI.indentLevel++; for (int i = 0; i < parr.Length; i++) { var paramType = parr[i].ParameterType; var argRect = new Rect(area.xMin, methNameRect.yMax + i * EditorGUIUtility.singleLineHeight, area.width, EditorGUIUtility.singleLineHeight); var argProp = argArrayProp.GetArrayElementAtIndex(i); if (paramType == typeof(object)) { //draw the default variant as the method accepts anything _variantDrawer.RestrictVariantType = false; _variantDrawer.ForcedObjectType = null; _variantDrawer.OnGUI(argRect, argProp, EditorHelper.TempContent("Arg " + i.ToString() + ": " + parr[i].ParameterName, "A parameter to be passed to the method if needed.")); } else { var argType = VariantReference.GetVariantType(paramType); _variantDrawer.RestrictVariantType = true; _variantDrawer.VariantTypeRestrictedTo = argType; _variantDrawer.ForcedObjectType = (paramType.IsInterface || TypeUtil.IsType(paramType, typeof(Component))) ? paramType : null; _variantDrawer.OnGUI(argRect, argProp, EditorHelper.TempContent("Arg " + i.ToString() + ": " + parr[i].ParameterName, "A parameter to be passed to the method if needed.")); } } EditorGUI.indentLevel--; } }