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