HKI Core
FloatingPointWidthHeightDrawer.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using UnityEditor;
3 
4 namespace HKI.Core.Variables.Editor
5 {
9  [CustomPropertyDrawer(typeof(FloatingPointWidthHeight))]
10  public class FloatWidthHeightDrawer : PropertyDrawer
11  {
12  // Private variables
13  const string widthSPName = "Width";
14  const string heightSPName = "Height";
15 
16  const float labelWidth = 120.0f;
17  const float widthLabelWidth = 40.0f;
18  const float heightLabelWidth = 45.0f;
19 
20  // OnGUI function
21  public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
22  {
23  SerializedProperty widthSP = property.FindPropertyRelative(widthSPName);
24  SerializedProperty heightSP = property.FindPropertyRelative(heightSPName);
25 
26  float inputFieldWidth = (position.width - labelWidth - widthLabelWidth - heightLabelWidth) / 2.0f;
27 
28  position.width = labelWidth;
29  EditorGUI.LabelField(position, label);
30 
31  position.x += labelWidth;
32  position.width = widthLabelWidth;
33  EditorGUI.LabelField(position, widthSPName);
34 
35  position.x += widthLabelWidth;
36  position.width = inputFieldWidth;
37  EditorGUI.PropertyField(position, widthSP, GUIContent.none);
38 
39  position.x += inputFieldWidth;
40  position.width = heightLabelWidth;
41  EditorGUI.LabelField(position, heightSPName);
42 
43  position.x += heightLabelWidth;
44  position.width = inputFieldWidth;
45  EditorGUI.PropertyField(position, heightSP, GUIContent.none);
46  }
47  }
48 }
Custom property drawer for the FloatingPointWidthHeight class.
override void OnGUI(Rect position, SerializedProperty property, GUIContent label)