-
Notifications
You must be signed in to change notification settings - Fork 450
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
52dfcf9
feat: NetworkAnimator Cleanup
andrews-unity ef03e4e
fix: adding missing files and AssemblyInfo
andrews-unity 5159102
standards fix
andrews-unity 00f3886
Merge branch 'develop' into feature/network-anim-exp-take-2
andrews-unity d8ff153
Merge branch 'develop' into feature/network-anim-exp-take-2
andrews-unity a43d121
Merge branch 'develop' into feature/network-anim-exp-take-2
andrews-unity 114e35e
fix: PR Feedback
andrews-unity c05e865
Merge branch 'develop' into feature/network-anim-exp-take-2
andrews-unity 1d87a50
Merge branch 'develop' into feature/network-anim-exp-take-2
mattwalsh-unity 7947802
Merge branch 'develop' into feature/network-anim-exp-take-2
andrews-unity File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
712 changes: 303 additions & 409 deletions
712
com.unity.netcode.gameobjects/Components/NetworkAnimator.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
com.unity.netcode.gameobjects/Editor/NetworkAnimatorEditor.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
com.unity.netcode.gameobjects/Editor/NetworkAnimatorEditor.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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