com.unity.netcode.gameobjects@1.1.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.1.0] - 2022-10-21 ### Added - Added `NetworkManager.IsApproved` flag that is set to `true` a client has been approved.(#2261) - `UnityTransport` now provides a way to set the Relay server data directly from the `RelayServerData` structure (provided by the Unity Transport package) throuh its `SetRelayServerData` method. This allows making use of the new APIs in UTP 1.3 that simplify integration of the Relay SDK. (#2235) - IPv6 is now supported for direct connections when using `UnityTransport`. (#2232) - Added WebSocket support when using UTP 2.0 with `UseWebSockets` property in the `UnityTransport` component of the `NetworkManager` allowing to pick WebSockets for communication. When building for WebGL, this selection happens automatically. (#2201) - Added position, rotation, and scale to the `ParentSyncMessage` which provides users the ability to specify the final values on the server-side when `OnNetworkObjectParentChanged` is invoked just before the message is created (when the `Transform` values are applied to the message). (#2146) - Added `NetworkObject.TryRemoveParent` method for convenience purposes opposed to having to cast null to either `GameObject` or `NetworkObject`. (#2146) ### Changed - Updated `UnityTransport` dependency on `com.unity.transport` to 1.3.0. (#2231) - The send queues of `UnityTransport` are now dynamically-sized. This means that there shouldn't be any need anymore to tweak the 'Max Send Queue Size' value. In fact, this field is now removed from the inspector and will not be serialized anymore. It is still possible to set it manually using the `MaxSendQueueSize` property, but it is not recommended to do so aside from some specific needs (e.g. limiting the amount of memory used by the send queues in very constrained environments). (#2212) - As a consequence of the above change, the `UnityTransport.InitialMaxSendQueueSize` field is now deprecated. There is no default value anymore since send queues are dynamically-sized. (#2212) - The debug simulator in `UnityTransport` is now non-deterministic. Its random number generator used to be seeded with a constant value, leading to the same pattern of packet drops, delays, and jitter in every run. (#2196) - `NetworkVariable<>` now supports managed `INetworkSerializable` types, as well as other managed types with serialization/deserialization delegates registered to `UserNetworkVariableSerialization<T>.WriteValue` and `UserNetworkVariableSerialization<T>.ReadValue` (#2219) - `NetworkVariable<>` and `BufferSerializer<BufferSerializerReader>` now deserialize `INetworkSerializable` types in-place, rather than constructing new ones. (#2219) ### Fixed - Fixed `NetworkManager.ApprovalTimeout` will not timeout due to slower client synchronization times as it now uses the added `NetworkManager.IsApproved` flag to determined if the client has been approved or not.(#2261) - Fixed issue caused when changing ownership of objects hidden to some clients (#2242) - Fixed issue where an in-scene placed NetworkObject would not invoke NetworkBehaviour.OnNetworkSpawn if the GameObject was disabled when it was despawned. (#2239) - Fixed issue where clients were not rebuilding the `NetworkConfig` hash value for each unique connection request. (#2226) - Fixed the issue where player objects were not taking the `DontDestroyWithOwner` property into consideration when a client disconnected. (#2225) - Fixed issue where `SceneEventProgress` would not complete if a client late joins while it is still in progress. (#2222) - Fixed issue where `SceneEventProgress` would not complete if a client disconnects. (#2222) - Fixed issues with detecting if a `SceneEventProgress` has timed out. (#2222) - Fixed issue #1924 where `UnityTransport` would fail to restart after a first failure (even if what caused the initial failure was addressed). (#2220) - Fixed issue where `NetworkTransform.SetStateServerRpc` and `NetworkTransform.SetStateClientRpc` were not honoring local vs world space settings when applying the position and rotation. (#2203) - Fixed ILPP `TypeLoadException` on WebGL on MacOS Editor and potentially other platforms. (#2199) - Implicit conversion of NetworkObjectReference to GameObject will now return null instead of throwing an exception if the referenced object could not be found (i.e., was already despawned) (#2158) - Fixed warning resulting from a stray NetworkAnimator.meta file (#2153) - Fixed Connection Approval Timeout not working client side. (#2164) - Fixed issue where the `WorldPositionStays` parenting parameter was not being synchronized with clients. (#2146) - Fixed issue where parented in-scene placed `NetworkObject`s would fail for late joining clients. (#2146) - Fixed issue where scale was not being synchronized which caused issues with nested parenting and scale when `WorldPositionStays` was true. (#2146) - Fixed issue with `NetworkTransform.ApplyTransformToNetworkStateWithInfo` where it was not honoring axis sync settings when `NetworkTransformState.IsTeleportingNextFrame` was true. (#2146) - Fixed issue with `NetworkTransform.TryCommitTransformToServer` where it was not honoring the `InLocalSpace` setting. (#2146) - Fixed ClientRpcs always reporting in the profiler view as going to all clients, even when limited to a subset of clients by `ClientRpcParams`. (#2144) - Fixed RPC codegen failing to choose the correct extension methods for `FastBufferReader` and `FastBufferWriter` when the parameters were a generic type (i.e., List<int>) and extensions for multiple instantiations of that type have been defined (i.e., List<int> and List<string>) (#2142) - Fixed the issue where running a server (i.e. not host) the second player would not receive updates (unless a third player joined). (#2127) - Fixed issue where late-joining client transition synchronization could fail when more than one transition was occurring.(#2127) - Fixed throwing an exception in `OnNetworkUpdate` causing other `OnNetworkUpdate` calls to not be executed. (#1739) - Fixed synchronization when Time.timeScale is set to 0. This changes timing update to use unscaled deltatime. Now network updates rate are independent from the local time scale. (#2171) - Fixed not sending all NetworkVariables to all clients when a client connects to a server. (#1987) - Fixed IsOwner/IsOwnedByServer being wrong on the server after calling RemoveOwnership (#2211)
This commit is contained in:
@@ -4,15 +4,87 @@ using UnityEngine;
|
||||
|
||||
namespace Unity.Netcode.RuntimeTests
|
||||
{
|
||||
|
||||
[TestFixture(TransformSpace.World)]
|
||||
[TestFixture(TransformSpace.Local)]
|
||||
public class NetworkTransformStateTests
|
||||
{
|
||||
[Test]
|
||||
public void TestSyncAxes(
|
||||
[Values] bool inLocalSpace,
|
||||
[Values] bool syncPosX, [Values] bool syncPosY, [Values] bool syncPosZ,
|
||||
[Values] bool syncRotX, [Values] bool syncRotY, [Values] bool syncRotZ,
|
||||
[Values] bool syncScaX, [Values] bool syncScaY, [Values] bool syncScaZ)
|
||||
public enum SyncAxis
|
||||
{
|
||||
SyncPosX,
|
||||
SyncPosY,
|
||||
SyncPosZ,
|
||||
SyncPosXY,
|
||||
SyncPosXZ,
|
||||
SyncPosYZ,
|
||||
SyncPosXYZ,
|
||||
SyncRotX,
|
||||
SyncRotY,
|
||||
SyncRotZ,
|
||||
SyncRotXY,
|
||||
SyncRotXZ,
|
||||
SyncRotYZ,
|
||||
SyncRotXYZ,
|
||||
SyncScaleX,
|
||||
SyncScaleY,
|
||||
SyncScaleZ,
|
||||
SyncScaleXY,
|
||||
SyncScaleXZ,
|
||||
SyncScaleYZ,
|
||||
SyncScaleXYZ,
|
||||
SyncAllX,
|
||||
SyncAllY,
|
||||
SyncAllZ,
|
||||
SyncAllXY,
|
||||
SyncAllXZ,
|
||||
SyncAllYZ,
|
||||
SyncAllXYZ
|
||||
}
|
||||
|
||||
public enum TransformSpace
|
||||
{
|
||||
World,
|
||||
Local
|
||||
}
|
||||
|
||||
public enum SynchronizationType
|
||||
{
|
||||
Delta,
|
||||
Teleport
|
||||
}
|
||||
|
||||
private TransformSpace m_TransformSpace;
|
||||
|
||||
public NetworkTransformStateTests(TransformSpace transformSpace)
|
||||
{
|
||||
m_TransformSpace = transformSpace;
|
||||
}
|
||||
|
||||
private bool WillAnAxisBeSynchronized(ref NetworkTransform networkTransform)
|
||||
{
|
||||
return networkTransform.SyncScaleX || networkTransform.SyncScaleY || networkTransform.SyncScaleZ ||
|
||||
networkTransform.SyncRotAngleX || networkTransform.SyncRotAngleY || networkTransform.SyncRotAngleZ ||
|
||||
networkTransform.SyncPositionX || networkTransform.SyncPositionY || networkTransform.SyncPositionZ;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSyncAxes([Values] SynchronizationType synchronizationType, [Values] SyncAxis syncAxis)
|
||||
|
||||
{
|
||||
bool inLocalSpace = m_TransformSpace == TransformSpace.Local;
|
||||
bool isTeleporting = synchronizationType == SynchronizationType.Teleport;
|
||||
bool syncPosX = syncAxis == SyncAxis.SyncPosX || syncAxis == SyncAxis.SyncPosXY || syncAxis == SyncAxis.SyncPosXZ || syncAxis == SyncAxis.SyncPosXYZ || syncAxis == SyncAxis.SyncAllX || syncAxis == SyncAxis.SyncAllXY || syncAxis == SyncAxis.SyncAllXZ || syncAxis == SyncAxis.SyncAllXYZ;
|
||||
bool syncPosY = syncAxis == SyncAxis.SyncPosY || syncAxis == SyncAxis.SyncPosXY || syncAxis == SyncAxis.SyncPosYZ || syncAxis == SyncAxis.SyncPosXYZ || syncAxis == SyncAxis.SyncAllY || syncAxis == SyncAxis.SyncAllXY || syncAxis == SyncAxis.SyncAllYZ || syncAxis == SyncAxis.SyncAllXYZ;
|
||||
bool syncPosZ = syncAxis == SyncAxis.SyncPosZ || syncAxis == SyncAxis.SyncPosXZ || syncAxis == SyncAxis.SyncPosYZ || syncAxis == SyncAxis.SyncPosXYZ || syncAxis == SyncAxis.SyncAllZ || syncAxis == SyncAxis.SyncAllXZ || syncAxis == SyncAxis.SyncAllYZ || syncAxis == SyncAxis.SyncAllXYZ;
|
||||
|
||||
bool syncRotX = syncAxis == SyncAxis.SyncRotX || syncAxis == SyncAxis.SyncRotXY || syncAxis == SyncAxis.SyncRotXZ || syncAxis == SyncAxis.SyncRotXYZ || syncAxis == SyncAxis.SyncRotX || syncAxis == SyncAxis.SyncAllXY || syncAxis == SyncAxis.SyncAllXZ || syncAxis == SyncAxis.SyncAllXYZ;
|
||||
bool syncRotY = syncAxis == SyncAxis.SyncRotY || syncAxis == SyncAxis.SyncRotXY || syncAxis == SyncAxis.SyncRotYZ || syncAxis == SyncAxis.SyncRotXYZ || syncAxis == SyncAxis.SyncRotY || syncAxis == SyncAxis.SyncAllXY || syncAxis == SyncAxis.SyncAllYZ || syncAxis == SyncAxis.SyncAllXYZ;
|
||||
bool syncRotZ = syncAxis == SyncAxis.SyncRotZ || syncAxis == SyncAxis.SyncRotXZ || syncAxis == SyncAxis.SyncRotYZ || syncAxis == SyncAxis.SyncRotXYZ || syncAxis == SyncAxis.SyncRotZ || syncAxis == SyncAxis.SyncAllXZ || syncAxis == SyncAxis.SyncAllYZ || syncAxis == SyncAxis.SyncAllXYZ;
|
||||
|
||||
bool syncScaX = syncAxis == SyncAxis.SyncScaleX || syncAxis == SyncAxis.SyncScaleXY || syncAxis == SyncAxis.SyncScaleXZ || syncAxis == SyncAxis.SyncScaleXYZ || syncAxis == SyncAxis.SyncAllX || syncAxis == SyncAxis.SyncAllXY || syncAxis == SyncAxis.SyncAllXZ || syncAxis == SyncAxis.SyncAllXYZ;
|
||||
bool syncScaY = syncAxis == SyncAxis.SyncScaleY || syncAxis == SyncAxis.SyncScaleXY || syncAxis == SyncAxis.SyncScaleYZ || syncAxis == SyncAxis.SyncScaleXYZ || syncAxis == SyncAxis.SyncAllY || syncAxis == SyncAxis.SyncAllXY || syncAxis == SyncAxis.SyncAllYZ || syncAxis == SyncAxis.SyncAllXYZ;
|
||||
bool syncScaZ = syncAxis == SyncAxis.SyncScaleZ || syncAxis == SyncAxis.SyncScaleXZ || syncAxis == SyncAxis.SyncScaleYZ || syncAxis == SyncAxis.SyncScaleXYZ || syncAxis == SyncAxis.SyncAllZ || syncAxis == SyncAxis.SyncAllXZ || syncAxis == SyncAxis.SyncAllYZ || syncAxis == SyncAxis.SyncAllXYZ;
|
||||
|
||||
var gameObject = new GameObject($"Test-{nameof(NetworkTransformStateTests)}.{nameof(TestSyncAxes)}");
|
||||
var networkObject = gameObject.AddComponent<NetworkObject>();
|
||||
var networkTransform = gameObject.AddComponent<NetworkTransform>();
|
||||
@@ -36,27 +108,13 @@ namespace Unity.Netcode.RuntimeTests
|
||||
networkTransform.SyncScaleZ = syncScaZ;
|
||||
networkTransform.InLocalSpace = inLocalSpace;
|
||||
|
||||
// We want a relatively clean networkTransform state before we try to apply the transform to it
|
||||
// We only preserve InLocalSpace and IsTeleportingNextFrame properties as they are the only things
|
||||
// needed when applying a transform to a NetworkTransformState
|
||||
var networkTransformState = new NetworkTransform.NetworkTransformState
|
||||
{
|
||||
PositionX = initialPosition.x,
|
||||
PositionY = initialPosition.y,
|
||||
PositionZ = initialPosition.z,
|
||||
RotAngleX = initialRotAngles.x,
|
||||
RotAngleY = initialRotAngles.y,
|
||||
RotAngleZ = initialRotAngles.z,
|
||||
ScaleX = initialScale.x,
|
||||
ScaleY = initialScale.y,
|
||||
ScaleZ = initialScale.z,
|
||||
HasPositionX = syncPosX,
|
||||
HasPositionY = syncPosY,
|
||||
HasPositionZ = syncPosZ,
|
||||
HasRotAngleX = syncRotX,
|
||||
HasRotAngleY = syncRotY,
|
||||
HasRotAngleZ = syncRotZ,
|
||||
HasScaleX = syncScaX,
|
||||
HasScaleY = syncScaY,
|
||||
HasScaleZ = syncScaZ,
|
||||
InLocalSpace = inLocalSpace
|
||||
InLocalSpace = inLocalSpace,
|
||||
IsTeleportingNextFrame = isTeleporting,
|
||||
};
|
||||
|
||||
// Step 1: change properties, expect state to be dirty
|
||||
@@ -71,95 +129,382 @@ namespace Unity.Netcode.RuntimeTests
|
||||
}
|
||||
}
|
||||
|
||||
// Step 2: disable a particular sync flag, expect state to be not dirty
|
||||
// We want to start with a fresh NetworkTransformState since it could have other state
|
||||
// information from the last time we applied the transform
|
||||
networkTransformState = new NetworkTransform.NetworkTransformState
|
||||
{
|
||||
var position = networkTransform.transform.position;
|
||||
var rotAngles = networkTransform.transform.eulerAngles;
|
||||
var scale = networkTransform.transform.localScale;
|
||||
InLocalSpace = inLocalSpace,
|
||||
IsTeleportingNextFrame = isTeleporting,
|
||||
};
|
||||
var position = networkTransform.transform.position;
|
||||
var rotAngles = networkTransform.transform.eulerAngles;
|
||||
var scale = networkTransform.transform.localScale;
|
||||
|
||||
// Step 2: Verify the state changes in a tick are additive
|
||||
// TODO: This will need to change if we update NetworkTransform to send all of the
|
||||
// axis deltas that happened over a tick as a collection instead of collapsing them
|
||||
// as the changes are detected.
|
||||
{
|
||||
networkTransformState = new NetworkTransform.NetworkTransformState
|
||||
{
|
||||
InLocalSpace = inLocalSpace,
|
||||
IsTeleportingNextFrame = isTeleporting,
|
||||
};
|
||||
|
||||
// SyncPositionX
|
||||
if (syncPosX)
|
||||
{
|
||||
position.x++;
|
||||
networkTransform.transform.position = position;
|
||||
Assert.IsTrue(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
Assert.IsTrue(networkTransformState.HasPositionX);
|
||||
}
|
||||
|
||||
// SyncPositionY
|
||||
if (syncPosY)
|
||||
{
|
||||
position = networkTransform.transform.position;
|
||||
position.y++;
|
||||
networkTransform.transform.position = position;
|
||||
Assert.IsTrue(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
Assert.IsTrue(networkTransformState.HasPositionX || !syncPosX);
|
||||
Assert.IsTrue(networkTransformState.HasPositionY);
|
||||
}
|
||||
|
||||
// SyncPositionZ
|
||||
if (syncPosZ)
|
||||
{
|
||||
position = networkTransform.transform.position;
|
||||
position.z++;
|
||||
networkTransform.transform.position = position;
|
||||
Assert.IsTrue(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
Assert.IsTrue(networkTransformState.HasPositionX || !syncPosX);
|
||||
Assert.IsTrue(networkTransformState.HasPositionY || !syncPosY);
|
||||
Assert.IsTrue(networkTransformState.HasPositionZ);
|
||||
}
|
||||
|
||||
// SyncRotAngleX
|
||||
if (syncRotX)
|
||||
{
|
||||
rotAngles = networkTransform.transform.eulerAngles;
|
||||
rotAngles.x++;
|
||||
networkTransform.transform.eulerAngles = rotAngles;
|
||||
Assert.IsTrue(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
Assert.IsTrue(networkTransformState.HasPositionX || !syncPosX);
|
||||
Assert.IsTrue(networkTransformState.HasPositionY || !syncPosY);
|
||||
Assert.IsTrue(networkTransformState.HasPositionZ || !syncPosZ);
|
||||
Assert.IsTrue(networkTransformState.HasRotAngleX);
|
||||
}
|
||||
|
||||
// SyncRotAngleY
|
||||
if (syncRotY)
|
||||
{
|
||||
rotAngles = networkTransform.transform.eulerAngles;
|
||||
rotAngles.y++;
|
||||
networkTransform.transform.eulerAngles = rotAngles;
|
||||
Assert.IsTrue(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
Assert.IsTrue(networkTransformState.HasPositionX || !syncPosX);
|
||||
Assert.IsTrue(networkTransformState.HasPositionY || !syncPosY);
|
||||
Assert.IsTrue(networkTransformState.HasPositionZ || !syncPosZ);
|
||||
Assert.IsTrue(networkTransformState.HasRotAngleX || !syncRotX);
|
||||
Assert.IsTrue(networkTransformState.HasRotAngleY);
|
||||
}
|
||||
// SyncRotAngleZ
|
||||
if (syncRotZ)
|
||||
{
|
||||
rotAngles = networkTransform.transform.eulerAngles;
|
||||
rotAngles.z++;
|
||||
networkTransform.transform.eulerAngles = rotAngles;
|
||||
Assert.IsTrue(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
Assert.IsTrue(networkTransformState.HasPositionX || !syncPosX);
|
||||
Assert.IsTrue(networkTransformState.HasPositionY || !syncPosY);
|
||||
Assert.IsTrue(networkTransformState.HasPositionZ || !syncPosZ);
|
||||
Assert.IsTrue(networkTransformState.HasRotAngleX || !syncRotX);
|
||||
Assert.IsTrue(networkTransformState.HasRotAngleY || !syncRotY);
|
||||
Assert.IsTrue(networkTransformState.HasRotAngleZ);
|
||||
}
|
||||
|
||||
// SyncScaleX
|
||||
if (syncScaX)
|
||||
{
|
||||
scale = networkTransform.transform.localScale;
|
||||
scale.x++;
|
||||
networkTransform.transform.localScale = scale;
|
||||
Assert.IsTrue(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
Assert.IsTrue(networkTransformState.HasPositionX || !syncPosX);
|
||||
Assert.IsTrue(networkTransformState.HasPositionY || !syncPosY);
|
||||
Assert.IsTrue(networkTransformState.HasPositionZ || !syncPosZ);
|
||||
Assert.IsTrue(networkTransformState.HasRotAngleX || !syncRotX);
|
||||
Assert.IsTrue(networkTransformState.HasRotAngleY || !syncRotY);
|
||||
Assert.IsTrue(networkTransformState.HasRotAngleZ || !syncRotZ);
|
||||
Assert.IsTrue(networkTransformState.HasScaleX);
|
||||
}
|
||||
// SyncScaleY
|
||||
if (syncScaY)
|
||||
{
|
||||
scale = networkTransform.transform.localScale;
|
||||
scale.y++;
|
||||
networkTransform.transform.localScale = scale;
|
||||
Assert.IsTrue(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
Assert.IsTrue(networkTransformState.HasPositionX || !syncPosX);
|
||||
Assert.IsTrue(networkTransformState.HasPositionY || !syncPosY);
|
||||
Assert.IsTrue(networkTransformState.HasPositionZ || !syncPosZ);
|
||||
Assert.IsTrue(networkTransformState.HasRotAngleX || !syncRotX);
|
||||
Assert.IsTrue(networkTransformState.HasRotAngleY || !syncRotY);
|
||||
Assert.IsTrue(networkTransformState.HasRotAngleZ || !syncRotZ);
|
||||
Assert.IsTrue(networkTransformState.HasScaleX || !syncScaX);
|
||||
Assert.IsTrue(networkTransformState.HasScaleY);
|
||||
}
|
||||
// SyncScaleZ
|
||||
if (syncScaZ)
|
||||
{
|
||||
scale = networkTransform.transform.localScale;
|
||||
scale.z++;
|
||||
networkTransform.transform.localScale = scale;
|
||||
Assert.IsTrue(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
Assert.IsTrue(networkTransformState.HasPositionX || !syncPosX);
|
||||
Assert.IsTrue(networkTransformState.HasPositionY || !syncPosY);
|
||||
Assert.IsTrue(networkTransformState.HasPositionZ || !syncPosZ);
|
||||
Assert.IsTrue(networkTransformState.HasRotAngleX || !syncRotX);
|
||||
Assert.IsTrue(networkTransformState.HasRotAngleY || !syncRotY);
|
||||
Assert.IsTrue(networkTransformState.HasRotAngleZ || !syncRotZ);
|
||||
Assert.IsTrue(networkTransformState.HasScaleX || !syncScaX);
|
||||
Assert.IsTrue(networkTransformState.HasScaleY || !syncScaY);
|
||||
Assert.IsTrue(networkTransformState.HasScaleZ);
|
||||
}
|
||||
}
|
||||
|
||||
// Step 3: disable a particular sync flag, expect state to be not dirty
|
||||
// We do this last because it changes which axis will be synchronized.
|
||||
{
|
||||
networkTransformState = new NetworkTransform.NetworkTransformState
|
||||
{
|
||||
InLocalSpace = inLocalSpace,
|
||||
IsTeleportingNextFrame = isTeleporting,
|
||||
};
|
||||
|
||||
position = networkTransform.transform.position;
|
||||
rotAngles = networkTransform.transform.eulerAngles;
|
||||
scale = networkTransform.transform.localScale;
|
||||
|
||||
// SyncPositionX
|
||||
if (syncPosX)
|
||||
{
|
||||
networkTransform.SyncPositionX = false;
|
||||
|
||||
position.x++;
|
||||
networkTransform.transform.position = position;
|
||||
|
||||
Assert.IsFalse(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
// If we are synchronizing more than 1 axis (teleporting impacts this too)
|
||||
if (syncAxis != SyncAxis.SyncPosX && WillAnAxisBeSynchronized(ref networkTransform))
|
||||
{
|
||||
// For the x axis position value We should expect the state to still be considered dirty (more than one axis is being synchronized and we are teleporting)
|
||||
Assert.IsTrue(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
// However, we expect it to not have applied the position x delta
|
||||
Assert.IsFalse(networkTransformState.HasPositionX);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.IsFalse(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
}
|
||||
}
|
||||
|
||||
// SyncPositionY
|
||||
if (syncPosY)
|
||||
{
|
||||
networkTransform.SyncPositionY = false;
|
||||
|
||||
position.y++;
|
||||
networkTransform.transform.position = position;
|
||||
|
||||
Assert.IsFalse(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
if (syncAxis != SyncAxis.SyncPosY && WillAnAxisBeSynchronized(ref networkTransform))
|
||||
{
|
||||
// We want to start with a fresh NetworkTransformState since it could have other state
|
||||
// information from the last time we applied the transform
|
||||
networkTransformState = new NetworkTransform.NetworkTransformState
|
||||
{
|
||||
InLocalSpace = inLocalSpace,
|
||||
IsTeleportingNextFrame = isTeleporting,
|
||||
};
|
||||
Assert.IsTrue(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
Assert.IsFalse(networkTransformState.HasPositionY);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.IsFalse(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
}
|
||||
}
|
||||
|
||||
// SyncPositionZ
|
||||
if (syncPosZ)
|
||||
{
|
||||
networkTransform.SyncPositionZ = false;
|
||||
|
||||
position.z++;
|
||||
networkTransform.transform.position = position;
|
||||
|
||||
Assert.IsFalse(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
if (syncAxis != SyncAxis.SyncPosZ && WillAnAxisBeSynchronized(ref networkTransform))
|
||||
{
|
||||
// We want to start with a fresh NetworkTransformState since it could have other state
|
||||
// information from the last time we applied the transform
|
||||
networkTransformState = new NetworkTransform.NetworkTransformState
|
||||
{
|
||||
InLocalSpace = inLocalSpace,
|
||||
IsTeleportingNextFrame = isTeleporting,
|
||||
};
|
||||
Assert.IsTrue(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
Assert.IsFalse(networkTransformState.HasPositionZ);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.IsFalse(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
}
|
||||
}
|
||||
|
||||
// SyncRotAngleX
|
||||
if (syncRotX)
|
||||
{
|
||||
networkTransform.SyncRotAngleX = false;
|
||||
|
||||
rotAngles.x++;
|
||||
networkTransform.transform.eulerAngles = rotAngles;
|
||||
|
||||
Assert.IsFalse(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
if (syncAxis != SyncAxis.SyncRotX && WillAnAxisBeSynchronized(ref networkTransform))
|
||||
{
|
||||
// We want to start with a fresh NetworkTransformState since it could have other state
|
||||
// information from the last time we applied the transform
|
||||
networkTransformState = new NetworkTransform.NetworkTransformState
|
||||
{
|
||||
InLocalSpace = inLocalSpace,
|
||||
IsTeleportingNextFrame = isTeleporting,
|
||||
};
|
||||
Assert.IsTrue(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
Assert.IsFalse(networkTransformState.HasRotAngleX);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.IsFalse(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
}
|
||||
}
|
||||
// SyncRotAngleY
|
||||
if (syncRotY)
|
||||
{
|
||||
networkTransform.SyncRotAngleY = false;
|
||||
|
||||
rotAngles.y++;
|
||||
networkTransform.transform.eulerAngles = rotAngles;
|
||||
|
||||
Assert.IsFalse(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
if (syncAxis != SyncAxis.SyncRotY && WillAnAxisBeSynchronized(ref networkTransform))
|
||||
{
|
||||
// We want to start with a fresh NetworkTransformState since it could have other state
|
||||
// information from the last time we applied the transform
|
||||
networkTransformState = new NetworkTransform.NetworkTransformState
|
||||
{
|
||||
InLocalSpace = inLocalSpace,
|
||||
IsTeleportingNextFrame = isTeleporting,
|
||||
};
|
||||
Assert.IsTrue(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
Assert.IsFalse(networkTransformState.HasRotAngleY);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.IsFalse(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
}
|
||||
}
|
||||
// SyncRotAngleZ
|
||||
if (syncRotZ)
|
||||
{
|
||||
networkTransform.SyncRotAngleZ = false;
|
||||
|
||||
rotAngles.z++;
|
||||
networkTransform.transform.eulerAngles = rotAngles;
|
||||
|
||||
Assert.IsFalse(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
if (syncAxis != SyncAxis.SyncRotZ && WillAnAxisBeSynchronized(ref networkTransform))
|
||||
{
|
||||
// We want to start with a fresh NetworkTransformState since it could have other state
|
||||
// information from the last time we applied the transform
|
||||
networkTransformState = new NetworkTransform.NetworkTransformState
|
||||
{
|
||||
InLocalSpace = inLocalSpace,
|
||||
IsTeleportingNextFrame = isTeleporting,
|
||||
};
|
||||
Assert.IsTrue(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
Assert.IsFalse(networkTransformState.HasRotAngleZ);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.IsFalse(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
}
|
||||
}
|
||||
|
||||
// SyncScaleX
|
||||
if (syncScaX)
|
||||
{
|
||||
networkTransform.SyncScaleX = false;
|
||||
|
||||
scale.x++;
|
||||
networkTransform.transform.localScale = scale;
|
||||
|
||||
Assert.IsFalse(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
if (syncAxis != SyncAxis.SyncScaleX && WillAnAxisBeSynchronized(ref networkTransform))
|
||||
{
|
||||
// We want to start with a fresh NetworkTransformState since it could have other state
|
||||
// information from the last time we applied the transform
|
||||
networkTransformState = new NetworkTransform.NetworkTransformState
|
||||
{
|
||||
InLocalSpace = inLocalSpace,
|
||||
IsTeleportingNextFrame = isTeleporting,
|
||||
};
|
||||
Assert.IsTrue(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
Assert.IsFalse(networkTransformState.HasScaleX);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.IsFalse(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
}
|
||||
}
|
||||
// SyncScaleY
|
||||
if (syncScaY)
|
||||
{
|
||||
networkTransform.SyncScaleY = false;
|
||||
|
||||
scale.y++;
|
||||
networkTransform.transform.localScale = scale;
|
||||
|
||||
Assert.IsFalse(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
if (syncAxis != SyncAxis.SyncScaleY && WillAnAxisBeSynchronized(ref networkTransform))
|
||||
{
|
||||
// We want to start with a fresh NetworkTransformState since it could have other state
|
||||
// information from the last time we applied the transform
|
||||
networkTransformState = new NetworkTransform.NetworkTransformState
|
||||
{
|
||||
InLocalSpace = inLocalSpace,
|
||||
IsTeleportingNextFrame = isTeleporting,
|
||||
};
|
||||
Assert.IsTrue(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
Assert.IsFalse(networkTransformState.HasScaleY);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.IsFalse(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
}
|
||||
}
|
||||
// SyncScaleZ
|
||||
if (syncScaZ)
|
||||
{
|
||||
networkTransform.SyncScaleZ = false;
|
||||
|
||||
scale.z++;
|
||||
networkTransform.transform.localScale = scale;
|
||||
|
||||
Assert.IsFalse(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
if (syncAxis != SyncAxis.SyncScaleZ && WillAnAxisBeSynchronized(ref networkTransform))
|
||||
{
|
||||
// We want to start with a fresh NetworkTransformState since it could have other state
|
||||
// information from the last time we applied the transform
|
||||
networkTransformState = new NetworkTransform.NetworkTransformState
|
||||
{
|
||||
InLocalSpace = inLocalSpace,
|
||||
IsTeleportingNextFrame = isTeleporting,
|
||||
};
|
||||
Assert.IsTrue(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
Assert.IsFalse(networkTransformState.HasScaleZ);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.IsFalse(networkTransform.ApplyTransformToNetworkState(ref networkTransformState, 0, networkTransform.transform));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Object.DestroyImmediate(gameObject);
|
||||
@@ -168,11 +513,11 @@ namespace Unity.Netcode.RuntimeTests
|
||||
|
||||
[Test]
|
||||
public void TestThresholds(
|
||||
[Values] bool inLocalSpace,
|
||||
[Values(NetworkTransform.PositionThresholdDefault, 1.0f)] float positionThreshold,
|
||||
[Values(NetworkTransform.RotAngleThresholdDefault, 1.0f)] float rotAngleThreshold,
|
||||
[Values(NetworkTransform.ScaleThresholdDefault, 0.5f)] float scaleThreshold)
|
||||
{
|
||||
var inLocalSpace = m_TransformSpace == TransformSpace.Local;
|
||||
var gameObject = new GameObject($"Test-{nameof(NetworkTransformStateTests)}.{nameof(TestThresholds)}");
|
||||
var networkTransform = gameObject.AddComponent<NetworkTransform>();
|
||||
networkTransform.enabled = false; // do not tick `FixedUpdate()` or `Update()`
|
||||
|
||||
@@ -189,7 +189,8 @@ namespace Unity.Netcode.RuntimeTests
|
||||
public enum OverrideState
|
||||
{
|
||||
Update,
|
||||
CommitToTransform
|
||||
CommitToTransform,
|
||||
SetState
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -299,9 +300,8 @@ namespace Unity.Netcode.RuntimeTests
|
||||
/// parented under another NetworkTransform
|
||||
/// </summary>
|
||||
[UnityTest]
|
||||
public IEnumerator NetworkTransformParentedLocalSpaceTest([Values] Interpolation interpolation, [Values] OverrideState overideState)
|
||||
public IEnumerator NetworkTransformParentedLocalSpaceTest([Values] Interpolation interpolation)
|
||||
{
|
||||
var overrideUpdate = overideState == OverrideState.CommitToTransform;
|
||||
m_AuthoritativeTransform.Interpolate = interpolation == Interpolation.EnableInterpolate;
|
||||
m_NonAuthoritativeTransform.Interpolate = interpolation == Interpolation.EnableInterpolate;
|
||||
var authoritativeChildObject = SpawnObject(m_ChildObjectToBeParented.gameObject, m_AuthoritativeTransform.NetworkManager);
|
||||
@@ -334,15 +334,28 @@ namespace Unity.Netcode.RuntimeTests
|
||||
/// Validates that moving, rotating, and scaling the authority side with a single
|
||||
/// tick will properly synchronize the non-authoritative side with the same values.
|
||||
/// </summary>
|
||||
private IEnumerator MoveRotateAndScaleAuthority(Vector3 position, Vector3 rotation, Vector3 scale)
|
||||
private IEnumerator MoveRotateAndScaleAuthority(Vector3 position, Vector3 rotation, Vector3 scale, OverrideState overrideState)
|
||||
{
|
||||
m_AuthoritativeTransform.transform.position = position;
|
||||
yield return null;
|
||||
var authoritativeRotation = m_AuthoritativeTransform.transform.rotation;
|
||||
authoritativeRotation.eulerAngles = rotation;
|
||||
m_AuthoritativeTransform.transform.rotation = authoritativeRotation;
|
||||
yield return null;
|
||||
m_AuthoritativeTransform.transform.localScale = scale;
|
||||
switch (overrideState)
|
||||
{
|
||||
case OverrideState.SetState:
|
||||
{
|
||||
m_AuthoritativeTransform.SetState(position, Quaternion.Euler(rotation), scale);
|
||||
break;
|
||||
}
|
||||
case OverrideState.Update:
|
||||
default:
|
||||
{
|
||||
m_AuthoritativeTransform.transform.position = position;
|
||||
yield return null;
|
||||
var authoritativeRotation = m_AuthoritativeTransform.transform.rotation;
|
||||
authoritativeRotation.eulerAngles = rotation;
|
||||
m_AuthoritativeTransform.transform.rotation = authoritativeRotation;
|
||||
yield return null;
|
||||
m_AuthoritativeTransform.transform.localScale = scale;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -400,7 +413,6 @@ namespace Unity.Netcode.RuntimeTests
|
||||
[UnityTest]
|
||||
public IEnumerator NetworkTransformMultipleChangesOverTime([Values] TransformSpace testLocalTransform, [Values] OverrideState overideState)
|
||||
{
|
||||
var overrideUpdate = overideState == OverrideState.CommitToTransform;
|
||||
m_AuthoritativeTransform.InLocalSpace = testLocalTransform == TransformSpace.Local;
|
||||
|
||||
var positionStart = new Vector3(1.0f, 0.5f, 2.0f);
|
||||
@@ -422,7 +434,7 @@ namespace Unity.Netcode.RuntimeTests
|
||||
yield return WaitForNextTick();
|
||||
|
||||
// Apply deltas
|
||||
MoveRotateAndScaleAuthority(position, rotation, scale);
|
||||
MoveRotateAndScaleAuthority(position, rotation, scale, overideState);
|
||||
|
||||
// Wait for deltas to synchronize on non-authoritative side
|
||||
yield return WaitForPositionRotationAndScaleToMatch(4);
|
||||
@@ -455,7 +467,7 @@ namespace Unity.Netcode.RuntimeTests
|
||||
// to apply both deltas within the same tick period.
|
||||
yield return WaitForNextTick();
|
||||
|
||||
MoveRotateAndScaleAuthority(position, rotation, scale);
|
||||
MoveRotateAndScaleAuthority(position, rotation, scale, overideState);
|
||||
yield return WaitForPositionRotationAndScaleToMatch(4);
|
||||
}
|
||||
|
||||
@@ -471,7 +483,7 @@ namespace Unity.Netcode.RuntimeTests
|
||||
rotation = rotationStart * i;
|
||||
scale = scaleStart * i;
|
||||
|
||||
MoveRotateAndScaleAuthority(position, rotation, scale);
|
||||
MoveRotateAndScaleAuthority(position, rotation, scale, overideState);
|
||||
}
|
||||
|
||||
yield return WaitForPositionRotationAndScaleToMatch(1);
|
||||
@@ -486,7 +498,7 @@ namespace Unity.Netcode.RuntimeTests
|
||||
position = positionStart * i;
|
||||
rotation = rotationStart * i;
|
||||
scale = scaleStart * i;
|
||||
MoveRotateAndScaleAuthority(position, rotation, scale);
|
||||
MoveRotateAndScaleAuthority(position, rotation, scale, overideState);
|
||||
}
|
||||
yield return WaitForPositionRotationAndScaleToMatch(1);
|
||||
}
|
||||
@@ -513,11 +525,16 @@ namespace Unity.Netcode.RuntimeTests
|
||||
|
||||
Assert.AreEqual(Vector3.zero, m_NonAuthoritativeTransform.transform.position, "server side pos should be zero at first"); // sanity check
|
||||
|
||||
authPlayerTransform.position = new Vector3(10, 20, 30);
|
||||
if (overrideUpdate)
|
||||
var nextPosition = new Vector3(10, 20, 30);
|
||||
if (overideState != OverrideState.SetState)
|
||||
{
|
||||
authPlayerTransform.position = nextPosition;
|
||||
m_OwnerTransform.CommitToTransform();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_OwnerTransform.SetState(nextPosition, null, null, m_AuthoritativeTransform.Interpolate);
|
||||
}
|
||||
|
||||
yield return WaitForConditionOrTimeOut(PositionsMatch);
|
||||
AssertOnTimeout($"Timed out waiting for positions to match");
|
||||
@@ -525,20 +542,30 @@ namespace Unity.Netcode.RuntimeTests
|
||||
// test rotation
|
||||
Assert.AreEqual(Quaternion.identity, m_NonAuthoritativeTransform.transform.rotation, "wrong initial value for rotation"); // sanity check
|
||||
|
||||
authPlayerTransform.rotation = Quaternion.Euler(45, 40, 35); // using euler angles instead of quaternions directly to really see issues users might encounter
|
||||
if (overrideUpdate)
|
||||
var nextRotation = Quaternion.Euler(45, 40, 35); // using euler angles instead of quaternions directly to really see issues users might encounter
|
||||
if (overideState != OverrideState.SetState)
|
||||
{
|
||||
authPlayerTransform.rotation = nextRotation;
|
||||
m_OwnerTransform.CommitToTransform();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_OwnerTransform.SetState(null, nextRotation, null, m_AuthoritativeTransform.Interpolate);
|
||||
}
|
||||
|
||||
yield return WaitForConditionOrTimeOut(RotationsMatch);
|
||||
AssertOnTimeout($"Timed out waiting for rotations to match");
|
||||
|
||||
authPlayerTransform.localScale = new Vector3(2, 3, 4);
|
||||
var nextScale = new Vector3(2, 3, 4);
|
||||
if (overrideUpdate)
|
||||
{
|
||||
authPlayerTransform.localScale = nextScale;
|
||||
m_OwnerTransform.CommitToTransform();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_OwnerTransform.SetState(null, null, nextScale, m_AuthoritativeTransform.Interpolate);
|
||||
}
|
||||
|
||||
yield return WaitForConditionOrTimeOut(ScaleValuesMatch);
|
||||
AssertOnTimeout($"Timed out waiting for scale values to match");
|
||||
|
||||
Reference in New Issue
Block a user