HKI Core
AITransitionDrawer.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using UnityEditor;
3 
4 namespace HKI.Core.AI.StateMachine.Editor
5 {
11  [CustomPropertyDrawer(typeof(AITransition))]
12  public class AITransitionDrawer : PropertyDrawer
13  {
14  // Private variables
15  const string decisionSPName = "Decision";
16  const string trueStateSPName = "TrueState";
17  const string falseStateSPName = "FalseState";
18 
19  const float decisionLabelWidth = 60.0f;
20  const float trueStateLabelWidth = 75.0f;
21  const float falseStateLabelWidth = 75.0f;
22 
23  // OnGUI function
24  public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
25  {
26  SerializedProperty decisionSP = property.FindPropertyRelative(decisionSPName);
27  SerializedProperty trueStateSP = property.FindPropertyRelative(trueStateSPName);
28  SerializedProperty falseStateSP = property.FindPropertyRelative(falseStateSPName);
29 
30  float fieldWidth = (position.width - decisionLabelWidth - trueStateLabelWidth - falseStateLabelWidth) / 3.0f;
31 
32  position.width = decisionLabelWidth;
33  EditorGUI.LabelField(position, "Decision:");
34 
35  position.x += decisionLabelWidth;
36  position.width = fieldWidth;
37  EditorGUI.PropertyField(position, decisionSP, GUIContent.none);
38 
39  position.x += fieldWidth;
40  position.width = trueStateLabelWidth;
41  EditorGUI.LabelField(position, "True State:");
42 
43  position.x += trueStateLabelWidth;
44  position.width = fieldWidth;
45  EditorGUI.PropertyField(position, trueStateSP, GUIContent.none);
46 
47  position.x += fieldWidth;
48  position.width = falseStateLabelWidth;
49  EditorGUI.LabelField(position, "False State:");
50 
51  position.x += falseStateLabelWidth;
52  position.width = fieldWidth;
53  EditorGUI.PropertyField(position, falseStateSP, GUIContent.none);
54  }
55  }
56 }
This is obsolete code it'll be removed later. For now it's still included for exemplary purposes for ...
override void OnGUI(Rect position, SerializedProperty property, GUIContent label)