forked from MinaPecheux/UnityTutorials-RTS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputBindingDrawer.cs
More file actions
44 lines (36 loc) · 1.86 KB
/
Copy pathInputBindingDrawer.cs
File metadata and controls
44 lines (36 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* Adapted from:
* https://learn.unity.com/tutorial/property-drawers-and-custom-inspectors */
using UnityEditor;
using UnityEngine;
[CustomPropertyDrawer(typeof(InputBinding))]
public class InputBindingDrawer : PropertyDrawer
{
// Draw the property inside the given rect
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
// Using BeginProperty / EndProperty on the parent property means that
// prefab override logic works on the entire property.
EditorGUI.BeginProperty(position, label, property);
// Draw label
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
// Don't make child fields be indented
int indent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;
// Calculate rects
float rowHeight = EditorGUIUtility.singleLineHeight;
Rect displayNameRect = new Rect(position.x, position.y, position.width, rowHeight);
Rect keyRect = new Rect(position.x, position.y + rowHeight, 50, rowHeight);
Rect inputEventRect = new Rect(position.x + 55, position.y + rowHeight, position.width - 55, rowHeight);
// Draw fields - passs GUIContent.none to each so they are drawn without labels
EditorGUI.PropertyField(displayNameRect, property.FindPropertyRelative("displayName"), GUIContent.none);
EditorGUI.PropertyField(keyRect, property.FindPropertyRelative("key"), GUIContent.none);
EditorGUI.PropertyField(inputEventRect, property.FindPropertyRelative("inputEvent"), GUIContent.none);
// Set indent back to what it was
EditorGUI.indentLevel = indent;
EditorGUI.EndProperty();
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return EditorGUIUtility.singleLineHeight * 2f;
}
}