HKI Core
DayMonthYearDrawer.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using UnityEditor;
3 
4 namespace HKI.Core.Variables.Editor
5 {
6  [CustomPropertyDrawer(typeof(DayMonthYear))]
7  public class DayMonthYearDrawer : PropertyDrawer
8  {
9  // Private variables
10  const string daySPName = "Day";
11  const string monthSPName = "Month";
12  const string yearSPName = "Year";
13  const string bcadSPName = "BCAD";
14 
15  const float labelWidth = 120.0f;
16  const float dayLabelWidth = 40.0f;
17  const float monthLabelWidth = 45.0f;
18  const float yearLabelWidth = 40.0f;
19  const float bcadLabelWidth = 45.0f;
20 
21  // OnGUI function
22  public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
23  {
24  SerializedProperty daySP = property.FindPropertyRelative(daySPName);
25  SerializedProperty monthSP = property.FindPropertyRelative(monthSPName);
26  SerializedProperty yearSP = property.FindPropertyRelative(yearSPName);
27  SerializedProperty bcadSP = property.FindPropertyRelative(bcadSPName);
28 
29  float inputFieldWidth = (position.width - labelWidth - dayLabelWidth - monthLabelWidth - yearLabelWidth - bcadLabelWidth) / 4.0f;
30 
31  position.width = labelWidth;
32  EditorGUI.LabelField(position, label);
33 
34  position.x += labelWidth;
35  position.width = dayLabelWidth;
36  EditorGUI.LabelField(position, daySPName);
37 
38  position.x += dayLabelWidth;
39  position.width = inputFieldWidth;
40  EditorGUI.PropertyField(position, daySP, GUIContent.none);
41 
42  position.x += inputFieldWidth;
43  position.width = monthLabelWidth;
44  EditorGUI.LabelField(position, monthSPName);
45 
46  position.x += monthLabelWidth;
47  position.width = inputFieldWidth;
48  EditorGUI.PropertyField(position, monthSP, GUIContent.none);
49 
50  position.x += inputFieldWidth;
51  position.width = yearLabelWidth;
52  EditorGUI.LabelField(position, yearSPName);
53 
54  position.x += yearLabelWidth;
55  position.width = inputFieldWidth;
56  EditorGUI.PropertyField(position, yearSP, GUIContent.none);
57 
58  position.x += inputFieldWidth;
59  position.width = bcadLabelWidth;
60  EditorGUI.LabelField(position, bcadSPName);
61 
62  position.x += bcadLabelWidth;
63  position.width = inputFieldWidth;
64  EditorGUI.PropertyField(position, bcadSP, GUIContent.none);
65  }
66  }
67 }
override void OnGUI(Rect position, SerializedProperty property, GUIContent label)