-
Notifications
You must be signed in to change notification settings - Fork 459
Expand file tree
/
Copy pathNetworkAnimatorParameterEntryDrawer.cs
More file actions
96 lines (88 loc) · 4.48 KB
/
NetworkAnimatorParameterEntryDrawer.cs
File metadata and controls
96 lines (88 loc) · 4.48 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#if COM_UNITY_MODULES_ANIMATION
using Unity.Netcode.Components;
using UnityEditor;
using UnityEngine;
namespace Unity.Netcode.Editor
{
[CustomPropertyDrawer(typeof(NetworkAnimator.AnimatorParametersListContainer))]
internal class NetworkAnimatorParameterEntryDrawer : PropertyDrawer
{
// Draw the property inside the given rect
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
// Draw the foldout for the list
SerializedProperty items = property.FindPropertyRelative(nameof(NetworkAnimator.AnimatorParameterEntries.ParameterEntries));
position.height = EditorGUIUtility.singleLineHeight;
property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, label);
if (property.isExpanded)
{
// Set the indention level down
EditorGUI.indentLevel++;
for (int i = 0; i < items.arraySize; i++)
{
position.y += EditorGUIUtility.singleLineHeight + 2;
SerializedProperty element = items.GetArrayElementAtIndex(i);
var nameField = element.FindPropertyRelative(nameof(NetworkAnimator.AnimatorParameterEntry.name));
// Draw the foldout for the item
element.isExpanded = EditorGUI.Foldout(position, element.isExpanded, nameField.stringValue);
if (!element.isExpanded)
{
continue;
}
// Draw the contents of the item
position.y += EditorGUIUtility.singleLineHeight + 2;
// Set the indention level down
EditorGUI.indentLevel++;
// Calculate rects
var nameHashRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);
position.y += EditorGUIUtility.singleLineHeight + 2;
var paramRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);
position.y += EditorGUIUtility.singleLineHeight + 2;
var syncRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);
// Get the three properties we want to visualize in the inspector view
var synchronizeField = element.FindPropertyRelative(nameof(NetworkAnimator.AnimatorParameterEntry.Synchronize));
var nameHashField = element.FindPropertyRelative(nameof(NetworkAnimator.AnimatorParameterEntry.NameHash));
var parameterTypeField = element.FindPropertyRelative(nameof(NetworkAnimator.AnimatorParameterEntry.ParameterType));
// Draw the read only fields
GUI.enabled = false;
EditorGUI.PropertyField(nameHashRect, nameHashField);
EditorGUI.PropertyField(paramRect, parameterTypeField);
GUI.enabled = true;
// Draw the read/write fields
EditorGUI.PropertyField(syncRect, synchronizeField);
// Set the indention level up
EditorGUI.indentLevel--;
}
// Set the indention level up
EditorGUI.indentLevel--;
}
EditorGUI.EndProperty();
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
var totalHeight = EditorGUIUtility.singleLineHeight;
if (!property.isExpanded)
{
return totalHeight;
}
var singleLineWithSpace = EditorGUIUtility.singleLineHeight + 2;
SerializedProperty items = property.FindPropertyRelative(nameof(NetworkAnimator.AnimatorParameterEntries.ParameterEntries));
totalHeight += singleLineWithSpace;
for (int i = 0; i < items.arraySize; i++)
{
SerializedProperty element = items.GetArrayElementAtIndex(i);
if (element.isExpanded)
{
totalHeight += (singleLineWithSpace * 4);
}
else
{
totalHeight += EditorGUIUtility.singleLineHeight;
}
}
return totalHeight;
}
}
}
#endif