-
Notifications
You must be signed in to change notification settings - Fork 461
Expand file tree
/
Copy pathNetworkedAnimatorEditor.cs
More file actions
78 lines (65 loc) · 2.55 KB
/
NetworkedAnimatorEditor.cs
File metadata and controls
78 lines (65 loc) · 2.55 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
using System;
using MLAPI.Prototyping;
using UnityEditor.Animations;
using UnityEngine;
namespace UnityEditor
{
[CustomEditor(typeof(NetworkedAnimator), true)]
[CanEditMultipleObjects]
public class NetworkAnimatorEditor : Editor
{
private NetworkedAnimator m_Target;
[NonSerialized]
private bool m_Initialized;
private SerializedProperty m_AnimatorProperty;
private GUIContent m_AnimatorLabel;
private void Initialize()
{
if (m_Initialized) return;
m_Initialized = true;
m_Target = target as NetworkedAnimator;
m_AnimatorProperty = serializedObject.FindProperty("m_Animator");
m_AnimatorLabel = new GUIContent("Animator", "The Animator component to synchronize.");
}
private void DrawControls()
{
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(m_AnimatorProperty, m_AnimatorLabel);
if (EditorGUI.EndChangeCheck()) m_Target.ResetTrackedParams();
var animator = m_Target.animator;
if (ReferenceEquals(animator, null)) return;
var animatorController = animator.runtimeAnimatorController as AnimatorController;
if (ReferenceEquals(animatorController, null)) return;
EditorGUI.indentLevel += 1;
var showWarning = false;
{
int paramIndex = 0;
foreach (var animParam in animatorController.parameters)
{
if (paramIndex >= 32)
{
showWarning = true;
break;
}
bool wasTracking = m_Target.GetParamTracking(paramIndex);
bool isTracking = EditorGUILayout.Toggle(animParam.name, wasTracking);
if (isTracking != wasTracking)
{
m_Target.SetParamTracking(paramIndex, isTracking);
EditorUtility.SetDirty(target);
}
paramIndex++;
}
}
if (showWarning) EditorGUILayout.HelpBox("NetworkAnimator can only select between the first 32 parameters in a mecanim controller", MessageType.Warning);
EditorGUI.indentLevel -= 1;
}
public override void OnInspectorGUI()
{
Initialize();
serializedObject.Update();
DrawControls();
serializedObject.ApplyModifiedProperties();
}
}
}