Skip to content

Commit

Permalink
fix: updating testproject NetworkAnimator test (Unity-Technologies#2075)
Browse files Browse the repository at this point in the history
* fix

This resolves the issue with NetworkAnimator not de-registering itself from OnClientConnected.
This resolves some issues with the manual NetworkAnimator test.

* update

MTT-4080
(this branch includes fixes for the OnClientConnectedCallback issue)
Renamed NetworkAnimatorEnhancement scene to NetworkAnimatorServerOwnerTest.
Adding the manual NetworkAnimatorServerOwnerTest scene to the scenes in build list.

* style

fixing whitespace issue.

* update

Fixing how AnimatedCubeController determines the type of NetworkAnimator and whether it is server or owner authoritative.

* update

Simplifying the conditional check requirements down to IsSpawned and IsOwner for the AnimationUserInput component since the only input checked should always be by the owner.

* update

removing an artifact from cherry picking a previous branch's work that included the manual test fixes.

* style

removing unused property.
  • Loading branch information
NoelStephensUnity authored Jul 29, 2022
1 parent 6d37247 commit 0e84dcd
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ MonoBehaviour:
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 39a16938ffb5cd846a9f6df7a686a9c4, type: 3}
m_Name: NetworkAnimatorEnhancements
m_Name: NetworkAnimatorServerOwnerTest
m_EditorClassIdentifier:
SceneToReference: {fileID: 102900000, guid: f88da8bb8d07e11418eaad6524d5cc12, type: 3}
m_IncludedScenes: []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections;
using Unity.Netcode;
using Unity.Netcode.Components;
Expand All @@ -14,23 +15,17 @@ public class AnimatedCubeController : NetworkBehaviour
private NetworkAnimator m_NetworkAnimator;
private bool m_IsServerAuthoritative = true;

private void Awake()
private void DetermineNetworkAnimatorComponentType()
{
m_Animator = GetComponent<Animator>();
m_NetworkAnimator = GetComponent<NetworkAnimator>();
if (m_NetworkAnimator == null)
if (m_NetworkAnimator != null)
{
m_NetworkAnimator = GetComponent<OwnerNetworkAnimator>();
if (m_NetworkAnimator != null)
{
m_IsServerAuthoritative = false;
}
else
{
throw new System.Exception($"{nameof(AnimatedCubeController)} requires that it is paired with either a {nameof(NetworkAnimator)} or {nameof(OwnerNetworkAnimator)}. Neither of the two components were found!");
}
m_IsServerAuthoritative = m_NetworkAnimator.GetType() != typeof(OwnerNetworkAnimator);
}
else
{
throw new Exception($"{nameof(AnimatedCubeController)} requires that it is paired with either a {nameof(NetworkAnimator)} or {nameof(OwnerNetworkAnimator)}. Neither of the two components were found!");
}
m_Rotate = m_Animator.GetBool("Rotate");
}

public override void OnNetworkSpawn()
Expand All @@ -39,6 +34,9 @@ public override void OnNetworkSpawn()
{
enabled = false;
}
m_Animator = GetComponent<Animator>();
DetermineNetworkAnimatorComponentType();
m_Rotate = m_Animator.GetBool("Rotate");
}

private bool HasAuthority()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private void Start()
// Update is called once per frame
private void LateUpdate()
{
if (!IsSpawned || !IsOwner && !IsServer)
if (!IsSpawned || !IsOwner)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ GameObject:
- component: {fileID: 3078684837582866037}
- component: {fileID: 3078684837575715027}
- component: {fileID: 5295167409644547614}
- component: {fileID: 1923420540885290134}
- component: {fileID: 3632991713004262889}
m_Layer: 0
m_Name: NetworkAnimatedCube-Owner
m_TagString: Untagged
Expand Down Expand Up @@ -344,7 +344,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
TestIterations: 20
--- !u!114 &1923420540885290134
--- !u!114 &3632991713004262889
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
Expand All @@ -353,11 +353,10 @@ MonoBehaviour:
m_GameObject: {fileID: 3078684837583100501}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e8d0727d5ae3244e3b569694d3912374, type: 3}
m_Script: {fileID: 11500000, guid: f6a3556fb5f3bee4e8a0fb88acff87ff, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Animator: {fileID: 3078684837575715027}
m_IsServerAuthoritative: 0
--- !u!1 &3214090169133903718
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -649,7 +648,6 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Animator: {fileID: 6047057957339659638}
m_IsServerAuthoritative: 1
--- !u!1 &4033769488171516769
GameObject:
m_ObjectHideFlags: 0
Expand Down
3 changes: 2 additions & 1 deletion testproject/ProjectSettings/EditorBuildSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ EditorBuildSettings:
- enabled: 1
path: Assets/Tests/Manual/InSceneObjectParentingTests/InSceneNetworkObjectToLoad.unity
guid: f06a8525a4b5200459f62905c29ce09e
path: Assets/Tests/Manual/NetworkAnimatorTests/NetworkAnimatorEnhancement.unity
- enabled: 1
path: Assets/Tests/Manual/NetworkAnimatorTests/NetworkAnimatorServerOwnerTest.unity
guid: f88da8bb8d07e11418eaad6524d5cc12
m_configObjects:
com.unity.addressableassets: {fileID: 11400000, guid: 5a3d5c53c25349c48912726ae850f3b0,
Expand Down

0 comments on commit 0e84dcd

Please sign in to comment.