com.unity.netcode.gameobjects@1.8.0
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com). ## [1.8.0] - 2023-12-12 ### Added - Added a new RPC attribute, which is simply `Rpc`. (#2762) - This is a generic attribute that can perform the functions of both Server and Client RPCs, as well as enabling client-to-client RPCs. Includes several default targets: `Server`, `NotServer`, `Owner`, `NotOwner`, `Me`, `NotMe`, `ClientsAndHost`, and `Everyone`. Runtime overrides are available for any of these targets, as well as for sending to a specific ID or groups of IDs. - This attribute also includes the ability to defer RPCs that are sent to the local process to the start of the next frame instead of executing them immediately, treating them as if they had gone across the network. The default behavior is to execute immediately. - This attribute effectively replaces `ServerRpc` and `ClientRpc`. `ServerRpc` and `ClientRpc` remain in their existing forms for backward compatibility, but `Rpc` will be the recommended and most supported option. - Added `NetworkManager.OnConnectionEvent` as a unified connection event callback to notify clients and servers of all client connections and disconnections within the session (#2762) - Added `NetworkManager.ServerIsHost` and `NetworkBehaviour.ServerIsHost` to allow a client to tell if it is connected to a host or to a dedicated server (#2762) - Added `SceneEventProgress.SceneManagementNotEnabled` return status to be returned when a `NetworkSceneManager` method is invoked and scene management is not enabled. (#2735) - Added `SceneEventProgress.ServerOnlyAction` return status to be returned when a `NetworkSceneManager` method is invoked by a client. (#2735) - Added `NetworkObject.InstantiateAndSpawn` and `NetworkSpawnManager.InstantiateAndSpawn` methods to simplify prefab spawning by assuring that the prefab is valid and applies any override prior to instantiating the `GameObject` and spawning the `NetworkObject` instance. (#2710) ### Fixed - Fixed issue where a client disconnected by a server-host would not receive a local notification. (#2789) - Fixed issue where a server-host could shutdown during a relay connection but periodically the transport disconnect message sent to any connected clients could be dropped. (#2789) - Fixed issue where a host could disconnect its local client but remain running as a server. (#2789) - Fixed issue where `OnClientDisconnectedCallback` was not being invoked under certain conditions. (#2789) - Fixed issue where `OnClientDisconnectedCallback` was always returning 0 as the client identifier. (#2789) - Fixed issue where if a host or server shutdown while a client owned NetworkObjects (other than the player) it would throw an exception. (#2789) - Fixed issue where setting values on a `NetworkVariable` or `NetworkList` within `OnNetworkDespawn` during a shutdown sequence would throw an exception. (#2789) - Fixed issue where a teleport state could potentially be overridden by a previous unreliable delta state. (#2777) - Fixed issue where `NetworkTransform` was using the `NetworkManager.ServerTime.Tick` as opposed to `NetworkManager.NetworkTickSystem.ServerTime.Tick` during the authoritative side's tick update where it performed a delta state check. (#2777) - Fixed issue where a parented in-scene placed NetworkObject would be destroyed upon a client or server exiting a network session but not unloading the original scene in which the NetworkObject was placed. (#2737) - Fixed issue where during client synchronization and scene loading, when client synchronization or the scene loading mode are set to `LoadSceneMode.Single`, a `CreateObjectMessage` could be received, processed, and the resultant spawned `NetworkObject` could be instantiated in the client's currently active scene that could, towards the end of the client synchronization or loading process, be unloaded and cause the newly created `NetworkObject` to be destroyed (and throw and exception). (#2735) - Fixed issue where a `NetworkTransform` instance with interpolation enabled would result in wide visual motion gaps (stuttering) under above normal latency conditions and a 1-5% or higher packet are drop rate. (#2713) - Fixed issue where you could not have multiple source network prefab overrides targeting the same network prefab as their override. (#2710) ### Changed - Changed the server or host shutdown so it will now perform a "soft shutdown" when `NetworkManager.Shutdown` is invoked. This will send a disconnect notification to all connected clients and the server-host will wait for all connected clients to disconnect or timeout after a 5 second period before completing the shutdown process. (#2789) - Changed `OnClientDisconnectedCallback` will now return the assigned client identifier on the local client side if the client was approved and assigned one prior to being disconnected. (#2789) - Changed `NetworkTransform.SetState` (and related methods) now are cumulative during a fractional tick period and sent on the next pending tick. (#2777) - `NetworkManager.ConnectedClientsIds` is now accessible on the client side and will contain the list of all clients in the session, including the host client if the server is operating in host mode (#2762) - Changed `NetworkSceneManager` to return a `SceneEventProgress` status and not throw exceptions for methods invoked when scene management is disabled and when a client attempts to access a `NetworkSceneManager` method by a client. (#2735) - Changed `NetworkTransform` authoritative instance tick registration so a single `NetworkTransform` specific tick event update will update all authoritative instances to improve perofmance. (#2713) - Changed `NetworkPrefabs.OverrideToNetworkPrefab` dictionary is no longer used/populated due to it ending up being related to a regression bug and not allowing more than one override to be assigned to a network prefab asset. (#2710) - Changed in-scene placed `NetworkObject`s now store their source network prefab asset's `GlobalObjectIdHash` internally that is used, when scene management is disabled, by clients to spawn the correct prefab even if the `NetworkPrefab` entry has an override. This does not impact dynamically spawning the same prefab which will yield the override on both host and client. (#2710) - Changed in-scene placed `NetworkObject`s no longer require a `NetworkPrefab` entry with `GlobalObjectIdHash` override in order for clients to properly synchronize. (#2710) - Changed in-scene placed `NetworkObject`s now set their `IsSceneObject` value when generating their `GlobalObjectIdHash` value. (#2710) - Changed the default `NetworkConfig.SpawnTimeout` value from 1.0s to 10.0s. (#2710)
This commit is contained in:
1004
Tests/Runtime/NetworkTransform/NetworkTransformBase.cs
Normal file
1004
Tests/Runtime/NetworkTransform/NetworkTransformBase.cs
Normal file
File diff suppressed because it is too large
Load Diff
11
Tests/Runtime/NetworkTransform/NetworkTransformBase.cs.meta
Normal file
11
Tests/Runtime/NetworkTransform/NetworkTransformBase.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ccdf46d0c73f8ac47921ec1be2772fac
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
314
Tests/Runtime/NetworkTransform/NetworkTransformGeneral.cs
Normal file
314
Tests/Runtime/NetworkTransform/NetworkTransformGeneral.cs
Normal file
@@ -0,0 +1,314 @@
|
||||
using NUnit.Framework;
|
||||
using Unity.Netcode.Components;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.Netcode.RuntimeTests
|
||||
{
|
||||
[TestFixture(HostOrServer.Host, Authority.OwnerAuthority)]
|
||||
[TestFixture(HostOrServer.Host, Authority.ServerAuthority)]
|
||||
public class NetworkTransformGeneral : NetworkTransformBase
|
||||
{
|
||||
public NetworkTransformGeneral(HostOrServer testWithHost, Authority authority) :
|
||||
base(testWithHost, authority, RotationCompression.None, Rotation.Euler, Precision.Full)
|
||||
{ }
|
||||
|
||||
protected override bool m_EnableTimeTravel => true;
|
||||
protected override bool m_SetupIsACoroutine => false;
|
||||
protected override bool m_TearDownIsACoroutine => false;
|
||||
|
||||
/// <summary>
|
||||
/// Test to verify nonAuthority cannot change the transform directly
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void VerifyNonAuthorityCantChangeTransform([Values] Interpolation interpolation)
|
||||
{
|
||||
m_AuthoritativeTransform.Interpolate = interpolation == Interpolation.EnableInterpolate;
|
||||
m_NonAuthoritativeTransform.Interpolate = interpolation == Interpolation.EnableInterpolate;
|
||||
|
||||
Assert.AreEqual(Vector3.zero, m_NonAuthoritativeTransform.transform.position, "other side pos should be zero at first"); // sanity check
|
||||
|
||||
m_NonAuthoritativeTransform.transform.position = new Vector3(4, 5, 6);
|
||||
|
||||
TimeTravelAdvanceTick();
|
||||
TimeTravelAdvanceTick();
|
||||
|
||||
Assert.AreEqual(Vector3.zero, m_NonAuthoritativeTransform.transform.position, "[Position] NonAuthority was able to change the position!");
|
||||
|
||||
var nonAuthorityRotation = m_NonAuthoritativeTransform.transform.rotation;
|
||||
var originalNonAuthorityEulerRotation = nonAuthorityRotation.eulerAngles;
|
||||
var nonAuthorityEulerRotation = originalNonAuthorityEulerRotation;
|
||||
// Verify rotation is not marked dirty when rotated by half of the threshold
|
||||
nonAuthorityEulerRotation.y += 20.0f;
|
||||
nonAuthorityRotation.eulerAngles = nonAuthorityEulerRotation;
|
||||
m_NonAuthoritativeTransform.transform.rotation = nonAuthorityRotation;
|
||||
TimeTravelAdvanceTick();
|
||||
var nonAuthorityCurrentEuler = m_NonAuthoritativeTransform.transform.rotation.eulerAngles;
|
||||
Assert.True(originalNonAuthorityEulerRotation.Equals(nonAuthorityCurrentEuler), "[Rotation] NonAuthority was able to change the rotation!");
|
||||
|
||||
var nonAuthorityScale = m_NonAuthoritativeTransform.transform.localScale;
|
||||
m_NonAuthoritativeTransform.transform.localScale = nonAuthorityScale * 100;
|
||||
|
||||
TimeTravelAdvanceTick();
|
||||
|
||||
Assert.True(nonAuthorityScale.Equals(m_NonAuthoritativeTransform.transform.localScale), "[Scale] NonAuthority was able to change the scale!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates that rotation checks don't produce false positive
|
||||
/// results when rolling over between 0 and 360 degrees
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestRotationThresholdDeltaCheck([Values] Interpolation interpolation)
|
||||
{
|
||||
m_AuthoritativeTransform.Interpolate = interpolation == Interpolation.EnableInterpolate;
|
||||
m_NonAuthoritativeTransform.Interpolate = interpolation == Interpolation.EnableInterpolate;
|
||||
m_NonAuthoritativeTransform.RotAngleThreshold = m_AuthoritativeTransform.RotAngleThreshold = 5.0f;
|
||||
var halfThreshold = m_AuthoritativeTransform.RotAngleThreshold * 0.5001f;
|
||||
|
||||
// Apply the current state prior to getting reference rotations which assures we have
|
||||
// applied the most current rotation deltas and that all bitset flags are updated
|
||||
var results = m_AuthoritativeTransform.ApplyState();
|
||||
TimeTravelAdvanceTick();
|
||||
|
||||
// Get the current rotation values;
|
||||
var authorityRotation = m_AuthoritativeTransform.transform.rotation;
|
||||
var authorityEulerRotation = authorityRotation.eulerAngles;
|
||||
|
||||
// Verify rotation is not marked dirty when rotated by half of the threshold
|
||||
authorityEulerRotation.y += halfThreshold;
|
||||
authorityRotation.eulerAngles = authorityEulerRotation;
|
||||
m_AuthoritativeTransform.transform.rotation = authorityRotation;
|
||||
results = m_AuthoritativeTransform.ApplyState();
|
||||
Assert.IsFalse(results.isRotationDirty, $"Rotation is dirty when rotation threshold is {m_AuthoritativeTransform.RotAngleThreshold} degrees and only adjusted by {halfThreshold} degrees!");
|
||||
// Now allow the delta state to be processed and sent (just allow for two ticks to cover edge cases with time travel and the testing environment)
|
||||
TimeTravelAdvanceTick();
|
||||
TimeTravelAdvanceTick();
|
||||
|
||||
// Verify rotation is marked dirty when rotated by another half threshold value
|
||||
authorityEulerRotation.y += halfThreshold;
|
||||
authorityRotation.eulerAngles = authorityEulerRotation;
|
||||
m_AuthoritativeTransform.transform.rotation = authorityRotation;
|
||||
results = m_AuthoritativeTransform.ApplyState();
|
||||
Assert.IsTrue(results.isRotationDirty, $"Rotation was not dirty when rotated by the threshold value: {m_AuthoritativeTransform.RotAngleThreshold} degrees!");
|
||||
// Now allow the delta state to be processed and sent (just allow for two ticks to cover edge cases with time travel and the testing environment)
|
||||
TimeTravelAdvanceTick();
|
||||
TimeTravelAdvanceTick();
|
||||
|
||||
//Reset rotation back to zero on all axis
|
||||
authorityRotation.eulerAngles = authorityEulerRotation = Vector3.zero;
|
||||
m_AuthoritativeTransform.transform.rotation = authorityRotation;
|
||||
// Now allow the delta state to be processed and sent (just allow for two ticks to cover edge cases with time travel and the testing environment)
|
||||
TimeTravelAdvanceTick();
|
||||
TimeTravelAdvanceTick();
|
||||
|
||||
// Rotate by 360 minus halfThreshold (which is really just negative halfThreshold) and verify rotation is not marked dirty
|
||||
authorityEulerRotation.y = 360 - halfThreshold;
|
||||
authorityRotation.eulerAngles = authorityEulerRotation;
|
||||
m_AuthoritativeTransform.transform.rotation = authorityRotation;
|
||||
results = m_AuthoritativeTransform.ApplyState();
|
||||
Assert.IsFalse(results.isRotationDirty, $"Rotation is dirty when rotation threshold is {m_AuthoritativeTransform.RotAngleThreshold} degrees and only adjusted by " +
|
||||
$"{Mathf.DeltaAngle(0, authorityEulerRotation.y)} degrees!");
|
||||
// Now allow the delta state to be processed and sent (just allow for two ticks to cover edge cases with time travel and the testing environment)
|
||||
TimeTravelAdvanceTick();
|
||||
TimeTravelAdvanceTick();
|
||||
|
||||
// Now apply one more minor decrement that should trigger a dirty flag
|
||||
authorityEulerRotation.y -= halfThreshold;
|
||||
authorityRotation.eulerAngles = authorityEulerRotation;
|
||||
m_AuthoritativeTransform.transform.rotation = authorityRotation;
|
||||
results = m_AuthoritativeTransform.ApplyState();
|
||||
Assert.IsTrue(results.isRotationDirty, $"Rotation was not dirty when rotated by {Mathf.DeltaAngle(0, authorityEulerRotation.y)} degrees!");
|
||||
|
||||
//Reset rotation back to zero on all axis
|
||||
authorityRotation.eulerAngles = authorityEulerRotation = Vector3.zero;
|
||||
m_AuthoritativeTransform.transform.rotation = authorityRotation;
|
||||
// Now allow the delta state to be processed and sent (just allow for two ticks to cover edge cases with time travel and the testing environment)
|
||||
TimeTravelAdvanceTick();
|
||||
TimeTravelAdvanceTick();
|
||||
|
||||
// Minor decrement again under the threshold value
|
||||
authorityEulerRotation.y -= halfThreshold;
|
||||
authorityRotation.eulerAngles = authorityEulerRotation;
|
||||
m_AuthoritativeTransform.transform.rotation = authorityRotation;
|
||||
results = m_AuthoritativeTransform.ApplyState();
|
||||
Assert.IsFalse(results.isRotationDirty, $"Rotation is dirty when rotation threshold is {m_AuthoritativeTransform.RotAngleThreshold} degrees and only adjusted by " +
|
||||
$"{Mathf.DeltaAngle(0, authorityEulerRotation.y)} degrees!");
|
||||
// Now allow the delta state to be processed and sent (just allow for two ticks to cover edge cases with time travel and the testing environment)
|
||||
TimeTravelAdvanceTick();
|
||||
TimeTravelAdvanceTick();
|
||||
|
||||
// Now decrement another half threshold which should trigger the dirty flag
|
||||
authorityEulerRotation.y -= halfThreshold;
|
||||
authorityRotation.eulerAngles = authorityEulerRotation;
|
||||
m_AuthoritativeTransform.transform.rotation = authorityRotation;
|
||||
results = m_AuthoritativeTransform.ApplyState();
|
||||
Assert.IsTrue(results.isRotationDirty, $"Rotation was not dirty when rotated by {Mathf.DeltaAngle(0, authorityEulerRotation.y)} degrees!");
|
||||
}
|
||||
|
||||
private bool ValidateBitSetValues()
|
||||
{
|
||||
var serverState = m_AuthoritativeTransform.AuthorityLastSentState;
|
||||
var clientState = m_NonAuthoritativeTransform.LocalAuthoritativeNetworkState;
|
||||
if (serverState.HasPositionX == clientState.HasPositionX && serverState.HasPositionY == clientState.HasPositionY && serverState.HasPositionZ == clientState.HasPositionZ &&
|
||||
serverState.HasRotAngleX == clientState.HasRotAngleX && serverState.HasRotAngleY == clientState.HasRotAngleY && serverState.HasRotAngleZ == clientState.HasRotAngleZ &&
|
||||
serverState.HasScaleX == clientState.HasScaleX && serverState.HasScaleY == clientState.HasScaleY && serverState.HasScaleZ == clientState.HasScaleZ)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test to make sure that the bitset value is updated properly
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestBitsetValue([Values] Interpolation interpolation)
|
||||
{
|
||||
m_AuthoritativeTransform.Interpolate = interpolation == Interpolation.EnableInterpolate;
|
||||
m_NonAuthoritativeTransform.RotAngleThreshold = m_AuthoritativeTransform.RotAngleThreshold = 0.1f;
|
||||
m_AuthoritativeTransform.transform.rotation = Quaternion.Euler(1, 2, 3);
|
||||
TimeTravelAdvanceTick();
|
||||
var success = WaitForConditionOrTimeOutWithTimeTravel(ValidateBitSetValues);
|
||||
Assert.True(success, $"Timed out waiting for Authoritative Bitset state to equal NonAuthoritative replicated Bitset state!");
|
||||
success = WaitForConditionOrTimeOutWithTimeTravel(() => RotationsMatch());
|
||||
Assert.True(success, $"[Timed-Out] Authoritative rotation {m_AuthoritativeTransform.transform.rotation.eulerAngles} != Non-Authoritative rotation {m_NonAuthoritativeTransform.transform.rotation.eulerAngles}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This validates that you can perform multiple explicit <see cref="NetworkTransform.SetState(Vector3?, Quaternion?, Vector3?, bool)"/> calls
|
||||
/// within the same fractional tick period without the loss of the states applied.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestMultipleExplicitSetStates([Values] Interpolation interpolation)
|
||||
{
|
||||
var interpolate = interpolation == Interpolation.EnableInterpolate;
|
||||
m_AuthoritativeTransform.Interpolate = interpolate;
|
||||
var updatedPosition = GetRandomVector3(-5.0f, 5.0f);
|
||||
m_AuthoritativeTransform.SetState(updatedPosition, null, null, !interpolate);
|
||||
// Advance to next frame
|
||||
TimeTravel(0.001f, 1);
|
||||
|
||||
updatedPosition += GetRandomVector3(-5.0f, 5.0f);
|
||||
m_AuthoritativeTransform.SetState(updatedPosition, null, null, !interpolate);
|
||||
TimeTravelAdvanceTick();
|
||||
|
||||
var success = WaitForConditionOrTimeOutWithTimeTravel(() => PositionsMatch());
|
||||
Assert.True(success, $"[Timed-Out] Authoritative position {m_AuthoritativeTransform.transform.position} != Non-Authoritative position {m_NonAuthoritativeTransform.transform.position}");
|
||||
Assert.True(Approximately(updatedPosition, m_NonAuthoritativeTransform.transform.position), $"NonAuthority position {m_NonAuthoritativeTransform.transform.position} does not equal the calculated position {updatedPosition}!");
|
||||
|
||||
var updatedRotation = m_AuthoritativeTransform.transform.rotation;
|
||||
updatedRotation.eulerAngles += GetRandomVector3(-30.0f, 30.0f);
|
||||
m_AuthoritativeTransform.SetState(null, updatedRotation, null, !interpolate);
|
||||
// Advance to next frame
|
||||
TimeTravel(0.001f, 1);
|
||||
|
||||
updatedRotation.eulerAngles += GetRandomVector3(-30.0f, 30.0f);
|
||||
m_AuthoritativeTransform.SetState(null, updatedRotation, null, !interpolate);
|
||||
TimeTravelAdvanceTick();
|
||||
|
||||
success = WaitForConditionOrTimeOutWithTimeTravel(() => RotationsMatch());
|
||||
Assert.True(success, $"[Timed-Out] Authoritative rotation {m_AuthoritativeTransform.transform.rotation.eulerAngles} != Non-Authoritative rotation {m_NonAuthoritativeTransform.transform.rotation.eulerAngles}");
|
||||
Assert.True(Approximately(updatedRotation.eulerAngles, m_NonAuthoritativeTransform.transform.rotation.eulerAngles), $"NonAuthority rotation {m_NonAuthoritativeTransform.transform.rotation.eulerAngles} does not equal the calculated rotation {updatedRotation.eulerAngles}!");
|
||||
|
||||
var updatedScale = m_AuthoritativeTransform.transform.localScale;
|
||||
updatedScale += GetRandomVector3(-2.0f, 2.0f);
|
||||
m_AuthoritativeTransform.SetState(null, null, updatedScale, !interpolate);
|
||||
// Advance to next frame
|
||||
TimeTravel(0.001f, 1);
|
||||
|
||||
updatedScale += GetRandomVector3(-2.0f, 2.0f);
|
||||
m_AuthoritativeTransform.SetState(null, null, updatedScale, !interpolate);
|
||||
TimeTravelAdvanceTick();
|
||||
|
||||
success = WaitForConditionOrTimeOutWithTimeTravel(() => ScaleValuesMatch());
|
||||
Assert.True(success, $"[Timed-Out] Authoritative rotation {m_AuthoritativeTransform.transform.localScale} != Non-Authoritative rotation {m_NonAuthoritativeTransform.transform.localScale}");
|
||||
Assert.True(Approximately(updatedScale, m_NonAuthoritativeTransform.transform.localScale), $"NonAuthority scale {m_NonAuthoritativeTransform.transform.localScale} does not equal the calculated scale {updatedScale}!");
|
||||
|
||||
// Now test explicitly setting all axis of transform multiple times during a fractional tick period
|
||||
updatedPosition += GetRandomVector3(-5.0f, 5.0f);
|
||||
updatedRotation.eulerAngles += GetRandomVector3(-30.0f, 30.0f);
|
||||
updatedScale += GetRandomVector3(-2.0f, 2.0f);
|
||||
m_AuthoritativeTransform.SetState(updatedPosition, updatedRotation, updatedScale, !interpolate);
|
||||
// Advance to next frame
|
||||
TimeTravel(0.001f, 1);
|
||||
|
||||
updatedPosition += GetRandomVector3(-5.0f, 5.0f);
|
||||
updatedRotation.eulerAngles += GetRandomVector3(-30.0f, 30.0f);
|
||||
updatedScale += GetRandomVector3(-2.0f, 2.0f);
|
||||
m_AuthoritativeTransform.SetState(updatedPosition, updatedRotation, updatedScale, !interpolate);
|
||||
// Advance to next frame
|
||||
TimeTravel(0.001f, 1);
|
||||
|
||||
updatedPosition += GetRandomVector3(-5.0f, 5.0f);
|
||||
updatedRotation.eulerAngles += GetRandomVector3(-30.0f, 30.0f);
|
||||
updatedScale += GetRandomVector3(-2.0f, 2.0f);
|
||||
m_AuthoritativeTransform.SetState(updatedPosition, updatedRotation, updatedScale, !interpolate);
|
||||
// Advance to next frame
|
||||
TimeTravel(0.001f, 1);
|
||||
|
||||
TimeTravelAdvanceTick();
|
||||
|
||||
success = WaitForConditionOrTimeOutWithTimeTravel(() => PositionsMatch() && RotationsMatch() && ScaleValuesMatch());
|
||||
Assert.True(success, $"[Timed-Out] Authoritative transform != Non-Authoritative transform!");
|
||||
Assert.True(Approximately(updatedPosition, m_NonAuthoritativeTransform.transform.position), $"NonAuthority position {m_NonAuthoritativeTransform.transform.position} does not equal the calculated position {updatedPosition}!");
|
||||
Assert.True(Approximately(updatedRotation.eulerAngles, m_NonAuthoritativeTransform.transform.rotation.eulerAngles), $"NonAuthority rotation {m_NonAuthoritativeTransform.transform.rotation.eulerAngles} does not equal the calculated rotation {updatedRotation.eulerAngles}!");
|
||||
Assert.True(Approximately(updatedScale, m_NonAuthoritativeTransform.transform.localScale), $"NonAuthority scale {m_NonAuthoritativeTransform.transform.localScale} does not equal the calculated scale {updatedScale}!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This test validates the <see cref="NetworkTransform.SetState(Vector3?, Quaternion?, Vector3?, bool)"/> method
|
||||
/// usage for the non-authoritative side. It will either be the owner or the server making/requesting state changes.
|
||||
/// This validates that:
|
||||
/// - The owner authoritative mode can still be controlled by the server (i.e. owner authoritative with server authority override capabilities)
|
||||
/// - The server authoritative mode can still be directed by the client owner.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This also tests that the original server authoritative model with client-owner driven NetworkTransforms is preserved.
|
||||
/// </remarks>
|
||||
[Test]
|
||||
public void NonAuthorityOwnerSettingStateTest([Values] Interpolation interpolation)
|
||||
{
|
||||
var interpolate = interpolation != Interpolation.EnableInterpolate;
|
||||
m_AuthoritativeTransform.Interpolate = interpolate;
|
||||
m_NonAuthoritativeTransform.Interpolate = interpolate;
|
||||
m_NonAuthoritativeTransform.RotAngleThreshold = m_AuthoritativeTransform.RotAngleThreshold = 0.1f;
|
||||
|
||||
// Test one parameter at a time first
|
||||
var newPosition = new Vector3(125f, 35f, 65f);
|
||||
var newRotation = Quaternion.Euler(1, 2, 3);
|
||||
var newScale = new Vector3(2.0f, 2.0f, 2.0f);
|
||||
m_NonAuthoritativeTransform.SetState(newPosition, null, null, interpolate);
|
||||
var success = WaitForConditionOrTimeOutWithTimeTravel(() => PositionsMatchesValue(newPosition));
|
||||
Assert.True(success, $"Timed out waiting for non-authoritative position state request to be applied!");
|
||||
Assert.True(Approximately(newPosition, m_AuthoritativeTransform.transform.position), "Authoritative position does not match!");
|
||||
Assert.True(Approximately(newPosition, m_NonAuthoritativeTransform.transform.position), "Non-Authoritative position does not match!");
|
||||
|
||||
m_NonAuthoritativeTransform.SetState(null, newRotation, null, interpolate);
|
||||
success = WaitForConditionOrTimeOutWithTimeTravel(() => RotationMatchesValue(newRotation.eulerAngles));
|
||||
Assert.True(success, $"Timed out waiting for non-authoritative rotation state request to be applied!");
|
||||
Assert.True(Approximately(newRotation.eulerAngles, m_AuthoritativeTransform.transform.rotation.eulerAngles), "Authoritative rotation does not match!");
|
||||
Assert.True(Approximately(newRotation.eulerAngles, m_NonAuthoritativeTransform.transform.rotation.eulerAngles), "Non-Authoritative rotation does not match!");
|
||||
|
||||
m_NonAuthoritativeTransform.SetState(null, null, newScale, interpolate);
|
||||
success = WaitForConditionOrTimeOutWithTimeTravel(() => ScaleMatchesValue(newScale));
|
||||
Assert.True(success, $"Timed out waiting for non-authoritative scale state request to be applied!");
|
||||
Assert.True(Approximately(newScale, m_AuthoritativeTransform.transform.localScale), "Authoritative scale does not match!");
|
||||
Assert.True(Approximately(newScale, m_NonAuthoritativeTransform.transform.localScale), "Non-Authoritative scale does not match!");
|
||||
|
||||
// Test all parameters at once
|
||||
newPosition = new Vector3(55f, 95f, -25f);
|
||||
newRotation = Quaternion.Euler(20, 5, 322);
|
||||
newScale = new Vector3(0.5f, 0.5f, 0.5f);
|
||||
|
||||
m_NonAuthoritativeTransform.SetState(newPosition, newRotation, newScale, interpolate);
|
||||
success = WaitForConditionOrTimeOutWithTimeTravel(() => PositionRotationScaleMatches(newPosition, newRotation.eulerAngles, newScale));
|
||||
Assert.True(success, $"Timed out waiting for non-authoritative position, rotation, and scale state request to be applied!");
|
||||
Assert.True(Approximately(newPosition, m_AuthoritativeTransform.transform.position), "Authoritative position does not match!");
|
||||
Assert.True(Approximately(newPosition, m_NonAuthoritativeTransform.transform.position), "Non-Authoritative position does not match!");
|
||||
Assert.True(Approximately(newRotation.eulerAngles, m_AuthoritativeTransform.transform.rotation.eulerAngles), "Authoritative rotation does not match!");
|
||||
Assert.True(Approximately(newRotation.eulerAngles, m_NonAuthoritativeTransform.transform.rotation.eulerAngles), "Non-Authoritative rotation does not match!");
|
||||
Assert.True(Approximately(newScale, m_AuthoritativeTransform.transform.localScale), "Authoritative scale does not match!");
|
||||
Assert.True(Approximately(newScale, m_NonAuthoritativeTransform.transform.localScale), "Non-Authoritative scale does not match!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a69eaaf3c4b8464a93520a3514bf5e8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,485 @@
|
||||
// TODO: Rewrite test to use the tools package. Debug simulator not available in UTP 2.X.
|
||||
#if !UTP_TRANSPORT_2_0_ABOVE
|
||||
using System.Collections;
|
||||
using NUnit.Framework;
|
||||
using Unity.Netcode.Components;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace Unity.Netcode.RuntimeTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Integration tests for NetworkTransform that will test both
|
||||
/// server and host operating modes and will test both authoritative
|
||||
/// models for each operating mode when packet loss and latency is
|
||||
/// present.
|
||||
/// </summary>
|
||||
[TestFixture(HostOrServer.Host, Authority.ServerAuthority, RotationCompression.None, Rotation.Euler, Precision.Full)]
|
||||
[TestFixture(HostOrServer.Host, Authority.ServerAuthority, RotationCompression.None, Rotation.Euler, Precision.Half)]
|
||||
[TestFixture(HostOrServer.Host, Authority.ServerAuthority, RotationCompression.None, Rotation.Quaternion, Precision.Full)]
|
||||
[TestFixture(HostOrServer.Host, Authority.ServerAuthority, RotationCompression.None, Rotation.Quaternion, Precision.Half)]
|
||||
[TestFixture(HostOrServer.Host, Authority.ServerAuthority, RotationCompression.QuaternionCompress, Rotation.Quaternion, Precision.Full)]
|
||||
[TestFixture(HostOrServer.Host, Authority.ServerAuthority, RotationCompression.QuaternionCompress, Rotation.Quaternion, Precision.Half)]
|
||||
public class NetworkTransformPacketLossTests : NetworkTransformBase
|
||||
{
|
||||
private const int k_Latency = 50;
|
||||
private const int k_PacketLoss = 2;
|
||||
|
||||
private Vector3 m_RandomPosition;
|
||||
private Vector3 m_TeleportOffset = new Vector3(-1024f, 0f, 0f);
|
||||
private bool m_Teleported;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="testWithHost">Determines if we are running as a server or host</param>
|
||||
/// <param name="authority">Determines if we are using server or owner authority</param>
|
||||
public NetworkTransformPacketLossTests(HostOrServer testWithHost, Authority authority, RotationCompression rotationCompression, Rotation rotation, Precision precision) :
|
||||
base(testWithHost, authority, rotationCompression, rotation, precision)
|
||||
{ }
|
||||
|
||||
protected override void OnServerAndClientsCreated()
|
||||
{
|
||||
base.OnServerAndClientsCreated();
|
||||
|
||||
var unityTransport = m_ServerNetworkManager.NetworkConfig.NetworkTransport as Transports.UTP.UnityTransport;
|
||||
unityTransport.SetDebugSimulatorParameters(k_Latency, 0, k_PacketLoss);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles validating all children of the test objects have matching local and global space vaues.
|
||||
/// </summary>
|
||||
private IEnumerator AllChildrenLocalTransformValuesMatch(bool useSubChild, ChildrenTransformCheckType checkType)
|
||||
{
|
||||
// We don't assert on timeout here because we want to log this information during PostAllChildrenLocalTransformValuesMatch
|
||||
yield return WaitForConditionOrTimeOut(() => AllInstancesKeptLocalTransformValues(useSubChild));
|
||||
var success = true;
|
||||
m_InfoMessage.AppendLine($"[{checkType}][{useSubChild}] Timed out waiting for all children to have the correct local space values:\n");
|
||||
if (s_GlobalTimeoutHelper.TimedOut)
|
||||
{
|
||||
var waitForMs = new WaitForSeconds(0.001f);
|
||||
// If we timed out, then wait for a full range of ticks to assure all data has been synchronized before declaring this a failed test.
|
||||
for (int j = 0; j < m_ServerNetworkManager.NetworkConfig.TickRate; j++)
|
||||
{
|
||||
var instances = useSubChild ? ChildObjectComponent.SubInstances : ChildObjectComponent.Instances;
|
||||
success = PostAllChildrenLocalTransformValuesMatch(useSubChild);
|
||||
yield return waitForMs;
|
||||
}
|
||||
}
|
||||
|
||||
if (!success)
|
||||
{
|
||||
Assert.True(success, m_InfoMessage.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates that transform values remain the same when a NetworkTransform is
|
||||
/// parented under another NetworkTransform under all of the possible axial conditions
|
||||
/// as well as when the parent has a varying scale.
|
||||
/// </summary>
|
||||
[UnityTest]
|
||||
public IEnumerator ParentedNetworkTransformTest([Values] Interpolation interpolation, [Values] bool worldPositionStays, [Values(0.5f, 1.0f, 5.0f)] float scale)
|
||||
{
|
||||
ChildObjectComponent.EnableChildLog = m_EnableVerboseDebug;
|
||||
if (m_EnableVerboseDebug)
|
||||
{
|
||||
ChildObjectComponent.TestCount++;
|
||||
}
|
||||
// Get the NetworkManager that will have authority in order to spawn with the correct authority
|
||||
var isServerAuthority = m_Authority == Authority.ServerAuthority;
|
||||
var authorityNetworkManager = m_ServerNetworkManager;
|
||||
if (!isServerAuthority)
|
||||
{
|
||||
authorityNetworkManager = m_ClientNetworkManagers[0];
|
||||
}
|
||||
|
||||
// Spawn a parent and children
|
||||
ChildObjectComponent.HasSubChild = true;
|
||||
var serverSideParent = SpawnObject(m_ParentObject.gameObject, authorityNetworkManager).GetComponent<NetworkObject>();
|
||||
var serverSideChild = SpawnObject(m_ChildObject.gameObject, authorityNetworkManager).GetComponent<NetworkObject>();
|
||||
var serverSideSubChild = SpawnObject(m_SubChildObject.gameObject, authorityNetworkManager).GetComponent<NetworkObject>();
|
||||
|
||||
// Assure all of the child object instances are spawned before proceeding to parenting
|
||||
yield return WaitForConditionOrTimeOut(AllChildObjectInstancesAreSpawned);
|
||||
AssertOnTimeout("Timed out waiting for all child instances to be spawned!");
|
||||
|
||||
// Get the authority parent and child instances
|
||||
m_AuthorityParentObject = NetworkTransformTestComponent.AuthorityInstance.NetworkObject;
|
||||
m_AuthorityChildObject = ChildObjectComponent.AuthorityInstance.NetworkObject;
|
||||
m_AuthoritySubChildObject = ChildObjectComponent.AuthoritySubInstance.NetworkObject;
|
||||
|
||||
// The child NetworkTransform will use world space when world position stays and
|
||||
// local space when world position does not stay when parenting.
|
||||
ChildObjectComponent.AuthorityInstance.InLocalSpace = !worldPositionStays;
|
||||
ChildObjectComponent.AuthorityInstance.UseHalfFloatPrecision = m_Precision == Precision.Half;
|
||||
ChildObjectComponent.AuthorityInstance.UseQuaternionSynchronization = m_Rotation == Rotation.Quaternion;
|
||||
ChildObjectComponent.AuthorityInstance.UseQuaternionCompression = m_RotationCompression == RotationCompression.QuaternionCompress;
|
||||
|
||||
ChildObjectComponent.AuthoritySubInstance.InLocalSpace = !worldPositionStays;
|
||||
ChildObjectComponent.AuthoritySubInstance.UseHalfFloatPrecision = m_Precision == Precision.Half;
|
||||
ChildObjectComponent.AuthoritySubInstance.UseQuaternionSynchronization = m_Rotation == Rotation.Quaternion;
|
||||
ChildObjectComponent.AuthoritySubInstance.UseQuaternionCompression = m_RotationCompression == RotationCompression.QuaternionCompress;
|
||||
|
||||
// Set whether we are interpolating or not
|
||||
m_AuthorityParentNetworkTransform = m_AuthorityParentObject.GetComponent<NetworkTransformTestComponent>();
|
||||
m_AuthorityParentNetworkTransform.Interpolate = interpolation == Interpolation.EnableInterpolate;
|
||||
m_AuthorityChildNetworkTransform = m_AuthorityChildObject.GetComponent<ChildObjectComponent>();
|
||||
m_AuthorityChildNetworkTransform.Interpolate = interpolation == Interpolation.EnableInterpolate;
|
||||
m_AuthoritySubChildNetworkTransform = m_AuthoritySubChildObject.GetComponent<ChildObjectComponent>();
|
||||
m_AuthoritySubChildNetworkTransform.Interpolate = interpolation == Interpolation.EnableInterpolate;
|
||||
|
||||
|
||||
// Apply a scale to the parent object to make sure the scale on the child is properly updated on
|
||||
// non-authority instances.
|
||||
var halfScale = scale * 0.5f;
|
||||
m_AuthorityParentObject.transform.localScale = GetRandomVector3(scale - halfScale, scale + halfScale);
|
||||
m_AuthorityChildObject.transform.localScale = GetRandomVector3(scale - halfScale, scale + halfScale);
|
||||
m_AuthoritySubChildObject.transform.localScale = GetRandomVector3(scale - halfScale, scale + halfScale);
|
||||
|
||||
// Allow one tick for authority to update these changes
|
||||
|
||||
yield return WaitForConditionOrTimeOut(PositionRotationScaleMatches);
|
||||
|
||||
AssertOnTimeout("All transform values did not match prior to parenting!");
|
||||
|
||||
// Parent the child under the parent with the current world position stays setting
|
||||
Assert.True(serverSideChild.TrySetParent(serverSideParent.transform, worldPositionStays), "[Server-Side Child] Failed to set child's parent!");
|
||||
|
||||
// Parent the sub-child under the child with the current world position stays setting
|
||||
Assert.True(serverSideSubChild.TrySetParent(serverSideChild.transform, worldPositionStays), "[Server-Side SubChild] Failed to set sub-child's parent!");
|
||||
|
||||
// This waits for all child instances to be parented
|
||||
yield return WaitForConditionOrTimeOut(AllChildObjectInstancesHaveChild);
|
||||
AssertOnTimeout("Timed out waiting for all instances to have parented a child!");
|
||||
var latencyWait = new WaitForSeconds(k_Latency * 0.003f);
|
||||
// Wait for at least 3x designated latency period
|
||||
yield return latencyWait;
|
||||
|
||||
// This validates each child instance has preserved their local space values
|
||||
yield return AllChildrenLocalTransformValuesMatch(false, ChildrenTransformCheckType.Connected_Clients);
|
||||
|
||||
// This validates each sub-child instance has preserved their local space values
|
||||
yield return AllChildrenLocalTransformValuesMatch(true, ChildrenTransformCheckType.Connected_Clients);
|
||||
|
||||
// Verify that a late joining client will synchronize to the parented NetworkObjects properly
|
||||
yield return CreateAndStartNewClient();
|
||||
|
||||
// Assure all of the child object instances are spawned (basically for the newly connected client)
|
||||
yield return WaitForConditionOrTimeOut(AllChildObjectInstancesAreSpawned);
|
||||
AssertOnTimeout("Timed out waiting for all child instances to be spawned!");
|
||||
|
||||
// This waits for all child instances to be parented
|
||||
yield return WaitForConditionOrTimeOut(AllChildObjectInstancesHaveChild);
|
||||
AssertOnTimeout("Timed out waiting for all instances to have parented a child!");
|
||||
|
||||
// Wait for at least 3x designated latency period
|
||||
yield return latencyWait;
|
||||
|
||||
// This validates each child instance has preserved their local space values
|
||||
yield return AllChildrenLocalTransformValuesMatch(false, ChildrenTransformCheckType.Late_Join_Client);
|
||||
|
||||
// This validates each sub-child instance has preserved their local space values
|
||||
yield return AllChildrenLocalTransformValuesMatch(true, ChildrenTransformCheckType.Late_Join_Client);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This validates that multiple changes can occur within the same tick or over
|
||||
/// several ticks while still keeping non-authoritative instances synchronized.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// When testing < 3 axis: Interpolation is disabled and only 3 delta updates are applied per unique test
|
||||
/// When testing 3 axis: Interpolation is enabled, sometimes an axis is intentionally excluded during a
|
||||
/// delta update, and it runs through 8 delta updates per unique test.
|
||||
/// </remarks>
|
||||
[UnityTest]
|
||||
public IEnumerator NetworkTransformMultipleChangesOverTime([Values] TransformSpace testLocalTransform, [Values] Axis axis)
|
||||
{
|
||||
yield return s_DefaultWaitForTick;
|
||||
// Just test for OverrideState.Update (they are already being tested for functionality in normal NetworkTransformTests)
|
||||
var overideState = OverrideState.Update;
|
||||
var tickRelativeTime = new WaitForSeconds(1.0f / m_ServerNetworkManager.NetworkConfig.TickRate);
|
||||
m_AuthoritativeTransform.InLocalSpace = testLocalTransform == TransformSpace.Local;
|
||||
bool axisX = axis == Axis.X || axis == Axis.XY || axis == Axis.XZ || axis == Axis.XYZ;
|
||||
bool axisY = axis == Axis.Y || axis == Axis.XY || axis == Axis.YZ || axis == Axis.XYZ;
|
||||
bool axisZ = axis == Axis.Z || axis == Axis.XZ || axis == Axis.YZ || axis == Axis.XYZ;
|
||||
|
||||
var axisCount = axisX ? 1 : 0;
|
||||
axisCount += axisY ? 1 : 0;
|
||||
axisCount += axisZ ? 1 : 0;
|
||||
|
||||
m_AuthoritativeTransform.StatePushed = false;
|
||||
// Enable interpolation when all 3 axis are selected to make sure we are synchronizing properly
|
||||
// when interpolation is enabled.
|
||||
m_AuthoritativeTransform.Interpolate = axisCount == 3 ? true : false;
|
||||
|
||||
m_CurrentAxis = axis;
|
||||
|
||||
// Authority dictates what is synchronized and what the precision is going to be
|
||||
// so we only need to set this on the authoritative side.
|
||||
m_AuthoritativeTransform.UseHalfFloatPrecision = m_Precision == Precision.Half;
|
||||
m_AuthoritativeTransform.UseQuaternionSynchronization = m_Rotation == Rotation.Quaternion;
|
||||
m_AuthoritativeTransform.UseQuaternionCompression = m_RotationCompression == RotationCompression.QuaternionCompress;
|
||||
|
||||
m_AuthoritativeTransform.SyncPositionX = axisX;
|
||||
m_AuthoritativeTransform.SyncPositionY = axisY;
|
||||
m_AuthoritativeTransform.SyncPositionZ = axisZ;
|
||||
|
||||
if (!m_AuthoritativeTransform.UseQuaternionSynchronization)
|
||||
{
|
||||
m_AuthoritativeTransform.SyncRotAngleX = axisX;
|
||||
m_AuthoritativeTransform.SyncRotAngleY = axisY;
|
||||
m_AuthoritativeTransform.SyncRotAngleZ = axisZ;
|
||||
}
|
||||
else
|
||||
{
|
||||
// This is not required for usage (setting the value should not matter when quaternion synchronization is enabled)
|
||||
// but is required for this test so we don't get a failure on an axis that is marked to not be synchronized when
|
||||
// validating the authority's values on non-authority instances.
|
||||
m_AuthoritativeTransform.SyncRotAngleX = true;
|
||||
m_AuthoritativeTransform.SyncRotAngleY = true;
|
||||
m_AuthoritativeTransform.SyncRotAngleZ = true;
|
||||
}
|
||||
|
||||
m_AuthoritativeTransform.SyncScaleX = axisX;
|
||||
m_AuthoritativeTransform.SyncScaleY = axisY;
|
||||
m_AuthoritativeTransform.SyncScaleZ = axisZ;
|
||||
|
||||
var positionStart = GetRandomVector3(0.25f, 1.75f);
|
||||
var rotationStart = GetRandomVector3(1f, 15f);
|
||||
var scaleStart = GetRandomVector3(0.25f, 2.0f);
|
||||
var position = positionStart;
|
||||
var rotation = rotationStart;
|
||||
var scale = scaleStart;
|
||||
var success = false;
|
||||
|
||||
|
||||
// Wait for the deltas to be pushed
|
||||
yield return WaitForConditionOrTimeOut(() => m_AuthoritativeTransform.StatePushed);
|
||||
|
||||
// Just in case we drop the first few state updates
|
||||
if (s_GlobalTimeoutHelper.TimedOut)
|
||||
{
|
||||
// Set the local state to not reflect the authority state's local space settings
|
||||
// to trigger the state update (it would eventually get there, but this is an integration test)
|
||||
var state = m_AuthoritativeTransform.LocalAuthoritativeNetworkState;
|
||||
state.InLocalSpace = !m_AuthoritativeTransform.InLocalSpace;
|
||||
m_AuthoritativeTransform.LocalAuthoritativeNetworkState = state;
|
||||
// Wait for the deltas to be pushed
|
||||
yield return WaitForConditionOrTimeOut(() => m_AuthoritativeTransform.StatePushed);
|
||||
}
|
||||
AssertOnTimeout("State was never pushed!");
|
||||
|
||||
// Allow the precision settings to propagate first as changing precision
|
||||
// causes a teleport event to occur
|
||||
yield return s_DefaultWaitForTick;
|
||||
yield return s_DefaultWaitForTick;
|
||||
yield return s_DefaultWaitForTick;
|
||||
yield return s_DefaultWaitForTick;
|
||||
yield return s_DefaultWaitForTick;
|
||||
var iterations = axisCount == 3 ? k_PositionRotationScaleIterations3Axis : k_PositionRotationScaleIterations;
|
||||
|
||||
// Move and rotate within the same tick, validate the non-authoritative instance updates
|
||||
// to each set of changes. Repeat several times.
|
||||
for (int i = 0; i < iterations; i++)
|
||||
{
|
||||
// Always reset this per delta update pass
|
||||
m_AxisExcluded = false;
|
||||
var deltaPositionDelta = GetRandomVector3(-1.5f, 1.5f);
|
||||
var deltaRotationDelta = GetRandomVector3(-3.5f, 3.5f);
|
||||
var deltaScaleDelta = GetRandomVector3(-0.5f, 0.5f);
|
||||
|
||||
m_NonAuthoritativeTransform.StateUpdated = false;
|
||||
m_AuthoritativeTransform.StatePushed = false;
|
||||
|
||||
// With two or more axis, excluding one of them while chaging another will validate that
|
||||
// full precision updates are maintaining their target state value(s) to interpolate towards
|
||||
if (axisCount == 3)
|
||||
{
|
||||
position += RandomlyExcludeAxis(deltaPositionDelta);
|
||||
rotation += RandomlyExcludeAxis(deltaRotationDelta);
|
||||
scale += RandomlyExcludeAxis(deltaScaleDelta);
|
||||
}
|
||||
else
|
||||
{
|
||||
position += deltaPositionDelta;
|
||||
rotation += deltaRotationDelta;
|
||||
scale += deltaScaleDelta;
|
||||
}
|
||||
|
||||
// Apply delta between ticks
|
||||
MoveRotateAndScaleAuthority(position, rotation, scale, overideState);
|
||||
|
||||
// Wait for the deltas to be pushed (unlike the original test, we don't wait for state to be updated as that could be dropped here)
|
||||
yield return WaitForConditionOrTimeOut(() => m_AuthoritativeTransform.StatePushed);
|
||||
AssertOnTimeout($"[Non-Interpolate {i}] Timed out waiting for state to be pushed ({m_AuthoritativeTransform.StatePushed})!");
|
||||
|
||||
// For 3 axis, we will skip validating that the non-authority interpolates to its target point at least once.
|
||||
// This will validate that non-authoritative updates are maintaining their target state axis values if only 2
|
||||
// of the axis are being updated to assure interpolation maintains the targeted axial value per axis.
|
||||
// For 2 and 1 axis tests we always validate per delta update
|
||||
if (m_AxisExcluded || axisCount < 3)
|
||||
{
|
||||
// Wait for deltas to synchronize on non-authoritative side
|
||||
yield return WaitForConditionOrTimeOut(PositionRotationScaleMatches);
|
||||
// Provide additional debug info about what failed (if it fails)
|
||||
if (s_GlobalTimeoutHelper.TimedOut)
|
||||
{
|
||||
Debug.Log("[Synch Issue Start - 1]");
|
||||
// If we timed out, then wait for a full range of ticks (plus 1) to assure it sent synchronization data.
|
||||
for (int j = 0; j < m_ServerNetworkManager.NetworkConfig.TickRate * 2; j++)
|
||||
{
|
||||
success = PositionRotationScaleMatches();
|
||||
if (success)
|
||||
{
|
||||
// If we matched, then something was dropped and recovered when synchronized
|
||||
break;
|
||||
}
|
||||
yield return s_DefaultWaitForTick;
|
||||
}
|
||||
|
||||
// Only if we still didn't match
|
||||
if (!success)
|
||||
{
|
||||
m_EnableVerboseDebug = true;
|
||||
success = PositionRotationScaleMatches();
|
||||
m_EnableVerboseDebug = false;
|
||||
Debug.Log("[Synch Issue END - 1]");
|
||||
AssertOnTimeout($"[Non-Interpolate {i}] Timed out waiting for non-authority to match authority's position or rotation");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (axisCount == 3)
|
||||
{
|
||||
// As a final test, wait for deltas to synchronize on non-authoritative side to assure it interpolates to the correct values
|
||||
yield return WaitForConditionOrTimeOut(PositionRotationScaleMatches);
|
||||
// Provide additional debug info about what failed (if it fails)
|
||||
if (s_GlobalTimeoutHelper.TimedOut)
|
||||
{
|
||||
Debug.Log("[Synch Issue Start - 2]");
|
||||
// If we timed out, then wait for a full range of ticks (plus 1) to assure it sent synchronization data.
|
||||
for (int j = 0; j < m_ServerNetworkManager.NetworkConfig.TickRate * 2; j++)
|
||||
{
|
||||
success = PositionRotationScaleMatches();
|
||||
if (success)
|
||||
{
|
||||
// If we matched, then something was dropped and recovered when synchronized
|
||||
break;
|
||||
}
|
||||
yield return s_DefaultWaitForTick;
|
||||
}
|
||||
|
||||
// Only if we still didn't match
|
||||
if (!success)
|
||||
{
|
||||
m_EnableVerboseDebug = true;
|
||||
PositionRotationScaleMatches();
|
||||
m_EnableVerboseDebug = false;
|
||||
Debug.Log("[Synch Issue END - 2]");
|
||||
AssertOnTimeout("Timed out waiting for non-authority to match authority's position or rotation");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests changing all axial values one at a time with packet loss
|
||||
/// These tests are performed:
|
||||
/// - While in local space and world space
|
||||
/// - While interpolation is enabled and disabled
|
||||
/// </summary>
|
||||
[UnityTest]
|
||||
public IEnumerator TestAuthoritativeTransformChangeOneAtATime([Values] TransformSpace testLocalTransform, [Values] Interpolation interpolation)
|
||||
{
|
||||
// Just test for OverrideState.Update (they are already being tested for functionality in normal NetworkTransformTests)
|
||||
m_AuthoritativeTransform.Interpolate = interpolation == Interpolation.EnableInterpolate;
|
||||
m_AuthoritativeTransform.InLocalSpace = testLocalTransform == TransformSpace.Local;
|
||||
m_AuthoritativeTransform.UseQuaternionCompression = m_RotationCompression == RotationCompression.QuaternionCompress;
|
||||
m_AuthoritativeTransform.UseHalfFloatPrecision = m_Precision == Precision.Half;
|
||||
m_AuthoritativeTransform.UseQuaternionSynchronization = m_Rotation == Rotation.Quaternion;
|
||||
m_NonAuthoritativeTransform.Interpolate = interpolation == Interpolation.EnableInterpolate;
|
||||
|
||||
|
||||
// test position
|
||||
var authPlayerTransform = m_AuthoritativeTransform.transform;
|
||||
|
||||
Assert.AreEqual(Vector3.zero, m_NonAuthoritativeTransform.transform.position, "server side pos should be zero at first"); // sanity check
|
||||
|
||||
m_AuthoritativeTransform.transform.position = GetRandomVector3(2f, 30f);
|
||||
|
||||
yield return WaitForConditionOrTimeOut(() => PositionsMatch());
|
||||
AssertOnTimeout($"Timed out waiting for positions to match {m_AuthoritativeTransform.transform.position} | {m_NonAuthoritativeTransform.transform.position}");
|
||||
|
||||
// test rotation
|
||||
Assert.AreEqual(Quaternion.identity, m_NonAuthoritativeTransform.transform.rotation, "wrong initial value for rotation"); // sanity check
|
||||
|
||||
m_AuthoritativeTransform.transform.rotation = Quaternion.Euler(GetRandomVector3(5, 60)); // using euler angles instead of quaternions directly to really see issues users might encounter
|
||||
|
||||
// Make sure the values match
|
||||
yield return WaitForConditionOrTimeOut(() => RotationsMatch());
|
||||
AssertOnTimeout($"Timed out waiting for rotations to match");
|
||||
|
||||
m_AuthoritativeTransform.StatePushed = false;
|
||||
m_AuthoritativeTransform.transform.localScale = GetRandomVector3(1, 6);
|
||||
|
||||
// Make sure the scale values match
|
||||
yield return WaitForConditionOrTimeOut(() => ScaleValuesMatch());
|
||||
AssertOnTimeout($"Timed out waiting for scale values to match");
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator TestSameFrameDeltaStateAndTeleport([Values] TransformSpace testLocalTransform, [Values] Interpolation interpolation)
|
||||
{
|
||||
m_AuthoritativeTransform.Interpolate = interpolation == Interpolation.EnableInterpolate;
|
||||
|
||||
m_NonAuthoritativeTransform.Interpolate = interpolation == Interpolation.EnableInterpolate;
|
||||
|
||||
m_AuthoritativeTransform.InLocalSpace = testLocalTransform == TransformSpace.Local;
|
||||
|
||||
// test position
|
||||
var authPlayerTransform = m_AuthoritativeTransform.transform;
|
||||
|
||||
Assert.AreEqual(Vector3.zero, m_NonAuthoritativeTransform.transform.position, "server side pos should be zero at first"); // sanity check
|
||||
|
||||
m_AuthoritativeTransform.AuthorityPushedTransformState += OnAuthorityPushedTransformState;
|
||||
m_RandomPosition = GetRandomVector3(2f, 30f);
|
||||
m_AuthoritativeTransform.transform.position = m_RandomPosition;
|
||||
m_Teleported = false;
|
||||
yield return WaitForConditionOrTimeOut(() => m_Teleported);
|
||||
AssertOnTimeout($"Timed out waiting for random position to be pushed!");
|
||||
|
||||
yield return WaitForConditionOrTimeOut(() => PositionsMatch());
|
||||
AssertOnTimeout($"Timed out waiting for positions to match {m_AuthoritativeTransform.transform.position} | {m_NonAuthoritativeTransform.transform.position}");
|
||||
|
||||
var authPosition = m_AuthoritativeTransform.GetSpaceRelativePosition();
|
||||
var nonAuthPosition = m_NonAuthoritativeTransform.GetSpaceRelativePosition();
|
||||
|
||||
var finalPosition = m_TeleportOffset + m_RandomPosition;
|
||||
Assert.True(Approximately(authPosition, finalPosition), $"Authority did not set its position ({authPosition}) to the teleport position ({finalPosition})!");
|
||||
Assert.True(Approximately(nonAuthPosition, finalPosition), $"NonAuthority did not set its position ({nonAuthPosition}) to the teleport position ({finalPosition})!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For the TestSameFrameDeltaStateAndTeleport test, we want to teleport on the same frame that we had a delta state update when
|
||||
/// using unreliable delta state updates (i.e. we want the unreliable packet to be sent first and then the teleport to be sent on
|
||||
/// the next tick. Store off both states when invoked
|
||||
/// </summary>
|
||||
/// <param name="networkTransformState"></param>
|
||||
private void OnAuthorityPushedTransformState(ref NetworkTransform.NetworkTransformState networkTransformState)
|
||||
{
|
||||
// Match the first position update
|
||||
if (Approximately(m_RandomPosition, networkTransformState.GetPosition()))
|
||||
{
|
||||
// Teleport to the m_RandomPosition plus the
|
||||
m_AuthoritativeTransform.SetState(m_TeleportOffset + m_RandomPosition, null, null, false);
|
||||
m_AuthoritativeTransform.AuthorityPushedTransformState -= OnAuthorityPushedTransformState;
|
||||
m_Teleported = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e0f584e8eb891d5459373e96e54fe821
|
||||
timeCreated: 1620872927
|
||||
@@ -230,6 +230,11 @@ namespace Unity.Netcode.RuntimeTests
|
||||
var gameObject = new GameObject($"Test-{nameof(NetworkTransformStateTests)}.{nameof(TestSyncAxes)}");
|
||||
var networkObject = gameObject.AddComponent<NetworkObject>();
|
||||
var networkTransform = gameObject.AddComponent<NetworkTransform>();
|
||||
|
||||
var manager = new GameObject($"Test-{nameof(NetworkManager)}.{nameof(TestSyncAxes)}");
|
||||
var networkManager = manager.AddComponent<NetworkManager>();
|
||||
networkObject.NetworkManagerOwner = networkManager;
|
||||
|
||||
networkTransform.enabled = false; // do not tick `FixedUpdate()` or `Update()`
|
||||
|
||||
var initialPosition = Vector3.zero;
|
||||
@@ -269,6 +274,7 @@ namespace Unity.Netcode.RuntimeTests
|
||||
|
||||
if (syncPosX || syncPosY || syncPosZ || syncRotX || syncRotY || syncRotZ || syncScaX || syncScaY || syncScaZ)
|
||||
{
|
||||
Assert.NotNull(networkTransform.NetworkManager, "NetworkManager is NULL!");
|
||||
Assert.IsTrue(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
}
|
||||
}
|
||||
@@ -714,6 +720,7 @@ namespace Unity.Netcode.RuntimeTests
|
||||
}
|
||||
|
||||
Object.DestroyImmediate(gameObject);
|
||||
Object.DestroyImmediate(manager);
|
||||
}
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user