Skip to content

Commit 4bb6d3a

Browse files
feat: NetworkAnimator Cleanup (#1281)
* feat: NetworkAnimator Cleanup
1 parent 19d78c4 commit 4bb6d3a

File tree

7 files changed

+432
-425
lines changed

7 files changed

+432
-425
lines changed

com.unity.netcode.gameobjects/Components/NetworkAnimator.cs

Lines changed: 303 additions & 409 deletions
Large diffs are not rendered by default.

com.unity.netcode.gameobjects/Components/com.unity.netcode.components.asmdef

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
"name": "Unity.Netcode.Components",
33
"rootNamespace": "Unity.Netcode.Components",
44
"references": [
5-
"Unity.Netcode.Runtime"
6-
]
5+
"Unity.Netcode.Runtime",
6+
"Unity.Collections"
7+
],
8+
"includePlatforms": [],
9+
"excludePlatforms": [],
10+
"allowUnsafeCode": true,
11+
"overrideReferences": false,
12+
"precompiledReferences": [],
13+
"autoReferenced": true,
14+
"defineConstraints": [],
15+
"versionDefines": [],
16+
"noEngineReferences": false
717
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using System;
2+
using Unity.Netcode.Components;
3+
using UnityEditor;
4+
using UnityEditor.Animations;
5+
using UnityEngine;
6+
7+
namespace Unity.Netcode.Editor
8+
{
9+
public static class TextUtility
10+
{
11+
public static GUIContent TextContent(string name, string tooltip)
12+
{
13+
var newContent = new GUIContent(name);
14+
newContent.tooltip = tooltip;
15+
return newContent;
16+
}
17+
18+
public static GUIContent TextContent(string name)
19+
{
20+
return new GUIContent(name);
21+
}
22+
}
23+
24+
[CustomEditor(typeof(NetworkAnimator), true)]
25+
[CanEditMultipleObjects]
26+
public class NetworkAnimatorEditor : UnityEditor.Editor
27+
{
28+
private NetworkAnimator m_AnimSync;
29+
[NonSerialized] private bool m_Initialized;
30+
private SerializedProperty m_AnimatorProperty;
31+
private GUIContent m_AnimatorLabel;
32+
33+
private void Init()
34+
{
35+
if (m_Initialized)
36+
{
37+
return;
38+
}
39+
40+
m_Initialized = true;
41+
m_AnimSync = target as NetworkAnimator;
42+
43+
m_AnimatorProperty = serializedObject.FindProperty("m_Animator");
44+
m_AnimatorLabel = TextUtility.TextContent("Animator", "The Animator component to synchronize.");
45+
}
46+
47+
public override void OnInspectorGUI()
48+
{
49+
Init();
50+
serializedObject.Update();
51+
DrawControls();
52+
serializedObject.ApplyModifiedProperties();
53+
}
54+
55+
private void DrawControls()
56+
{
57+
EditorGUI.BeginChangeCheck();
58+
EditorGUILayout.PropertyField(m_AnimatorProperty, m_AnimatorLabel);
59+
if (EditorGUI.EndChangeCheck())
60+
{
61+
m_AnimSync.ResetParameterOptions();
62+
}
63+
64+
if (m_AnimSync.Animator == null)
65+
{
66+
return;
67+
}
68+
69+
var controller = m_AnimSync.Animator.runtimeAnimatorController as AnimatorController;
70+
if (controller != null)
71+
{
72+
var showWarning = false;
73+
EditorGUI.indentLevel += 1;
74+
int i = 0;
75+
76+
foreach (var p in controller.parameters)
77+
{
78+
if (i >= NetworkAnimator.K_MaxAnimationParams)
79+
{
80+
showWarning = true;
81+
break;
82+
}
83+
84+
bool oldSend = m_AnimSync.GetParameterAutoSend(i);
85+
bool send = EditorGUILayout.Toggle(p.name, oldSend);
86+
if (send != oldSend)
87+
{
88+
m_AnimSync.SetParameterAutoSend(i, send);
89+
EditorUtility.SetDirty(target);
90+
}
91+
i += 1;
92+
}
93+
94+
if (showWarning)
95+
{
96+
EditorGUILayout.HelpBox($"NetworkAnimator can only select between the first {NetworkAnimator.K_MaxAnimationParams} parameters in a mecanim controller", MessageType.Warning);
97+
}
98+
99+
EditorGUI.indentLevel -= 1;
100+
}
101+
}
102+
}
103+
}

com.unity.netcode.gameobjects/Editor/NetworkAnimatorEditor.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

com.unity.netcode.gameobjects/Runtime/AssemblyInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
[assembly: InternalsVisibleTo("TestProject.ToolsIntegration.RuntimeTests")]
1010
#endif
1111
[assembly: InternalsVisibleTo("Unity.Netcode.RuntimeTests")]
12+

com.unity.netcode.gameobjects/Runtime/Logging/NetworkLog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static class NetworkLog
1111
/// Gets the current log level.
1212
/// </summary>
1313
/// <value>The current log level.</value>
14-
internal static LogLevel CurrentLogLevel => NetworkManager.Singleton == null ? LogLevel.Normal : NetworkManager.Singleton.LogLevel;
14+
public static LogLevel CurrentLogLevel => NetworkManager.Singleton == null ? LogLevel.Normal : NetworkManager.Singleton.LogLevel;
1515

1616
// internal logging
1717
internal static void LogInfo(string message) => Debug.Log($"[Netcode] {message}");

testproject/Assets/Tests/Manual/NetworkAnimatorTests/AnimatedCubeController.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,6 @@ public override void OnNetworkSpawn()
2828

2929
private void Update()
3030
{
31-
if (m_NetworkAnimator.IsAuthorityOverAnimator)
32-
{
33-
if (Input.GetKeyDown(KeyCode.C))
34-
{
35-
ToggleRotateAnimation();
36-
}
37-
if (Input.GetKeyDown(KeyCode.Space))
38-
{
39-
PlayPulseAnimation();
40-
}
41-
}
42-
else
4331
{
4432
if (Input.GetKeyDown(KeyCode.C))
4533
{
@@ -60,7 +48,7 @@ private void ToggleRotateAnimation()
6048

6149
private void PlayPulseAnimation()
6250
{
63-
m_Animator.SetTrigger("Pulse");
51+
m_NetworkAnimator.SetTrigger("Pulse");
6452
}
6553

6654
[ServerRpc]

0 commit comments

Comments
 (0)