Skip to content

feat: NetworkAnimator Cleanup #1281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Oct 14, 2021
Merged
712 changes: 303 additions & 409 deletions com.unity.netcode.gameobjects/Components/NetworkAnimator.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
"name": "Unity.Netcode.Components",
"rootNamespace": "Unity.Netcode.Components",
"references": [
"Unity.Netcode.Runtime"
]
"Unity.Netcode.Runtime",
"Unity.Collections"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": true,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
Comment on lines -5 to +16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this diff could be as small & simple as:

-         "Unity.Netcode.Runtime"
+         "Unity.Netcode.Runtime",
+         "Unity.Collections"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well and the allow unsafe code :P but this is Unity saving the asmdef :P

}
103 changes: 103 additions & 0 deletions com.unity.netcode.gameobjects/Editor/NetworkAnimatorEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using System;
using Unity.Netcode.Components;
using UnityEditor;
using UnityEditor.Animations;
using UnityEngine;

namespace Unity.Netcode.Editor
{
public static class TextUtility
{
public static GUIContent TextContent(string name, string tooltip)
{
var newContent = new GUIContent(name);
newContent.tooltip = tooltip;
return newContent;
}

public static GUIContent TextContent(string name)
{
return new GUIContent(name);
}
}

[CustomEditor(typeof(NetworkAnimator), true)]
[CanEditMultipleObjects]
public class NetworkAnimatorEditor : UnityEditor.Editor
{
private NetworkAnimator m_AnimSync;
[NonSerialized] private bool m_Initialized;
private SerializedProperty m_AnimatorProperty;
private GUIContent m_AnimatorLabel;

private void Init()
{
if (m_Initialized)
{
return;
}

m_Initialized = true;
m_AnimSync = target as NetworkAnimator;

m_AnimatorProperty = serializedObject.FindProperty("m_Animator");
m_AnimatorLabel = TextUtility.TextContent("Animator", "The Animator component to synchronize.");
}

public override void OnInspectorGUI()
{
Init();
serializedObject.Update();
DrawControls();
serializedObject.ApplyModifiedProperties();
}

private void DrawControls()
{
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(m_AnimatorProperty, m_AnimatorLabel);
if (EditorGUI.EndChangeCheck())
{
m_AnimSync.ResetParameterOptions();
}

if (m_AnimSync.Animator == null)
{
return;
}

var controller = m_AnimSync.Animator.runtimeAnimatorController as AnimatorController;
if (controller != null)
{
var showWarning = false;
EditorGUI.indentLevel += 1;
int i = 0;

foreach (var p in controller.parameters)
{
if (i >= NetworkAnimator.K_MaxAnimationParams)
{
showWarning = true;
break;
}

bool oldSend = m_AnimSync.GetParameterAutoSend(i);
bool send = EditorGUILayout.Toggle(p.name, oldSend);
if (send != oldSend)
{
m_AnimSync.SetParameterAutoSend(i, send);
EditorUtility.SetDirty(target);
}
i += 1;
}

if (showWarning)
{
EditorGUILayout.HelpBox($"NetworkAnimator can only select between the first {NetworkAnimator.K_MaxAnimationParams} parameters in a mecanim controller", MessageType.Warning);
}

EditorGUI.indentLevel -= 1;
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions com.unity.netcode.gameobjects/Runtime/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
[assembly: InternalsVisibleTo("TestProject.ToolsIntegration.RuntimeTests")]
#endif
[assembly: InternalsVisibleTo("Unity.Netcode.RuntimeTests")]

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class NetworkLog
/// Gets the current log level.
/// </summary>
/// <value>The current log level.</value>
internal static LogLevel CurrentLogLevel => NetworkManager.Singleton == null ? LogLevel.Normal : NetworkManager.Singleton.LogLevel;
public static LogLevel CurrentLogLevel => NetworkManager.Singleton == null ? LogLevel.Normal : NetworkManager.Singleton.LogLevel;

// internal logging
internal static void LogInfo(string message) => Debug.Log($"[Netcode] {message}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@ public override void OnNetworkSpawn()

private void Update()
{
if (m_NetworkAnimator.IsAuthorityOverAnimator)
{
if (Input.GetKeyDown(KeyCode.C))
{
ToggleRotateAnimation();
}
if (Input.GetKeyDown(KeyCode.Space))
{
PlayPulseAnimation();
}
}
else
{
if (Input.GetKeyDown(KeyCode.C))
{
Expand All @@ -60,7 +48,7 @@ private void ToggleRotateAnimation()

private void PlayPulseAnimation()
{
m_Animator.SetTrigger("Pulse");
m_NetworkAnimator.SetTrigger("Pulse");
}

[ServerRpc]
Expand Down