/// <summary> /// Draws a selector letting the user pick any action associated with the AIBrain this action is on /// </summary> /// <param name="position"></param> /// <param name="prop"></param> protected virtual void DrawSelectionDropdown(Rect position, SerializedProperty prop) { AIAction thisAction = prop.objectReferenceValue as AIAction; AIAction[] actions = (prop.serializedObject.targetObject as AIBrain).GetAttachedActions(); int selected = 0; int i = 1; string[] options = new string[actions.Length + 1]; options[0] = "None"; foreach (AIAction action in actions) { string name = string.IsNullOrEmpty(action.Label) ? action.GetType().Name : action.Label; options[i] = i.ToString() + " - " + name; if (action == thisAction) { selected = i; } i++; } EditorGUI.BeginChangeCheck(); selected = EditorGUI.Popup(position, selected, options); if (EditorGUI.EndChangeCheck()) { prop.objectReferenceValue = (selected == 0) ? null : actions[selected - 1]; prop.serializedObject.ApplyModifiedProperties(); EditorUtility.SetDirty(prop.serializedObject.targetObject); } }
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { var h = Mathf.Max(LineHeight, EditorGUI.GetPropertyHeight(property)); float height = h; AIAction @typedObject = property.objectReferenceValue as AIAction; if (@typedObject != null && !string.IsNullOrEmpty(@typedObject.Label)) { height += h; } return(height); }
public override void OnGUI(Rect rect, SerializedProperty prop, GUIContent label) { var height = Mathf.Max(LineHeight, EditorGUI.GetPropertyHeight(prop)); Rect position = rect; position.height = height; EditorGUI.PropertyField(position, prop); //, new GUIContent("Script")); position.y += height; AIAction @typedObject = prop.objectReferenceValue as AIAction; if (@typedObject != null && !string.IsNullOrEmpty(@typedObject.Label)) { position.height = height; EditorGUI.LabelField(position, "Label", @typedObject.Label); position.y += height; } else { EditorGUIUtility.GetControlID(FocusType.Passive); } }