public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginChangeCheck(); EditorGUI.PropertyField(position, property); if (EditorGUI.EndChangeCheck()) { OnChangedCallAttribute at = attribute as OnChangedCallAttribute; //Exit if it is not in the right play mode if (at.Criteria != OnChangedCallAttribute.RunTimeCriteriaEnum.Both && ((!EditorApplication.isPlaying && at.Criteria == OnChangedCallAttribute.RunTimeCriteriaEnum.PlayModeOnly) || (EditorApplication.isPlaying && at.Criteria == OnChangedCallAttribute.RunTimeCriteriaEnum.EditorOnly))) { return; } Type parentType = property.serializedObject.targetObject.GetType(); var findMethod = parentType.GetMethods().Where(m => m.Name == at.methodName).ToList(); if (findMethod.Count() == 0) // Found? { Debug.LogError(string.Format("Error: [OnChangedCall(\"{0}\")] Method Name in ({1}) not found. Did you perhaps typo?", at.methodName, parentType.ToString())); return; } var method = findMethod.First(); if (method.GetParameters().Length != at.arguments.Length) // All arguments supplied? { Debug.LogError(string.Format("Error: [OnChangedCall] {0} in ({1}) Requires {2} arguments {3} supplied.", at.methodName, parentType.ToString(), method.GetParameters().Length, at.arguments.Length)); return; } method.Invoke(property.serializedObject.targetObject, at.arguments); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginChangeCheck(); EditorGUI.PropertyField(position, property); if (EditorGUI.EndChangeCheck()) { OnChangedCallAttribute at = attribute as OnChangedCallAttribute; MethodInfo method = property.serializedObject.targetObject.GetType().GetMethod(at.mMethodName); if (method != null) { method.Invoke(property.serializedObject.targetObject, null); } } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginChangeCheck(); EditorGUI.PropertyField(position, property); if (EditorGUI.EndChangeCheck()) { OnChangedCallAttribute at = attribute as OnChangedCallAttribute; MethodInfo method = property.serializedObject.targetObject.GetType().GetMethods().Where(m => m.Name == at.methodName).First(); if (method != null && method.GetParameters().Count() == 0)// Only instantiate methods with 0 parameters { method.Invoke(property.serializedObject.targetObject, null); } } }