com.unity.netcode.gameobjects@1.9.1
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.9.1] - 2024-04-18 ### Added - Added AnticipatedNetworkVariable<T>, which adds support for client anticipation of NetworkVariable values, allowing for more responsive gameplay (#2820) - Added AnticipatedNetworkTransform, which adds support for client anticipation of NetworkTransforms (#2820) - Added NetworkVariableBase.ExceedsDirtinessThreshold to allow network variables to throttle updates by only sending updates when the difference between the current and previous values exceeds a threshold. (This is exposed in NetworkVariable<T> with the callback NetworkVariable<T>.CheckExceedsDirtinessThreshold) (#2820) - Added NetworkVariableUpdateTraits, which add additional throttling support: MinSecondsBetweenUpdates will prevent the NetworkVariable from sending updates more often than the specified time period (even if it exceeds the dirtiness threshold), while MaxSecondsBetweenUpdates will force a dirty NetworkVariable to send an update after the specified time period even if it has not yet exceeded the dirtiness threshold. (#2820) - Added virtual method NetworkVariableBase.OnInitialize() which can be used by NetworkVariable subclasses to add initialization code (#2820) - Added virtual method NetworkVariableBase.Update(), which is called once per frame to support behaviors such as interpolation between an anticipated value and an authoritative one. (#2820) - Added NetworkTime.TickWithPartial, which represents the current tick as a double that includes the fractional/partial tick value. (#2820) - Added NetworkTickSystem.AnticipationTick, which can be helpful with implementation of client anticipation. This value represents the tick the current local client was at at the beginning of the most recent network round trip, which enables it to correlate server update ticks with the client tick that may have triggered them. (#2820) - `NetworkVariable` now includes built-in support for `NativeHashSet`, `NativeHashMap`, `List`, `HashSet`, and `Dictionary` (#2813) - `NetworkVariable` now includes delta compression for collection values (`NativeList`, `NativeArray`, `NativeHashSet`, `NativeHashMap`, `List`, `HashSet`, `Dictionary`, and `FixedString` types) to save bandwidth by only sending the values that changed. (Note: For `NativeList`, `NativeArray`, and `List`, this algorithm works differently than that used in `NetworkList`. This algorithm will use less bandwidth for "set" and "add" operations, but `NetworkList` is more bandwidth-efficient if you are performing frequent "insert" operations.) (#2813) - `UserNetworkVariableSerialization` now has optional callbacks for `WriteDelta` and `ReadDelta`. If both are provided, they will be used for all serialization operations on NetworkVariables of that type except for the first one for each client. If either is missing, the existing `Write` and `Read` will always be used. (#2813) - Network variables wrapping `INetworkSerializable` types can perform delta serialization by setting `UserNetworkVariableSerialization<T>.WriteDelta` and `UserNetworkVariableSerialization<T>.ReadDelta` for those types. The built-in `INetworkSerializable` serializer will continue to be used for all other serialization operations, but if those callbacks are set, it will call into them on all but the initial serialization to perform delta serialization. (This could be useful if you have a large struct where most values do not change regularly and you want to send only the fields that did change.) (#2813) ### Fixed - Fixed issue where NetworkTransformEditor would throw and exception if you excluded the physics package. (#2871) - Fixed issue where `NetworkTransform` could not properly synchronize its base position when using half float precision. (#2845) - Fixed issue where the host was not invoking `OnClientDisconnectCallback` for its own local client when internally shutting down. (#2822) - Fixed issue where NetworkTransform could potentially attempt to "unregister" a named message prior to it being registered. (#2807) - Fixed issue where in-scene placed `NetworkObject`s with complex nested children `NetworkObject`s (more than one child in depth) would not synchronize properly if WorldPositionStays was set to true. (#2796) ### Changed - Changed `NetworkObjectReference` and `NetworkBehaviourReference` to allow null references when constructing and serializing. (#2874) - Changed `NetworkAnimator` no longer requires the `Animator` component to exist on the same `GameObject`. (#2872) - Changed `NetworkTransform` to now use `NetworkTransformMessage` as opposed to named messages for NetworkTransformState updates. (#2810) - Changed `CustomMessageManager` so it no longer attempts to register or "unregister" a null or empty string and will log an error if this condition occurs. (#2807)
This commit is contained in:
@@ -90,11 +90,16 @@ namespace Unity.Netcode.EditorTests
|
||||
break;
|
||||
}
|
||||
case TypeOfCorruption.CorruptBytes:
|
||||
batchData.Seek(batchData.Length - 2);
|
||||
var currentByte = batchData.GetUnsafePtr()[0];
|
||||
batchData.WriteByteSafe((byte)(currentByte == 0 ? 1 : 0));
|
||||
MessageQueue.Add(batchData.ToArray());
|
||||
break;
|
||||
{
|
||||
batchData.Seek(batchData.Length - 4);
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
var currentByte = batchData.GetUnsafePtr()[i];
|
||||
batchData.WriteByteSafe((byte)(currentByte == 0 ? 1 : 0));
|
||||
MessageQueue.Add(batchData.ToArray());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TypeOfCorruption.Truncated:
|
||||
batchData.Truncate(batchData.Length - 1);
|
||||
MessageQueue.Add(batchData.ToArray());
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Unity.Netcode.TestHelpers.Runtime;
|
||||
@@ -37,7 +38,10 @@ namespace Unity.Netcode.RuntimeTests
|
||||
protected override int NumberOfClients => 1;
|
||||
|
||||
private OwnerPersistence m_OwnerPersistence;
|
||||
private ClientDisconnectType m_ClientDisconnectType;
|
||||
private bool m_ClientDisconnected;
|
||||
private Dictionary<NetworkManager, ConnectionEventData> m_DisconnectedEvent = new Dictionary<NetworkManager, ConnectionEventData>();
|
||||
private ulong m_DisconnectEventClientId;
|
||||
private ulong m_TransportClientId;
|
||||
private ulong m_ClientId;
|
||||
|
||||
@@ -89,6 +93,16 @@ namespace Unity.Netcode.RuntimeTests
|
||||
m_ClientDisconnected = true;
|
||||
}
|
||||
|
||||
private void OnConnectionEvent(NetworkManager networkManager, ConnectionEventData connectionEventData)
|
||||
{
|
||||
if (connectionEventData.EventType != ConnectionEvent.ClientDisconnected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_DisconnectedEvent.Add(networkManager, connectionEventData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Conditional check to assure the transport to client (and vice versa) mappings are cleaned up
|
||||
/// </summary>
|
||||
@@ -126,19 +140,26 @@ namespace Unity.Netcode.RuntimeTests
|
||||
public IEnumerator ClientPlayerDisconnected([Values] ClientDisconnectType clientDisconnectType)
|
||||
{
|
||||
m_ClientId = m_ClientNetworkManagers[0].LocalClientId;
|
||||
m_ClientDisconnectType = clientDisconnectType;
|
||||
|
||||
var serverSideClientPlayer = m_ServerNetworkManager.ConnectionManager.ConnectedClients[m_ClientId].PlayerObject;
|
||||
|
||||
m_TransportClientId = m_ServerNetworkManager.ConnectionManager.ClientIdToTransportId(m_ClientId);
|
||||
|
||||
var clientManager = m_ClientNetworkManagers[0];
|
||||
|
||||
if (clientDisconnectType == ClientDisconnectType.ServerDisconnectsClient)
|
||||
{
|
||||
m_ClientNetworkManagers[0].OnClientDisconnectCallback += OnClientDisconnectCallback;
|
||||
m_ClientNetworkManagers[0].OnConnectionEvent += OnConnectionEvent;
|
||||
m_ServerNetworkManager.OnConnectionEvent += OnConnectionEvent;
|
||||
m_ServerNetworkManager.DisconnectClient(m_ClientId);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ServerNetworkManager.OnClientDisconnectCallback += OnClientDisconnectCallback;
|
||||
m_ServerNetworkManager.OnConnectionEvent += OnConnectionEvent;
|
||||
m_ClientNetworkManagers[0].OnConnectionEvent += OnConnectionEvent;
|
||||
|
||||
yield return StopOneClient(m_ClientNetworkManagers[0]);
|
||||
}
|
||||
@@ -146,6 +167,23 @@ namespace Unity.Netcode.RuntimeTests
|
||||
yield return WaitForConditionOrTimeOut(() => m_ClientDisconnected);
|
||||
AssertOnTimeout("Timed out waiting for client to disconnect!");
|
||||
|
||||
if (clientDisconnectType == ClientDisconnectType.ServerDisconnectsClient)
|
||||
{
|
||||
Assert.IsTrue(m_DisconnectedEvent.ContainsKey(m_ServerNetworkManager), $"Could not find the server {nameof(NetworkManager)} disconnect event entry!");
|
||||
Assert.IsTrue(m_DisconnectedEvent[m_ServerNetworkManager].ClientId == m_ClientId, $"Expected ClientID {m_ClientId} but found ClientID {m_DisconnectedEvent[m_ServerNetworkManager].ClientId} for the server {nameof(NetworkManager)} disconnect event entry!");
|
||||
Assert.IsTrue(m_DisconnectedEvent.ContainsKey(clientManager), $"Could not find the client {nameof(NetworkManager)} disconnect event entry!");
|
||||
Assert.IsTrue(m_DisconnectedEvent[clientManager].ClientId == m_ClientId, $"Expected ClientID {m_ClientId} but found ClientID {m_DisconnectedEvent[m_ServerNetworkManager].ClientId} for the client {nameof(NetworkManager)} disconnect event entry!");
|
||||
// Unregister for this event otherwise it will be invoked during teardown
|
||||
m_ServerNetworkManager.OnConnectionEvent -= OnConnectionEvent;
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.IsTrue(m_DisconnectedEvent.ContainsKey(m_ServerNetworkManager), $"Could not find the server {nameof(NetworkManager)} disconnect event entry!");
|
||||
Assert.IsTrue(m_DisconnectedEvent[m_ServerNetworkManager].ClientId == m_ClientId, $"Expected ClientID {m_ClientId} but found ClientID {m_DisconnectedEvent[m_ServerNetworkManager].ClientId} for the server {nameof(NetworkManager)} disconnect event entry!");
|
||||
Assert.IsTrue(m_DisconnectedEvent.ContainsKey(clientManager), $"Could not find the client {nameof(NetworkManager)} disconnect event entry!");
|
||||
Assert.IsTrue(m_DisconnectedEvent[clientManager].ClientId == m_ClientId, $"Expected ClientID {m_ClientId} but found ClientID {m_DisconnectedEvent[m_ServerNetworkManager].ClientId} for the client {nameof(NetworkManager)} disconnect event entry!");
|
||||
}
|
||||
|
||||
if (m_OwnerPersistence == OwnerPersistence.DestroyWithOwner)
|
||||
{
|
||||
// When we are destroying with the owner, validate the player object is destroyed on the server side
|
||||
@@ -161,6 +199,21 @@ namespace Unity.Netcode.RuntimeTests
|
||||
|
||||
yield return WaitForConditionOrTimeOut(TransportIdCleanedUp);
|
||||
AssertOnTimeout("Timed out waiting for transport and client id mappings to be cleaned up!");
|
||||
|
||||
// Validate the host-client generates a OnClientDisconnected event when it shutsdown.
|
||||
// Only test when the test run is the client disconnecting from the server (otherwise the server will be shutdown already)
|
||||
if (clientDisconnectType == ClientDisconnectType.ClientDisconnectsFromServer)
|
||||
{
|
||||
m_DisconnectedEvent.Clear();
|
||||
m_ClientDisconnected = false;
|
||||
m_ServerNetworkManager.Shutdown();
|
||||
|
||||
yield return WaitForConditionOrTimeOut(() => m_ClientDisconnected);
|
||||
AssertOnTimeout("Timed out waiting for host-client to generate disconnect message!");
|
||||
|
||||
Assert.IsTrue(m_DisconnectedEvent.ContainsKey(m_ServerNetworkManager), $"Could not find the server {nameof(NetworkManager)} disconnect event entry!");
|
||||
Assert.IsTrue(m_DisconnectedEvent[m_ServerNetworkManager].ClientId == NetworkManager.ServerClientId, $"Expected ClientID {m_ClientId} but found ClientID {m_DisconnectedEvent[m_ServerNetworkManager].ClientId} for the server {nameof(NetworkManager)} disconnect event entry!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +86,24 @@ namespace Unity.Netcode.RuntimeTests
|
||||
Assert.AreEqual(m_ServerNetworkManager.LocalClientId, receivedMessageSender);
|
||||
}
|
||||
|
||||
private void MockNamedMessageCallback(ulong sender, FastBufferReader reader)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NullOrEmptyNamedMessageDoesNotThrowException()
|
||||
{
|
||||
LogAssert.Expect(UnityEngine.LogType.Error, $"[{nameof(CustomMessagingManager.RegisterNamedMessageHandler)}] Cannot register a named message of type null or empty!");
|
||||
m_ServerNetworkManager.CustomMessagingManager.RegisterNamedMessageHandler(string.Empty, MockNamedMessageCallback);
|
||||
LogAssert.Expect(UnityEngine.LogType.Error, $"[{nameof(CustomMessagingManager.RegisterNamedMessageHandler)}] Cannot register a named message of type null or empty!");
|
||||
m_ServerNetworkManager.CustomMessagingManager.RegisterNamedMessageHandler(null, MockNamedMessageCallback);
|
||||
LogAssert.Expect(UnityEngine.LogType.Error, $"[{nameof(CustomMessagingManager.UnregisterNamedMessageHandler)}] Cannot unregister a named message of type null or empty!");
|
||||
m_ServerNetworkManager.CustomMessagingManager.UnregisterNamedMessageHandler(string.Empty);
|
||||
LogAssert.Expect(UnityEngine.LogType.Error, $"[{nameof(CustomMessagingManager.UnregisterNamedMessageHandler)}] Cannot unregister a named message of type null or empty!");
|
||||
m_ServerNetworkManager.CustomMessagingManager.UnregisterNamedMessageHandler(null);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator NamedMessageIsReceivedOnMultipleClientsWithContent()
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@ using NUnit.Framework;
|
||||
using Unity.Netcode.TestHelpers.Runtime;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace Unity.Netcode.RuntimeTests
|
||||
{
|
||||
@@ -35,7 +36,7 @@ namespace Unity.Netcode.RuntimeTests
|
||||
|
||||
m_ServerManager.OnServerStopped += onServerStopped;
|
||||
m_ServerManager.Shutdown();
|
||||
UnityEngine.Object.DestroyImmediate(gameObject);
|
||||
Object.DestroyImmediate(gameObject);
|
||||
|
||||
yield return WaitUntilManagerShutsdown();
|
||||
|
||||
@@ -92,7 +93,7 @@ namespace Unity.Netcode.RuntimeTests
|
||||
m_ServerManager.OnServerStopped += onServerStopped;
|
||||
m_ServerManager.OnClientStopped += onClientStopped;
|
||||
m_ServerManager.Shutdown();
|
||||
UnityEngine.Object.DestroyImmediate(gameObject);
|
||||
Object.DestroyImmediate(gameObject);
|
||||
|
||||
yield return WaitUntilManagerShutsdown();
|
||||
|
||||
@@ -228,6 +229,18 @@ namespace Unity.Netcode.RuntimeTests
|
||||
public virtual IEnumerator Teardown()
|
||||
{
|
||||
NetcodeIntegrationTestHelpers.Destroy();
|
||||
if (m_ServerManager != null)
|
||||
{
|
||||
m_ServerManager.ShutdownInternal();
|
||||
Object.DestroyImmediate(m_ServerManager);
|
||||
m_ServerManager = null;
|
||||
}
|
||||
if (m_ClientManager != null)
|
||||
{
|
||||
m_ClientManager.ShutdownInternal();
|
||||
Object.DestroyImmediate(m_ClientManager);
|
||||
m_ClientManager = null;
|
||||
}
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
// 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
|
||||
{
|
||||
@@ -38,32 +36,38 @@ namespace Unity.Netcode.RuntimeTests
|
||||
base(testWithHost, authority, rotationCompression, rotation, precision)
|
||||
{ }
|
||||
|
||||
protected override void OnServerAndClientsCreated()
|
||||
{
|
||||
base.OnServerAndClientsCreated();
|
||||
protected override bool m_EnableTimeTravel => true;
|
||||
protected override bool m_SetupIsACoroutine => true;
|
||||
protected override bool m_TearDownIsACoroutine => true;
|
||||
|
||||
var unityTransport = m_ServerNetworkManager.NetworkConfig.NetworkTransport as Transports.UTP.UnityTransport;
|
||||
unityTransport.SetDebugSimulatorParameters(k_Latency, 0, k_PacketLoss);
|
||||
protected override void OnTimeTravelServerAndClientsConnected()
|
||||
{
|
||||
base.OnTimeTravelServerAndClientsConnected();
|
||||
|
||||
SetTimeTravelSimulatedLatency(k_Latency * 0.001f);
|
||||
SetTimeTravelSimulatedDropRate(k_PacketLoss * 0.01f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles validating all children of the test objects have matching local and global space vaues.
|
||||
/// </summary>
|
||||
private IEnumerator AllChildrenLocalTransformValuesMatch(bool useSubChild, ChildrenTransformCheckType checkType)
|
||||
private void 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));
|
||||
WaitForConditionOrTimeOutWithTimeTravel(() => 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);
|
||||
//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++)
|
||||
{
|
||||
m_InfoMessage.Clear();
|
||||
m_InfoMessage.AppendLine($"[{checkType}][{useSubChild}] Timed out waiting for all children to have the correct local space values:\n");
|
||||
var instances = useSubChild ? ChildObjectComponent.SubInstances : ChildObjectComponent.Instances;
|
||||
success = PostAllChildrenLocalTransformValuesMatch(useSubChild);
|
||||
yield return waitForMs;
|
||||
TimeTravel(0.001f);
|
||||
//yield return waitForMs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,8 +82,8 @@ namespace Unity.Netcode.RuntimeTests
|
||||
/// 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)
|
||||
[Test]
|
||||
public void ParentedNetworkTransformTest([Values] Interpolation interpolation, [Values] bool worldPositionStays, [Values(0.5f, 1.0f, 5.0f)] float scale)
|
||||
{
|
||||
ChildObjectComponent.EnableChildLog = m_EnableVerboseDebug;
|
||||
if (m_EnableVerboseDebug)
|
||||
@@ -101,7 +105,7 @@ namespace Unity.Netcode.RuntimeTests
|
||||
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);
|
||||
WaitForConditionOrTimeOutWithTimeTravel(AllChildObjectInstancesAreSpawned);
|
||||
AssertOnTimeout("Timed out waiting for all child instances to be spawned!");
|
||||
|
||||
// Get the authority parent and child instances
|
||||
@@ -139,7 +143,7 @@ namespace Unity.Netcode.RuntimeTests
|
||||
|
||||
// Allow one tick for authority to update these changes
|
||||
|
||||
yield return WaitForConditionOrTimeOut(PositionRotationScaleMatches);
|
||||
WaitForConditionOrTimeOutWithTimeTravel(PositionRotationScaleMatches);
|
||||
|
||||
AssertOnTimeout("All transform values did not match prior to parenting!");
|
||||
|
||||
@@ -150,37 +154,37 @@ namespace Unity.Netcode.RuntimeTests
|
||||
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);
|
||||
WaitForConditionOrTimeOutWithTimeTravel(AllChildObjectInstancesHaveChild);
|
||||
AssertOnTimeout("Timed out waiting for all instances to have parented a child!");
|
||||
var latencyWait = new WaitForSeconds(k_Latency * 0.003f);
|
||||
var latencyWait = k_Latency * 0.003f;
|
||||
// Wait for at least 3x designated latency period
|
||||
yield return latencyWait;
|
||||
TimeTravel(latencyWait);
|
||||
|
||||
// This validates each child instance has preserved their local space values
|
||||
yield return AllChildrenLocalTransformValuesMatch(false, ChildrenTransformCheckType.Connected_Clients);
|
||||
AllChildrenLocalTransformValuesMatch(false, ChildrenTransformCheckType.Connected_Clients);
|
||||
|
||||
// This validates each sub-child instance has preserved their local space values
|
||||
yield return AllChildrenLocalTransformValuesMatch(true, ChildrenTransformCheckType.Connected_Clients);
|
||||
AllChildrenLocalTransformValuesMatch(true, ChildrenTransformCheckType.Connected_Clients);
|
||||
|
||||
// Verify that a late joining client will synchronize to the parented NetworkObjects properly
|
||||
yield return CreateAndStartNewClient();
|
||||
CreateAndStartNewClientWithTimeTravel();
|
||||
|
||||
// Assure all of the child object instances are spawned (basically for the newly connected client)
|
||||
yield return WaitForConditionOrTimeOut(AllChildObjectInstancesAreSpawned);
|
||||
WaitForConditionOrTimeOutWithTimeTravel(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);
|
||||
WaitForConditionOrTimeOutWithTimeTravel(AllChildObjectInstancesHaveChild);
|
||||
AssertOnTimeout("Timed out waiting for all instances to have parented a child!");
|
||||
|
||||
// Wait for at least 3x designated latency period
|
||||
yield return latencyWait;
|
||||
TimeTravel(latencyWait);
|
||||
|
||||
// This validates each child instance has preserved their local space values
|
||||
yield return AllChildrenLocalTransformValuesMatch(false, ChildrenTransformCheckType.Late_Join_Client);
|
||||
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);
|
||||
AllChildrenLocalTransformValuesMatch(true, ChildrenTransformCheckType.Late_Join_Client);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -192,10 +196,10 @@ namespace Unity.Netcode.RuntimeTests
|
||||
/// 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)
|
||||
[Test]
|
||||
public void NetworkTransformMultipleChangesOverTime([Values] TransformSpace testLocalTransform, [Values] Axis axis)
|
||||
{
|
||||
yield return s_DefaultWaitForTick;
|
||||
TimeTravelAdvanceTick();
|
||||
// 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);
|
||||
@@ -255,7 +259,7 @@ namespace Unity.Netcode.RuntimeTests
|
||||
|
||||
|
||||
// Wait for the deltas to be pushed
|
||||
yield return WaitForConditionOrTimeOut(() => m_AuthoritativeTransform.StatePushed);
|
||||
WaitForConditionOrTimeOutWithTimeTravel(() => m_AuthoritativeTransform.StatePushed);
|
||||
|
||||
// Just in case we drop the first few state updates
|
||||
if (s_GlobalTimeoutHelper.TimedOut)
|
||||
@@ -266,17 +270,17 @@ namespace Unity.Netcode.RuntimeTests
|
||||
state.InLocalSpace = !m_AuthoritativeTransform.InLocalSpace;
|
||||
m_AuthoritativeTransform.LocalAuthoritativeNetworkState = state;
|
||||
// Wait for the deltas to be pushed
|
||||
yield return WaitForConditionOrTimeOut(() => m_AuthoritativeTransform.StatePushed);
|
||||
WaitForConditionOrTimeOutWithTimeTravel(() => 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;
|
||||
TimeTravelAdvanceTick();
|
||||
TimeTravelAdvanceTick();
|
||||
TimeTravelAdvanceTick();
|
||||
TimeTravelAdvanceTick();
|
||||
TimeTravelAdvanceTick();
|
||||
var iterations = axisCount == 3 ? k_PositionRotationScaleIterations3Axis : k_PositionRotationScaleIterations;
|
||||
|
||||
// Move and rotate within the same tick, validate the non-authoritative instance updates
|
||||
@@ -311,7 +315,7 @@ namespace Unity.Netcode.RuntimeTests
|
||||
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);
|
||||
WaitForConditionOrTimeOutWithTimeTravel(() => 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.
|
||||
@@ -321,7 +325,7 @@ namespace Unity.Netcode.RuntimeTests
|
||||
if (m_AxisExcluded || axisCount < 3)
|
||||
{
|
||||
// Wait for deltas to synchronize on non-authoritative side
|
||||
yield return WaitForConditionOrTimeOut(PositionRotationScaleMatches);
|
||||
WaitForConditionOrTimeOutWithTimeTravel(PositionRotationScaleMatches);
|
||||
// Provide additional debug info about what failed (if it fails)
|
||||
if (s_GlobalTimeoutHelper.TimedOut)
|
||||
{
|
||||
@@ -335,7 +339,7 @@ namespace Unity.Netcode.RuntimeTests
|
||||
// If we matched, then something was dropped and recovered when synchronized
|
||||
break;
|
||||
}
|
||||
yield return s_DefaultWaitForTick;
|
||||
TimeTravelAdvanceTick();
|
||||
}
|
||||
|
||||
// Only if we still didn't match
|
||||
@@ -354,7 +358,7 @@ namespace Unity.Netcode.RuntimeTests
|
||||
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);
|
||||
WaitForConditionOrTimeOutWithTimeTravel(PositionRotationScaleMatches);
|
||||
// Provide additional debug info about what failed (if it fails)
|
||||
if (s_GlobalTimeoutHelper.TimedOut)
|
||||
{
|
||||
@@ -368,7 +372,7 @@ namespace Unity.Netcode.RuntimeTests
|
||||
// If we matched, then something was dropped and recovered when synchronized
|
||||
break;
|
||||
}
|
||||
yield return s_DefaultWaitForTick;
|
||||
TimeTravelAdvanceTick();
|
||||
}
|
||||
|
||||
// Only if we still didn't match
|
||||
@@ -392,8 +396,8 @@ namespace Unity.Netcode.RuntimeTests
|
||||
/// - While in local space and world space
|
||||
/// - While interpolation is enabled and disabled
|
||||
/// </summary>
|
||||
[UnityTest]
|
||||
public IEnumerator TestAuthoritativeTransformChangeOneAtATime([Values] TransformSpace testLocalTransform, [Values] Interpolation interpolation)
|
||||
[Test]
|
||||
public void 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;
|
||||
@@ -411,7 +415,7 @@ namespace Unity.Netcode.RuntimeTests
|
||||
|
||||
m_AuthoritativeTransform.transform.position = GetRandomVector3(2f, 30f);
|
||||
|
||||
yield return WaitForConditionOrTimeOut(() => PositionsMatch());
|
||||
WaitForConditionOrTimeOutWithTimeTravel(() => PositionsMatch());
|
||||
AssertOnTimeout($"Timed out waiting for positions to match {m_AuthoritativeTransform.transform.position} | {m_NonAuthoritativeTransform.transform.position}");
|
||||
|
||||
// test rotation
|
||||
@@ -420,19 +424,19 @@ namespace Unity.Netcode.RuntimeTests
|
||||
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());
|
||||
WaitForConditionOrTimeOutWithTimeTravel(() => 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());
|
||||
WaitForConditionOrTimeOutWithTimeTravel(() => ScaleValuesMatch());
|
||||
AssertOnTimeout($"Timed out waiting for scale values to match");
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator TestSameFrameDeltaStateAndTeleport([Values] TransformSpace testLocalTransform, [Values] Interpolation interpolation)
|
||||
[Test]
|
||||
public void TestSameFrameDeltaStateAndTeleport([Values] TransformSpace testLocalTransform, [Values] Interpolation interpolation)
|
||||
{
|
||||
m_AuthoritativeTransform.Interpolate = interpolation == Interpolation.EnableInterpolate;
|
||||
|
||||
@@ -449,10 +453,10 @@ namespace Unity.Netcode.RuntimeTests
|
||||
m_RandomPosition = GetRandomVector3(2f, 30f);
|
||||
m_AuthoritativeTransform.transform.position = m_RandomPosition;
|
||||
m_Teleported = false;
|
||||
yield return WaitForConditionOrTimeOut(() => m_Teleported);
|
||||
WaitForConditionOrTimeOutWithTimeTravel(() => m_Teleported);
|
||||
AssertOnTimeout($"Timed out waiting for random position to be pushed!");
|
||||
|
||||
yield return WaitForConditionOrTimeOut(() => PositionsMatch());
|
||||
WaitForConditionOrTimeOutWithTimeTravel(() => PositionsMatch());
|
||||
AssertOnTimeout($"Timed out waiting for positions to match {m_AuthoritativeTransform.transform.position} | {m_NonAuthoritativeTransform.transform.position}");
|
||||
|
||||
var authPosition = m_AuthoritativeTransform.GetSpaceRelativePosition();
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Collections;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -41,6 +42,24 @@ namespace Unity.Netcode.RuntimeTests
|
||||
return k_TickRate;
|
||||
}
|
||||
|
||||
private bool m_UseParentingThreshold;
|
||||
private const float k_ParentingThreshold = 0.25f;
|
||||
|
||||
protected override float GetDeltaVarianceThreshold()
|
||||
{
|
||||
if (m_UseParentingThreshold)
|
||||
{
|
||||
return k_ParentingThreshold;
|
||||
}
|
||||
return base.GetDeltaVarianceThreshold();
|
||||
}
|
||||
|
||||
protected override IEnumerator OnSetup()
|
||||
{
|
||||
m_UseParentingThreshold = false;
|
||||
return base.OnSetup();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles validating the local space values match the original local space values.
|
||||
/// If not, it generates a message containing the axial values that did not match
|
||||
@@ -77,6 +96,7 @@ namespace Unity.Netcode.RuntimeTests
|
||||
[Test]
|
||||
public void ParentedNetworkTransformTest([Values] Interpolation interpolation, [Values] bool worldPositionStays, [Values(0.5f, 1.0f, 5.0f)] float scale)
|
||||
{
|
||||
m_UseParentingThreshold = true;
|
||||
// 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;
|
||||
|
||||
521
Tests/Runtime/NetworkTransformAnticipationTests.cs
Normal file
521
Tests/Runtime/NetworkTransformAnticipationTests.cs
Normal file
@@ -0,0 +1,521 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Unity.Netcode.Components;
|
||||
using Unity.Netcode.TestHelpers.Runtime;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace Unity.Netcode.RuntimeTests
|
||||
{
|
||||
public class NetworkTransformAnticipationComponent : NetworkBehaviour
|
||||
{
|
||||
[Rpc(SendTo.Server)]
|
||||
public void MoveRpc(Vector3 newPosition)
|
||||
{
|
||||
transform.position = newPosition;
|
||||
}
|
||||
|
||||
[Rpc(SendTo.Server)]
|
||||
public void ScaleRpc(Vector3 newScale)
|
||||
{
|
||||
transform.localScale = newScale;
|
||||
}
|
||||
|
||||
[Rpc(SendTo.Server)]
|
||||
public void RotateRpc(Quaternion newRotation)
|
||||
{
|
||||
transform.rotation = newRotation;
|
||||
}
|
||||
|
||||
public bool ShouldSmooth = false;
|
||||
public bool ShouldMove = false;
|
||||
|
||||
public override void OnReanticipate(double lastRoundTripTime)
|
||||
{
|
||||
var transform_ = GetComponent<AnticipatedNetworkTransform>();
|
||||
if (transform_.ShouldReanticipate)
|
||||
{
|
||||
if (ShouldSmooth)
|
||||
{
|
||||
transform_.Smooth(transform_.PreviousAnticipatedState, transform_.AuthoritativeState, 1);
|
||||
}
|
||||
|
||||
if (ShouldMove)
|
||||
{
|
||||
transform_.AnticipateMove(transform_.AuthoritativeState.Position + new Vector3(0, 5, 0));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class NetworkTransformAnticipationTests : NetcodeIntegrationTest
|
||||
{
|
||||
protected override int NumberOfClients => 2;
|
||||
|
||||
protected override bool m_EnableTimeTravel => true;
|
||||
protected override bool m_SetupIsACoroutine => false;
|
||||
protected override bool m_TearDownIsACoroutine => false;
|
||||
|
||||
protected override void OnPlayerPrefabGameObjectCreated()
|
||||
{
|
||||
m_PlayerPrefab.AddComponent<AnticipatedNetworkTransform>();
|
||||
m_PlayerPrefab.AddComponent<NetworkTransformAnticipationComponent>();
|
||||
}
|
||||
|
||||
protected override void OnTimeTravelServerAndClientsConnected()
|
||||
{
|
||||
var serverComponent = GetServerComponent();
|
||||
var testComponent = GetTestComponent();
|
||||
var otherClientComponent = GetOtherClientComponent();
|
||||
|
||||
serverComponent.transform.position = Vector3.zero;
|
||||
serverComponent.transform.localScale = Vector3.one;
|
||||
serverComponent.transform.rotation = Quaternion.LookRotation(Vector3.forward);
|
||||
testComponent.transform.position = Vector3.zero;
|
||||
testComponent.transform.localScale = Vector3.one;
|
||||
testComponent.transform.rotation = Quaternion.LookRotation(Vector3.forward);
|
||||
otherClientComponent.transform.position = Vector3.zero;
|
||||
otherClientComponent.transform.localScale = Vector3.one;
|
||||
otherClientComponent.transform.rotation = Quaternion.LookRotation(Vector3.forward);
|
||||
}
|
||||
|
||||
public AnticipatedNetworkTransform GetTestComponent()
|
||||
{
|
||||
return m_ClientNetworkManagers[0].LocalClient.PlayerObject.GetComponent<AnticipatedNetworkTransform>();
|
||||
}
|
||||
|
||||
public AnticipatedNetworkTransform GetServerComponent()
|
||||
{
|
||||
foreach (var obj in Object.FindObjectsByType<AnticipatedNetworkTransform>(FindObjectsSortMode.None))
|
||||
{
|
||||
if (obj.NetworkManager == m_ServerNetworkManager && obj.OwnerClientId == m_ClientNetworkManagers[0].LocalClientId)
|
||||
{
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public AnticipatedNetworkTransform GetOtherClientComponent()
|
||||
{
|
||||
foreach (var obj in Object.FindObjectsByType<AnticipatedNetworkTransform>(FindObjectsSortMode.None))
|
||||
{
|
||||
if (obj.NetworkManager == m_ClientNetworkManagers[1] && obj.OwnerClientId == m_ClientNetworkManagers[0].LocalClientId)
|
||||
{
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenAnticipating_ValueChangesImmediately()
|
||||
{
|
||||
var testComponent = GetTestComponent();
|
||||
|
||||
testComponent.AnticipateMove(new Vector3(0, 1, 2));
|
||||
testComponent.AnticipateScale(new Vector3(1, 2, 3));
|
||||
testComponent.AnticipateRotate(Quaternion.LookRotation(new Vector3(2, 3, 4)));
|
||||
|
||||
Assert.AreEqual(new Vector3(0, 1, 2), testComponent.transform.position);
|
||||
Assert.AreEqual(new Vector3(1, 2, 3), testComponent.transform.localScale);
|
||||
Assert.AreEqual(Quaternion.LookRotation(new Vector3(2, 3, 4)), testComponent.transform.rotation);
|
||||
|
||||
Assert.AreEqual(new Vector3(0, 1, 2), testComponent.AnticipatedState.Position);
|
||||
Assert.AreEqual(new Vector3(1, 2, 3), testComponent.AnticipatedState.Scale);
|
||||
Assert.AreEqual(Quaternion.LookRotation(new Vector3(2, 3, 4)), testComponent.AnticipatedState.Rotation);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenAnticipating_AuthoritativeValueDoesNotChange()
|
||||
{
|
||||
var testComponent = GetTestComponent();
|
||||
|
||||
var startPosition = testComponent.transform.position;
|
||||
var startScale = testComponent.transform.localScale;
|
||||
var startRotation = testComponent.transform.rotation;
|
||||
|
||||
testComponent.AnticipateMove(new Vector3(0, 1, 2));
|
||||
testComponent.AnticipateScale(new Vector3(1, 2, 3));
|
||||
testComponent.AnticipateRotate(Quaternion.LookRotation(new Vector3(2, 3, 4)));
|
||||
|
||||
Assert.AreEqual(startPosition, testComponent.AuthoritativeState.Position);
|
||||
Assert.AreEqual(startScale, testComponent.AuthoritativeState.Scale);
|
||||
Assert.AreEqual(startRotation, testComponent.AuthoritativeState.Rotation);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenAnticipating_ServerDoesNotChange()
|
||||
{
|
||||
var testComponent = GetTestComponent();
|
||||
|
||||
var startPosition = testComponent.transform.position;
|
||||
var startScale = testComponent.transform.localScale;
|
||||
var startRotation = testComponent.transform.rotation;
|
||||
|
||||
testComponent.AnticipateMove(new Vector3(0, 1, 2));
|
||||
testComponent.AnticipateScale(new Vector3(1, 2, 3));
|
||||
testComponent.AnticipateRotate(Quaternion.LookRotation(new Vector3(2, 3, 4)));
|
||||
|
||||
var serverComponent = GetServerComponent();
|
||||
|
||||
Assert.AreEqual(startPosition, serverComponent.AuthoritativeState.Position);
|
||||
Assert.AreEqual(startScale, serverComponent.AuthoritativeState.Scale);
|
||||
Assert.AreEqual(startRotation, serverComponent.AuthoritativeState.Rotation);
|
||||
Assert.AreEqual(startPosition, serverComponent.AnticipatedState.Position);
|
||||
Assert.AreEqual(startScale, serverComponent.AnticipatedState.Scale);
|
||||
Assert.AreEqual(startRotation, serverComponent.AnticipatedState.Rotation);
|
||||
|
||||
TimeTravel(2, 120);
|
||||
|
||||
Assert.AreEqual(startPosition, serverComponent.AuthoritativeState.Position);
|
||||
Assert.AreEqual(startScale, serverComponent.AuthoritativeState.Scale);
|
||||
Assert.AreEqual(startRotation, serverComponent.AuthoritativeState.Rotation);
|
||||
Assert.AreEqual(startPosition, serverComponent.AnticipatedState.Position);
|
||||
Assert.AreEqual(startScale, serverComponent.AnticipatedState.Scale);
|
||||
Assert.AreEqual(startRotation, serverComponent.AnticipatedState.Rotation);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenAnticipating_OtherClientDoesNotChange()
|
||||
{
|
||||
var testComponent = GetTestComponent();
|
||||
|
||||
var startPosition = testComponent.transform.position;
|
||||
var startScale = testComponent.transform.localScale;
|
||||
var startRotation = testComponent.transform.rotation;
|
||||
|
||||
testComponent.AnticipateMove(new Vector3(0, 1, 2));
|
||||
testComponent.AnticipateScale(new Vector3(1, 2, 3));
|
||||
testComponent.AnticipateRotate(Quaternion.LookRotation(new Vector3(2, 3, 4)));
|
||||
|
||||
var otherClientComponent = GetOtherClientComponent();
|
||||
|
||||
Assert.AreEqual(startPosition, otherClientComponent.AuthoritativeState.Position);
|
||||
Assert.AreEqual(startScale, otherClientComponent.AuthoritativeState.Scale);
|
||||
Assert.AreEqual(startRotation, otherClientComponent.AuthoritativeState.Rotation);
|
||||
Assert.AreEqual(startPosition, otherClientComponent.AnticipatedState.Position);
|
||||
Assert.AreEqual(startScale, otherClientComponent.AnticipatedState.Scale);
|
||||
Assert.AreEqual(startRotation, otherClientComponent.AnticipatedState.Rotation);
|
||||
|
||||
TimeTravel(2, 120);
|
||||
|
||||
Assert.AreEqual(startPosition, otherClientComponent.AuthoritativeState.Position);
|
||||
Assert.AreEqual(startScale, otherClientComponent.AuthoritativeState.Scale);
|
||||
Assert.AreEqual(startRotation, otherClientComponent.AuthoritativeState.Rotation);
|
||||
Assert.AreEqual(startPosition, otherClientComponent.AnticipatedState.Position);
|
||||
Assert.AreEqual(startScale, otherClientComponent.AnticipatedState.Scale);
|
||||
Assert.AreEqual(startRotation, otherClientComponent.AnticipatedState.Rotation);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenServerChangesSnapValue_ValuesAreUpdated()
|
||||
{
|
||||
var testComponent = GetTestComponent();
|
||||
var serverComponent = GetServerComponent();
|
||||
serverComponent.Interpolate = false;
|
||||
|
||||
testComponent.AnticipateMove(new Vector3(0, 1, 2));
|
||||
testComponent.AnticipateScale(new Vector3(1, 2, 3));
|
||||
testComponent.AnticipateRotate(Quaternion.LookRotation(new Vector3(2, 3, 4)));
|
||||
|
||||
var rpcComponent = testComponent.GetComponent<NetworkTransformAnticipationComponent>();
|
||||
rpcComponent.MoveRpc(new Vector3(2, 3, 4));
|
||||
|
||||
WaitForMessageReceivedWithTimeTravel<RpcMessage>(new List<NetworkManager> { m_ServerNetworkManager });
|
||||
var otherClientComponent = GetOtherClientComponent();
|
||||
|
||||
WaitForConditionOrTimeOutWithTimeTravel(() => testComponent.AuthoritativeState.Position == serverComponent.transform.position && otherClientComponent.AuthoritativeState.Position == serverComponent.transform.position);
|
||||
|
||||
Assert.AreEqual(serverComponent.transform.position, testComponent.transform.position);
|
||||
Assert.AreEqual(serverComponent.transform.position, testComponent.AnticipatedState.Position);
|
||||
Assert.AreEqual(serverComponent.transform.position, testComponent.AuthoritativeState.Position);
|
||||
|
||||
Assert.AreEqual(serverComponent.transform.position, otherClientComponent.transform.position);
|
||||
Assert.AreEqual(serverComponent.transform.position, otherClientComponent.AnticipatedState.Position);
|
||||
Assert.AreEqual(serverComponent.transform.position, otherClientComponent.AuthoritativeState.Position);
|
||||
}
|
||||
|
||||
public void AssertQuaternionsAreEquivalent(Quaternion a, Quaternion b)
|
||||
{
|
||||
var aAngles = a.eulerAngles;
|
||||
var bAngles = b.eulerAngles;
|
||||
Assert.AreEqual(aAngles.x, bAngles.x, 0.001, $"Quaternions were not equal. Expected: {a}, but was {b}");
|
||||
Assert.AreEqual(aAngles.y, bAngles.y, 0.001, $"Quaternions were not equal. Expected: {a}, but was {b}");
|
||||
Assert.AreEqual(aAngles.z, bAngles.z, 0.001, $"Quaternions were not equal. Expected: {a}, but was {b}");
|
||||
}
|
||||
public void AssertVectorsAreEquivalent(Vector3 a, Vector3 b)
|
||||
{
|
||||
Assert.AreEqual(a.x, b.x, 0.001, $"Vectors were not equal. Expected: {a}, but was {b}");
|
||||
Assert.AreEqual(a.y, b.y, 0.001, $"Vectors were not equal. Expected: {a}, but was {b}");
|
||||
Assert.AreEqual(a.z, b.z, 0.001, $"Vectors were not equal. Expected: {a}, but was {b}");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenServerChangesSmoothValue_ValuesAreLerped()
|
||||
{
|
||||
var testComponent = GetTestComponent();
|
||||
var otherClientComponent = GetOtherClientComponent();
|
||||
|
||||
testComponent.StaleDataHandling = StaleDataHandling.Ignore;
|
||||
otherClientComponent.StaleDataHandling = StaleDataHandling.Ignore;
|
||||
|
||||
var serverComponent = GetServerComponent();
|
||||
serverComponent.Interpolate = false;
|
||||
|
||||
testComponent.GetComponent<NetworkTransformAnticipationComponent>().ShouldSmooth = true;
|
||||
otherClientComponent.GetComponent<NetworkTransformAnticipationComponent>().ShouldSmooth = true;
|
||||
|
||||
var startPosition = testComponent.transform.position;
|
||||
var startScale = testComponent.transform.localScale;
|
||||
var startRotation = testComponent.transform.rotation;
|
||||
var anticipePosition = new Vector3(0, 1, 2);
|
||||
var anticipeScale = new Vector3(1, 2, 3);
|
||||
var anticipeRotation = Quaternion.LookRotation(new Vector3(2, 3, 4));
|
||||
var serverSetPosition = new Vector3(3, 4, 5);
|
||||
var serverSetScale = new Vector3(4, 5, 6);
|
||||
var serverSetRotation = Quaternion.LookRotation(new Vector3(5, 6, 7));
|
||||
|
||||
testComponent.AnticipateMove(anticipePosition);
|
||||
testComponent.AnticipateScale(anticipeScale);
|
||||
testComponent.AnticipateRotate(anticipeRotation);
|
||||
|
||||
var rpcComponent = testComponent.GetComponent<NetworkTransformAnticipationComponent>();
|
||||
rpcComponent.MoveRpc(serverSetPosition);
|
||||
rpcComponent.RotateRpc(serverSetRotation);
|
||||
rpcComponent.ScaleRpc(serverSetScale);
|
||||
|
||||
WaitForMessagesReceivedWithTimeTravel(new List<Type>
|
||||
{
|
||||
typeof(RpcMessage),
|
||||
typeof(RpcMessage),
|
||||
typeof(RpcMessage),
|
||||
}, new List<NetworkManager> { m_ServerNetworkManager });
|
||||
|
||||
WaitForMessageReceivedWithTimeTravel<NetworkTransformMessage>(m_ClientNetworkManagers.ToList());
|
||||
|
||||
var percentChanged = 1f / 60f;
|
||||
|
||||
AssertVectorsAreEquivalent(Vector3.Lerp(anticipePosition, serverSetPosition, percentChanged), testComponent.transform.position);
|
||||
AssertVectorsAreEquivalent(Vector3.Lerp(anticipeScale, serverSetScale, percentChanged), testComponent.transform.localScale);
|
||||
AssertQuaternionsAreEquivalent(Quaternion.Slerp(anticipeRotation, serverSetRotation, percentChanged), testComponent.transform.rotation);
|
||||
|
||||
AssertVectorsAreEquivalent(Vector3.Lerp(anticipePosition, serverSetPosition, percentChanged), testComponent.AnticipatedState.Position);
|
||||
AssertVectorsAreEquivalent(Vector3.Lerp(anticipeScale, serverSetScale, percentChanged), testComponent.AnticipatedState.Scale);
|
||||
AssertQuaternionsAreEquivalent(Quaternion.Slerp(anticipeRotation, serverSetRotation, percentChanged), testComponent.AnticipatedState.Rotation);
|
||||
|
||||
AssertVectorsAreEquivalent(serverSetPosition, testComponent.AuthoritativeState.Position);
|
||||
AssertVectorsAreEquivalent(serverSetScale, testComponent.AuthoritativeState.Scale);
|
||||
AssertQuaternionsAreEquivalent(serverSetRotation, testComponent.AuthoritativeState.Rotation);
|
||||
|
||||
AssertVectorsAreEquivalent(Vector3.Lerp(startPosition, serverSetPosition, percentChanged), otherClientComponent.transform.position);
|
||||
AssertVectorsAreEquivalent(Vector3.Lerp(startScale, serverSetScale, percentChanged), otherClientComponent.transform.localScale);
|
||||
AssertQuaternionsAreEquivalent(Quaternion.Slerp(startRotation, serverSetRotation, percentChanged), otherClientComponent.transform.rotation);
|
||||
|
||||
AssertVectorsAreEquivalent(Vector3.Lerp(startPosition, serverSetPosition, percentChanged), otherClientComponent.AnticipatedState.Position);
|
||||
AssertVectorsAreEquivalent(Vector3.Lerp(startScale, serverSetScale, percentChanged), otherClientComponent.AnticipatedState.Scale);
|
||||
AssertQuaternionsAreEquivalent(Quaternion.Slerp(startRotation, serverSetRotation, percentChanged), otherClientComponent.AnticipatedState.Rotation);
|
||||
|
||||
AssertVectorsAreEquivalent(serverSetPosition, otherClientComponent.AuthoritativeState.Position);
|
||||
AssertVectorsAreEquivalent(serverSetScale, otherClientComponent.AuthoritativeState.Scale);
|
||||
AssertQuaternionsAreEquivalent(serverSetRotation, otherClientComponent.AuthoritativeState.Rotation);
|
||||
|
||||
for (var i = 1; i < 60; ++i)
|
||||
{
|
||||
TimeTravel(1f / 60f, 1);
|
||||
percentChanged = 1f / 60f * (i + 1);
|
||||
|
||||
AssertVectorsAreEquivalent(Vector3.Lerp(anticipePosition, serverSetPosition, percentChanged), testComponent.transform.position);
|
||||
AssertVectorsAreEquivalent(Vector3.Lerp(anticipeScale, serverSetScale, percentChanged), testComponent.transform.localScale);
|
||||
AssertQuaternionsAreEquivalent(Quaternion.Slerp(anticipeRotation, serverSetRotation, percentChanged), testComponent.transform.rotation);
|
||||
|
||||
AssertVectorsAreEquivalent(Vector3.Lerp(anticipePosition, serverSetPosition, percentChanged), testComponent.AnticipatedState.Position);
|
||||
AssertVectorsAreEquivalent(Vector3.Lerp(anticipeScale, serverSetScale, percentChanged), testComponent.AnticipatedState.Scale);
|
||||
AssertQuaternionsAreEquivalent(Quaternion.Slerp(anticipeRotation, serverSetRotation, percentChanged), testComponent.AnticipatedState.Rotation);
|
||||
|
||||
AssertVectorsAreEquivalent(serverSetPosition, testComponent.AuthoritativeState.Position);
|
||||
AssertVectorsAreEquivalent(serverSetScale, testComponent.AuthoritativeState.Scale);
|
||||
AssertQuaternionsAreEquivalent(serverSetRotation, testComponent.AuthoritativeState.Rotation);
|
||||
|
||||
AssertVectorsAreEquivalent(Vector3.Lerp(startPosition, serverSetPosition, percentChanged), otherClientComponent.transform.position);
|
||||
AssertVectorsAreEquivalent(Vector3.Lerp(startScale, serverSetScale, percentChanged), otherClientComponent.transform.localScale);
|
||||
AssertQuaternionsAreEquivalent(Quaternion.Slerp(startRotation, serverSetRotation, percentChanged), otherClientComponent.transform.rotation);
|
||||
|
||||
AssertVectorsAreEquivalent(Vector3.Lerp(startPosition, serverSetPosition, percentChanged), otherClientComponent.AnticipatedState.Position);
|
||||
AssertVectorsAreEquivalent(Vector3.Lerp(startScale, serverSetScale, percentChanged), otherClientComponent.AnticipatedState.Scale);
|
||||
AssertQuaternionsAreEquivalent(Quaternion.Slerp(startRotation, serverSetRotation, percentChanged), otherClientComponent.AnticipatedState.Rotation);
|
||||
|
||||
AssertVectorsAreEquivalent(serverSetPosition, otherClientComponent.AuthoritativeState.Position);
|
||||
AssertVectorsAreEquivalent(serverSetScale, otherClientComponent.AuthoritativeState.Scale);
|
||||
AssertQuaternionsAreEquivalent(serverSetRotation, otherClientComponent.AuthoritativeState.Rotation);
|
||||
}
|
||||
TimeTravel(1f / 60f, 1);
|
||||
|
||||
AssertVectorsAreEquivalent(serverSetPosition, testComponent.transform.position);
|
||||
AssertVectorsAreEquivalent(serverSetScale, testComponent.transform.localScale);
|
||||
AssertQuaternionsAreEquivalent(serverSetRotation, testComponent.transform.rotation);
|
||||
|
||||
AssertVectorsAreEquivalent(serverSetPosition, testComponent.AnticipatedState.Position);
|
||||
AssertVectorsAreEquivalent(serverSetScale, testComponent.AnticipatedState.Scale);
|
||||
AssertQuaternionsAreEquivalent(serverSetRotation, testComponent.AnticipatedState.Rotation);
|
||||
|
||||
AssertVectorsAreEquivalent(serverSetPosition, testComponent.AuthoritativeState.Position);
|
||||
AssertVectorsAreEquivalent(serverSetScale, testComponent.AuthoritativeState.Scale);
|
||||
AssertQuaternionsAreEquivalent(serverSetRotation, testComponent.AuthoritativeState.Rotation);
|
||||
|
||||
AssertVectorsAreEquivalent(serverSetPosition, otherClientComponent.transform.position);
|
||||
AssertVectorsAreEquivalent(serverSetScale, otherClientComponent.transform.localScale);
|
||||
AssertQuaternionsAreEquivalent(serverSetRotation, otherClientComponent.transform.rotation);
|
||||
|
||||
AssertVectorsAreEquivalent(serverSetPosition, otherClientComponent.AnticipatedState.Position);
|
||||
AssertVectorsAreEquivalent(serverSetScale, otherClientComponent.AnticipatedState.Scale);
|
||||
AssertQuaternionsAreEquivalent(serverSetRotation, otherClientComponent.AnticipatedState.Rotation);
|
||||
|
||||
AssertVectorsAreEquivalent(serverSetPosition, otherClientComponent.AuthoritativeState.Position);
|
||||
AssertVectorsAreEquivalent(serverSetScale, otherClientComponent.AuthoritativeState.Scale);
|
||||
AssertQuaternionsAreEquivalent(serverSetRotation, otherClientComponent.AuthoritativeState.Rotation);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenServerChangesReanticipeValue_ValuesAreReanticiped()
|
||||
{
|
||||
var testComponent = GetTestComponent();
|
||||
var otherClientComponent = GetOtherClientComponent();
|
||||
|
||||
testComponent.GetComponent<NetworkTransformAnticipationComponent>().ShouldMove = true;
|
||||
otherClientComponent.GetComponent<NetworkTransformAnticipationComponent>().ShouldMove = true;
|
||||
|
||||
var serverComponent = GetServerComponent();
|
||||
serverComponent.Interpolate = false;
|
||||
serverComponent.transform.position = new Vector3(0, 1, 2);
|
||||
var rpcComponent = testComponent.GetComponent<NetworkTransformAnticipationComponent>();
|
||||
rpcComponent.MoveRpc(new Vector3(0, 1, 2));
|
||||
|
||||
WaitForMessageReceivedWithTimeTravel<RpcMessage>(new List<NetworkManager> { m_ServerNetworkManager });
|
||||
|
||||
WaitForMessageReceivedWithTimeTravel<NetworkTransformMessage>(m_ClientNetworkManagers.ToList());
|
||||
|
||||
Assert.AreEqual(new Vector3(0, 6, 2), testComponent.transform.position);
|
||||
Assert.AreEqual(new Vector3(0, 6, 2), testComponent.AnticipatedState.Position);
|
||||
Assert.AreEqual(new Vector3(0, 1, 2), testComponent.AuthoritativeState.Position);
|
||||
|
||||
Assert.AreEqual(new Vector3(0, 6, 2), otherClientComponent.transform.position);
|
||||
Assert.AreEqual(new Vector3(0, 6, 2), otherClientComponent.AnticipatedState.Position);
|
||||
Assert.AreEqual(new Vector3(0, 1, 2), otherClientComponent.AuthoritativeState.Position);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenStaleDataArrivesToIgnoreVariable_ItIsIgnored([Values(10u, 30u, 60u)] uint tickRate, [Values(0u, 1u, 2u)] uint skipFrames)
|
||||
{
|
||||
m_ServerNetworkManager.NetworkConfig.TickRate = tickRate;
|
||||
m_ServerNetworkManager.NetworkTickSystem.TickRate = tickRate;
|
||||
|
||||
for (var i = 0; i < skipFrames; ++i)
|
||||
{
|
||||
TimeTravel(1 / 60f, 1);
|
||||
}
|
||||
|
||||
var serverComponent = GetServerComponent();
|
||||
serverComponent.Interpolate = false;
|
||||
|
||||
var testComponent = GetTestComponent();
|
||||
testComponent.StaleDataHandling = StaleDataHandling.Ignore;
|
||||
testComponent.Interpolate = false;
|
||||
|
||||
var otherClientComponent = GetOtherClientComponent();
|
||||
otherClientComponent.StaleDataHandling = StaleDataHandling.Ignore;
|
||||
otherClientComponent.Interpolate = false;
|
||||
|
||||
var rpcComponent = testComponent.GetComponent<NetworkTransformAnticipationComponent>();
|
||||
rpcComponent.MoveRpc(new Vector3(1, 2, 3));
|
||||
|
||||
WaitForMessageReceivedWithTimeTravel<RpcMessage>(new List<NetworkManager> { m_ServerNetworkManager });
|
||||
|
||||
testComponent.AnticipateMove(new Vector3(0, 5, 0));
|
||||
rpcComponent.MoveRpc(new Vector3(4, 5, 6));
|
||||
|
||||
// Depending on tick rate, one of these two things will happen.
|
||||
// The assertions are different based on this... either the tick rate is slow enough that the second RPC is received
|
||||
// before the next update and we move to 4, 5, 6, or the tick rate is fast enough that the next update is sent out
|
||||
// before the RPC is received and we get the update for the move to 1, 2, 3. Both are valid, what we want to assert
|
||||
// here is that the anticipated state never becomes 1, 2, 3.
|
||||
WaitForConditionOrTimeOutWithTimeTravel(() => testComponent.AuthoritativeState.Position == new Vector3(1, 2, 3) || testComponent.AuthoritativeState.Position == new Vector3(4, 5, 6));
|
||||
|
||||
if (testComponent.AnticipatedState.Position == new Vector3(4, 5, 6))
|
||||
{
|
||||
// Anticiped client received this data for a time earlier than its anticipation, and should have prioritized the anticiped value
|
||||
Assert.AreEqual(new Vector3(4, 5, 6), testComponent.transform.position);
|
||||
Assert.AreEqual(new Vector3(4, 5, 6), testComponent.AnticipatedState.Position);
|
||||
// However, the authoritative value still gets updated
|
||||
Assert.AreEqual(new Vector3(4, 5, 6), testComponent.AuthoritativeState.Position);
|
||||
|
||||
// Other client got the server value and had made no anticipation, so it applies it to the anticiped value as well.
|
||||
Assert.AreEqual(new Vector3(4, 5, 6), otherClientComponent.transform.position);
|
||||
Assert.AreEqual(new Vector3(4, 5, 6), otherClientComponent.AnticipatedState.Position);
|
||||
Assert.AreEqual(new Vector3(4, 5, 6), otherClientComponent.AuthoritativeState.Position);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Anticiped client received this data for a time earlier than its anticipation, and should have prioritized the anticiped value
|
||||
Assert.AreEqual(new Vector3(0, 5, 0), testComponent.transform.position);
|
||||
Assert.AreEqual(new Vector3(0, 5, 0), testComponent.AnticipatedState.Position);
|
||||
// However, the authoritative value still gets updated
|
||||
Assert.AreEqual(new Vector3(1, 2, 3), testComponent.AuthoritativeState.Position);
|
||||
|
||||
// Other client got the server value and had made no anticipation, so it applies it to the anticiped value as well.
|
||||
Assert.AreEqual(new Vector3(1, 2, 3), otherClientComponent.transform.position);
|
||||
Assert.AreEqual(new Vector3(1, 2, 3), otherClientComponent.AnticipatedState.Position);
|
||||
Assert.AreEqual(new Vector3(1, 2, 3), otherClientComponent.AuthoritativeState.Position);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void WhenNonStaleDataArrivesToIgnoreVariable_ItIsNotIgnored([Values(10u, 30u, 60u)] uint tickRate, [Values(0u, 1u, 2u)] uint skipFrames)
|
||||
{
|
||||
m_ServerNetworkManager.NetworkConfig.TickRate = tickRate;
|
||||
m_ServerNetworkManager.NetworkTickSystem.TickRate = tickRate;
|
||||
|
||||
for (var i = 0; i < skipFrames; ++i)
|
||||
{
|
||||
TimeTravel(1 / 60f, 1);
|
||||
}
|
||||
|
||||
var serverComponent = GetServerComponent();
|
||||
serverComponent.Interpolate = false;
|
||||
|
||||
var testComponent = GetTestComponent();
|
||||
testComponent.StaleDataHandling = StaleDataHandling.Ignore;
|
||||
testComponent.Interpolate = false;
|
||||
|
||||
var otherClientComponent = GetOtherClientComponent();
|
||||
otherClientComponent.StaleDataHandling = StaleDataHandling.Ignore;
|
||||
otherClientComponent.Interpolate = false;
|
||||
|
||||
testComponent.AnticipateMove(new Vector3(0, 5, 0));
|
||||
var rpcComponent = testComponent.GetComponent<NetworkTransformAnticipationComponent>();
|
||||
rpcComponent.MoveRpc(new Vector3(1, 2, 3));
|
||||
|
||||
WaitForMessageReceivedWithTimeTravel<RpcMessage>(new List<NetworkManager> { m_ServerNetworkManager });
|
||||
|
||||
WaitForConditionOrTimeOutWithTimeTravel(() => testComponent.AuthoritativeState.Position == serverComponent.transform.position && otherClientComponent.AuthoritativeState.Position == serverComponent.transform.position);
|
||||
|
||||
// Anticiped client received this data for a time earlier than its anticipation, and should have prioritized the anticiped value
|
||||
Assert.AreEqual(new Vector3(1, 2, 3), testComponent.transform.position);
|
||||
Assert.AreEqual(new Vector3(1, 2, 3), testComponent.AnticipatedState.Position);
|
||||
// However, the authoritative value still gets updated
|
||||
Assert.AreEqual(new Vector3(1, 2, 3), testComponent.AuthoritativeState.Position);
|
||||
|
||||
// Other client got the server value and had made no anticipation, so it applies it to the anticiped value as well.
|
||||
Assert.AreEqual(new Vector3(1, 2, 3), otherClientComponent.transform.position);
|
||||
Assert.AreEqual(new Vector3(1, 2, 3), otherClientComponent.AnticipatedState.Position);
|
||||
Assert.AreEqual(new Vector3(1, 2, 3), otherClientComponent.AuthoritativeState.Position);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Tests/Runtime/NetworkTransformAnticipationTests.cs.meta
Normal file
3
Tests/Runtime/NetworkTransformAnticipationTests.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f149de86bec4f6eb1a4d62a1b52938a
|
||||
timeCreated: 1706630210
|
||||
420
Tests/Runtime/NetworkVariableAnticipationTests.cs
Normal file
420
Tests/Runtime/NetworkVariableAnticipationTests.cs
Normal file
@@ -0,0 +1,420 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Unity.Netcode.TestHelpers.Runtime;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace Unity.Netcode.RuntimeTests
|
||||
{
|
||||
public class NetworkVariableAnticipationComponent : NetworkBehaviour
|
||||
{
|
||||
public AnticipatedNetworkVariable<int> SnapOnAnticipationFailVariable = new AnticipatedNetworkVariable<int>(0, StaleDataHandling.Ignore);
|
||||
public AnticipatedNetworkVariable<float> SmoothOnAnticipationFailVariable = new AnticipatedNetworkVariable<float>(0, StaleDataHandling.Reanticipate);
|
||||
public AnticipatedNetworkVariable<float> ReanticipateOnAnticipationFailVariable = new AnticipatedNetworkVariable<float>(0, StaleDataHandling.Reanticipate);
|
||||
|
||||
public override void OnReanticipate(double lastRoundTripTime)
|
||||
{
|
||||
if (SmoothOnAnticipationFailVariable.ShouldReanticipate)
|
||||
{
|
||||
if (Mathf.Abs(SmoothOnAnticipationFailVariable.AuthoritativeValue - SmoothOnAnticipationFailVariable.PreviousAnticipatedValue) > Mathf.Epsilon)
|
||||
{
|
||||
SmoothOnAnticipationFailVariable.Smooth(SmoothOnAnticipationFailVariable.PreviousAnticipatedValue, SmoothOnAnticipationFailVariable.AuthoritativeValue, 1, Mathf.Lerp);
|
||||
}
|
||||
}
|
||||
|
||||
if (ReanticipateOnAnticipationFailVariable.ShouldReanticipate)
|
||||
{
|
||||
// Would love to test some stuff about anticipation based on time, but that is difficult to test accurately.
|
||||
// This reanticipating variable will just always anticipate a value 5 higher than the server value.
|
||||
ReanticipateOnAnticipationFailVariable.Anticipate(ReanticipateOnAnticipationFailVariable.AuthoritativeValue + 5);
|
||||
}
|
||||
}
|
||||
|
||||
public bool SnapRpcResponseReceived = false;
|
||||
|
||||
[Rpc(SendTo.Server)]
|
||||
public void SetSnapValueRpc(int i, RpcParams rpcParams = default)
|
||||
{
|
||||
SnapOnAnticipationFailVariable.AuthoritativeValue = i;
|
||||
SetSnapValueResponseRpc(RpcTarget.Single(rpcParams.Receive.SenderClientId, RpcTargetUse.Temp));
|
||||
}
|
||||
|
||||
[Rpc(SendTo.SpecifiedInParams)]
|
||||
public void SetSnapValueResponseRpc(RpcParams rpcParams)
|
||||
{
|
||||
SnapRpcResponseReceived = true;
|
||||
}
|
||||
|
||||
[Rpc(SendTo.Server)]
|
||||
public void SetSmoothValueRpc(float f)
|
||||
{
|
||||
SmoothOnAnticipationFailVariable.AuthoritativeValue = f;
|
||||
}
|
||||
|
||||
[Rpc(SendTo.Server)]
|
||||
public void SetReanticipateValueRpc(float f)
|
||||
{
|
||||
ReanticipateOnAnticipationFailVariable.AuthoritativeValue = f;
|
||||
}
|
||||
}
|
||||
|
||||
public class NetworkVariableAnticipationTests : NetcodeIntegrationTest
|
||||
{
|
||||
protected override int NumberOfClients => 2;
|
||||
|
||||
protected override bool m_EnableTimeTravel => true;
|
||||
protected override bool m_SetupIsACoroutine => false;
|
||||
protected override bool m_TearDownIsACoroutine => false;
|
||||
|
||||
protected override void OnPlayerPrefabGameObjectCreated()
|
||||
{
|
||||
m_PlayerPrefab.AddComponent<NetworkVariableAnticipationComponent>();
|
||||
}
|
||||
|
||||
public NetworkVariableAnticipationComponent GetTestComponent()
|
||||
{
|
||||
return m_ClientNetworkManagers[0].LocalClient.PlayerObject.GetComponent<NetworkVariableAnticipationComponent>();
|
||||
}
|
||||
|
||||
public NetworkVariableAnticipationComponent GetServerComponent()
|
||||
{
|
||||
foreach (var obj in Object.FindObjectsByType<NetworkVariableAnticipationComponent>(FindObjectsSortMode.None))
|
||||
{
|
||||
if (obj.NetworkManager == m_ServerNetworkManager && obj.OwnerClientId == m_ClientNetworkManagers[0].LocalClientId)
|
||||
{
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public NetworkVariableAnticipationComponent GetOtherClientComponent()
|
||||
{
|
||||
foreach (var obj in Object.FindObjectsByType<NetworkVariableAnticipationComponent>(FindObjectsSortMode.None))
|
||||
{
|
||||
if (obj.NetworkManager == m_ClientNetworkManagers[1] && obj.OwnerClientId == m_ClientNetworkManagers[0].LocalClientId)
|
||||
{
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenAnticipating_ValueChangesImmediately()
|
||||
{
|
||||
var testComponent = GetTestComponent();
|
||||
|
||||
testComponent.SnapOnAnticipationFailVariable.Anticipate(10);
|
||||
testComponent.SmoothOnAnticipationFailVariable.Anticipate(15);
|
||||
testComponent.ReanticipateOnAnticipationFailVariable.Anticipate(20);
|
||||
|
||||
Assert.AreEqual(10, testComponent.SnapOnAnticipationFailVariable.Value);
|
||||
Assert.AreEqual(15, testComponent.SmoothOnAnticipationFailVariable.Value);
|
||||
Assert.AreEqual(20, testComponent.ReanticipateOnAnticipationFailVariable.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenAnticipating_AuthoritativeValueDoesNotChange()
|
||||
{
|
||||
var testComponent = GetTestComponent();
|
||||
|
||||
testComponent.SnapOnAnticipationFailVariable.Anticipate(10);
|
||||
testComponent.SmoothOnAnticipationFailVariable.Anticipate(15);
|
||||
testComponent.ReanticipateOnAnticipationFailVariable.Anticipate(20);
|
||||
|
||||
Assert.AreEqual(0, testComponent.SnapOnAnticipationFailVariable.AuthoritativeValue);
|
||||
Assert.AreEqual(0, testComponent.SmoothOnAnticipationFailVariable.AuthoritativeValue);
|
||||
Assert.AreEqual(0, testComponent.ReanticipateOnAnticipationFailVariable.AuthoritativeValue);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenAnticipating_ServerDoesNotChange()
|
||||
{
|
||||
var testComponent = GetTestComponent();
|
||||
|
||||
testComponent.SnapOnAnticipationFailVariable.Anticipate(10);
|
||||
testComponent.SmoothOnAnticipationFailVariable.Anticipate(15);
|
||||
testComponent.ReanticipateOnAnticipationFailVariable.Anticipate(20);
|
||||
|
||||
var serverComponent = GetServerComponent();
|
||||
|
||||
Assert.AreEqual(0, serverComponent.SnapOnAnticipationFailVariable.AuthoritativeValue);
|
||||
Assert.AreEqual(0, serverComponent.SmoothOnAnticipationFailVariable.AuthoritativeValue);
|
||||
Assert.AreEqual(0, serverComponent.ReanticipateOnAnticipationFailVariable.AuthoritativeValue);
|
||||
Assert.AreEqual(0, serverComponent.SnapOnAnticipationFailVariable.Value);
|
||||
Assert.AreEqual(0, serverComponent.SmoothOnAnticipationFailVariable.Value);
|
||||
Assert.AreEqual(0, serverComponent.ReanticipateOnAnticipationFailVariable.Value);
|
||||
|
||||
TimeTravel(2, 120);
|
||||
|
||||
Assert.AreEqual(0, serverComponent.SnapOnAnticipationFailVariable.AuthoritativeValue);
|
||||
Assert.AreEqual(0, serverComponent.SmoothOnAnticipationFailVariable.AuthoritativeValue);
|
||||
Assert.AreEqual(0, serverComponent.ReanticipateOnAnticipationFailVariable.AuthoritativeValue);
|
||||
Assert.AreEqual(0, serverComponent.SnapOnAnticipationFailVariable.Value);
|
||||
Assert.AreEqual(0, serverComponent.SmoothOnAnticipationFailVariable.Value);
|
||||
Assert.AreEqual(0, serverComponent.ReanticipateOnAnticipationFailVariable.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenAnticipating_OtherClientDoesNotChange()
|
||||
{
|
||||
var testComponent = GetTestComponent();
|
||||
|
||||
testComponent.SnapOnAnticipationFailVariable.Anticipate(10);
|
||||
testComponent.SmoothOnAnticipationFailVariable.Anticipate(15);
|
||||
testComponent.ReanticipateOnAnticipationFailVariable.Anticipate(20);
|
||||
|
||||
var otherClientComponent = GetOtherClientComponent();
|
||||
|
||||
Assert.AreEqual(0, otherClientComponent.SnapOnAnticipationFailVariable.AuthoritativeValue);
|
||||
Assert.AreEqual(0, otherClientComponent.SmoothOnAnticipationFailVariable.AuthoritativeValue);
|
||||
Assert.AreEqual(0, otherClientComponent.ReanticipateOnAnticipationFailVariable.AuthoritativeValue);
|
||||
Assert.AreEqual(0, otherClientComponent.SnapOnAnticipationFailVariable.Value);
|
||||
Assert.AreEqual(0, otherClientComponent.SmoothOnAnticipationFailVariable.Value);
|
||||
Assert.AreEqual(0, otherClientComponent.ReanticipateOnAnticipationFailVariable.Value);
|
||||
|
||||
TimeTravel(2, 120);
|
||||
|
||||
Assert.AreEqual(0, otherClientComponent.SnapOnAnticipationFailVariable.AuthoritativeValue);
|
||||
Assert.AreEqual(0, otherClientComponent.SmoothOnAnticipationFailVariable.AuthoritativeValue);
|
||||
Assert.AreEqual(0, otherClientComponent.ReanticipateOnAnticipationFailVariable.AuthoritativeValue);
|
||||
Assert.AreEqual(0, otherClientComponent.SnapOnAnticipationFailVariable.Value);
|
||||
Assert.AreEqual(0, otherClientComponent.SmoothOnAnticipationFailVariable.Value);
|
||||
Assert.AreEqual(0, otherClientComponent.ReanticipateOnAnticipationFailVariable.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenServerChangesSnapValue_ValuesAreUpdated()
|
||||
{
|
||||
var testComponent = GetTestComponent();
|
||||
|
||||
testComponent.SnapOnAnticipationFailVariable.Anticipate(10);
|
||||
|
||||
Assert.AreEqual(10, testComponent.SnapOnAnticipationFailVariable.Value);
|
||||
Assert.AreEqual(0, testComponent.SnapOnAnticipationFailVariable.AuthoritativeValue);
|
||||
|
||||
testComponent.SetSnapValueRpc(10);
|
||||
|
||||
WaitForMessageReceivedWithTimeTravel<RpcMessage>(
|
||||
new List<NetworkManager> { m_ServerNetworkManager }
|
||||
);
|
||||
|
||||
var serverComponent = GetServerComponent();
|
||||
Assert.AreEqual(10, serverComponent.SnapOnAnticipationFailVariable.Value);
|
||||
Assert.AreEqual(10, serverComponent.SnapOnAnticipationFailVariable.AuthoritativeValue);
|
||||
|
||||
var otherClientComponent = GetOtherClientComponent();
|
||||
Assert.AreEqual(0, otherClientComponent.SnapOnAnticipationFailVariable.Value);
|
||||
Assert.AreEqual(0, otherClientComponent.SnapOnAnticipationFailVariable.AuthoritativeValue);
|
||||
|
||||
WaitForMessageReceivedWithTimeTravel<NetworkVariableDeltaMessage>(m_ClientNetworkManagers.ToList());
|
||||
|
||||
Assert.AreEqual(10, testComponent.SnapOnAnticipationFailVariable.Value);
|
||||
Assert.AreEqual(10, testComponent.SnapOnAnticipationFailVariable.AuthoritativeValue);
|
||||
|
||||
Assert.AreEqual(10, otherClientComponent.SnapOnAnticipationFailVariable.Value);
|
||||
Assert.AreEqual(10, otherClientComponent.SnapOnAnticipationFailVariable.AuthoritativeValue);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenServerChangesSmoothValue_ValuesAreLerped()
|
||||
{
|
||||
var testComponent = GetTestComponent();
|
||||
|
||||
testComponent.SmoothOnAnticipationFailVariable.Anticipate(15);
|
||||
|
||||
Assert.AreEqual(15, testComponent.SmoothOnAnticipationFailVariable.Value, Mathf.Epsilon);
|
||||
Assert.AreEqual(0, testComponent.SmoothOnAnticipationFailVariable.AuthoritativeValue, Mathf.Epsilon);
|
||||
|
||||
// Set to a different value to simulate a anticipation failure - will lerp between the anticipated value
|
||||
// and the actual one
|
||||
testComponent.SetSmoothValueRpc(20);
|
||||
|
||||
WaitForMessageReceivedWithTimeTravel<RpcMessage>(
|
||||
new List<NetworkManager> { m_ServerNetworkManager }
|
||||
);
|
||||
|
||||
var serverComponent = GetServerComponent();
|
||||
Assert.AreEqual(20, serverComponent.SmoothOnAnticipationFailVariable.Value, Mathf.Epsilon);
|
||||
Assert.AreEqual(20, serverComponent.SmoothOnAnticipationFailVariable.AuthoritativeValue, Mathf.Epsilon);
|
||||
|
||||
var otherClientComponent = GetOtherClientComponent();
|
||||
Assert.AreEqual(0, otherClientComponent.SmoothOnAnticipationFailVariable.Value, Mathf.Epsilon);
|
||||
Assert.AreEqual(0, otherClientComponent.SmoothOnAnticipationFailVariable.AuthoritativeValue, Mathf.Epsilon);
|
||||
|
||||
WaitForMessageReceivedWithTimeTravel<NetworkVariableDeltaMessage>(m_ClientNetworkManagers.ToList());
|
||||
|
||||
Assert.AreEqual(15 + 1f / 60f * 5, testComponent.SmoothOnAnticipationFailVariable.Value, Mathf.Epsilon);
|
||||
Assert.AreEqual(20, testComponent.SmoothOnAnticipationFailVariable.AuthoritativeValue, Mathf.Epsilon);
|
||||
|
||||
Assert.AreEqual(0 + 1f / 60f * 20, otherClientComponent.SmoothOnAnticipationFailVariable.Value, Mathf.Epsilon);
|
||||
Assert.AreEqual(20, otherClientComponent.SmoothOnAnticipationFailVariable.AuthoritativeValue, Mathf.Epsilon);
|
||||
|
||||
for (var i = 1; i < 60; ++i)
|
||||
{
|
||||
TimeTravel(1f / 60f, 1);
|
||||
|
||||
Assert.AreEqual(15 + 1f / 60f * 5 * (i + 1), testComponent.SmoothOnAnticipationFailVariable.Value, 0.00001);
|
||||
Assert.AreEqual(20, testComponent.SmoothOnAnticipationFailVariable.AuthoritativeValue, Mathf.Epsilon);
|
||||
|
||||
Assert.AreEqual(0 + 1f / 60f * 20 * (i + 1), otherClientComponent.SmoothOnAnticipationFailVariable.Value, 0.00001);
|
||||
Assert.AreEqual(20, otherClientComponent.SmoothOnAnticipationFailVariable.AuthoritativeValue, Mathf.Epsilon);
|
||||
}
|
||||
TimeTravel(1f / 60f, 1);
|
||||
Assert.AreEqual(20, testComponent.SmoothOnAnticipationFailVariable.Value, Mathf.Epsilon);
|
||||
Assert.AreEqual(20, otherClientComponent.SmoothOnAnticipationFailVariable.Value, Mathf.Epsilon);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenServerChangesReanticipateValue_ValuesAreReanticipated()
|
||||
{
|
||||
var testComponent = GetTestComponent();
|
||||
|
||||
testComponent.ReanticipateOnAnticipationFailVariable.Anticipate(15);
|
||||
|
||||
Assert.AreEqual(15, testComponent.ReanticipateOnAnticipationFailVariable.Value, Mathf.Epsilon);
|
||||
Assert.AreEqual(0, testComponent.ReanticipateOnAnticipationFailVariable.AuthoritativeValue, Mathf.Epsilon);
|
||||
|
||||
// Set to a different value to simulate a anticipation failure - will lerp between the anticipated value
|
||||
// and the actual one
|
||||
testComponent.SetReanticipateValueRpc(20);
|
||||
|
||||
WaitForMessageReceivedWithTimeTravel<RpcMessage>(
|
||||
new List<NetworkManager> { m_ServerNetworkManager }
|
||||
);
|
||||
|
||||
var serverComponent = GetServerComponent();
|
||||
Assert.AreEqual(20, serverComponent.ReanticipateOnAnticipationFailVariable.Value, Mathf.Epsilon);
|
||||
Assert.AreEqual(20, serverComponent.ReanticipateOnAnticipationFailVariable.AuthoritativeValue, Mathf.Epsilon);
|
||||
|
||||
var otherClientComponent = GetOtherClientComponent();
|
||||
Assert.AreEqual(0, otherClientComponent.ReanticipateOnAnticipationFailVariable.Value, Mathf.Epsilon);
|
||||
Assert.AreEqual(0, otherClientComponent.ReanticipateOnAnticipationFailVariable.AuthoritativeValue, Mathf.Epsilon);
|
||||
|
||||
WaitForMessageReceivedWithTimeTravel<NetworkVariableDeltaMessage>(m_ClientNetworkManagers.ToList());
|
||||
|
||||
Assert.AreEqual(25, testComponent.ReanticipateOnAnticipationFailVariable.Value, Mathf.Epsilon);
|
||||
Assert.AreEqual(20, testComponent.ReanticipateOnAnticipationFailVariable.AuthoritativeValue, Mathf.Epsilon);
|
||||
|
||||
Assert.AreEqual(25, otherClientComponent.ReanticipateOnAnticipationFailVariable.Value, Mathf.Epsilon);
|
||||
Assert.AreEqual(20, otherClientComponent.ReanticipateOnAnticipationFailVariable.AuthoritativeValue, Mathf.Epsilon);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenNonStaleDataArrivesToIgnoreVariable_ItIsNotIgnored([Values(10u, 30u, 60u)] uint tickRate, [Values(0u, 1u, 2u)] uint skipFrames)
|
||||
{
|
||||
m_ServerNetworkManager.NetworkConfig.TickRate = tickRate;
|
||||
m_ServerNetworkManager.NetworkTickSystem.TickRate = tickRate;
|
||||
|
||||
for (var i = 0; i < skipFrames; ++i)
|
||||
{
|
||||
TimeTravel(1 / 60f, 1);
|
||||
}
|
||||
var testComponent = GetTestComponent();
|
||||
testComponent.SnapOnAnticipationFailVariable.Anticipate(10);
|
||||
|
||||
Assert.AreEqual(10, testComponent.SnapOnAnticipationFailVariable.Value);
|
||||
Assert.AreEqual(0, testComponent.SnapOnAnticipationFailVariable.AuthoritativeValue);
|
||||
testComponent.SetSnapValueRpc(20);
|
||||
WaitForMessageReceivedWithTimeTravel<RpcMessage>(new List<NetworkManager> { m_ServerNetworkManager });
|
||||
|
||||
var serverComponent = GetServerComponent();
|
||||
|
||||
Assert.AreEqual(20, serverComponent.SnapOnAnticipationFailVariable.Value);
|
||||
Assert.AreEqual(20, serverComponent.SnapOnAnticipationFailVariable.AuthoritativeValue);
|
||||
|
||||
WaitForMessageReceivedWithTimeTravel<NetworkVariableDeltaMessage>(m_ClientNetworkManagers.ToList());
|
||||
|
||||
// Both values get updated
|
||||
Assert.AreEqual(20, testComponent.SnapOnAnticipationFailVariable.Value);
|
||||
Assert.AreEqual(20, testComponent.SnapOnAnticipationFailVariable.AuthoritativeValue);
|
||||
|
||||
// Other client got the server value and had made no anticipation, so it applies it to the anticipated value as well.
|
||||
var otherClientComponent = GetOtherClientComponent();
|
||||
Assert.AreEqual(20, otherClientComponent.SnapOnAnticipationFailVariable.Value);
|
||||
Assert.AreEqual(20, otherClientComponent.SnapOnAnticipationFailVariable.AuthoritativeValue);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenStaleDataArrivesToIgnoreVariable_ItIsIgnored([Values(10u, 30u, 60u)] uint tickRate, [Values(0u, 1u, 2u)] uint skipFrames)
|
||||
{
|
||||
m_ServerNetworkManager.NetworkConfig.TickRate = tickRate;
|
||||
m_ServerNetworkManager.NetworkTickSystem.TickRate = tickRate;
|
||||
|
||||
for (var i = 0; i < skipFrames; ++i)
|
||||
{
|
||||
TimeTravel(1 / 60f, 1);
|
||||
}
|
||||
var testComponent = GetTestComponent();
|
||||
testComponent.SnapOnAnticipationFailVariable.Anticipate(10);
|
||||
|
||||
Assert.AreEqual(10, testComponent.SnapOnAnticipationFailVariable.Value);
|
||||
Assert.AreEqual(0, testComponent.SnapOnAnticipationFailVariable.AuthoritativeValue);
|
||||
|
||||
testComponent.SetSnapValueRpc(30);
|
||||
|
||||
var serverComponent = GetServerComponent();
|
||||
serverComponent.SnapOnAnticipationFailVariable.AuthoritativeValue = 20;
|
||||
|
||||
Assert.AreEqual(20, serverComponent.SnapOnAnticipationFailVariable.Value);
|
||||
Assert.AreEqual(20, serverComponent.SnapOnAnticipationFailVariable.AuthoritativeValue);
|
||||
|
||||
WaitForMessageReceivedWithTimeTravel<NetworkVariableDeltaMessage>(m_ClientNetworkManagers.ToList());
|
||||
|
||||
if (testComponent.SnapRpcResponseReceived)
|
||||
{
|
||||
// In this case the tick rate is slow enough that the RPC was received and processed, so we check that.
|
||||
Assert.AreEqual(30, testComponent.SnapOnAnticipationFailVariable.Value);
|
||||
Assert.AreEqual(30, testComponent.SnapOnAnticipationFailVariable.AuthoritativeValue);
|
||||
|
||||
var otherClientComponent = GetOtherClientComponent();
|
||||
Assert.AreEqual(30, otherClientComponent.SnapOnAnticipationFailVariable.Value);
|
||||
Assert.AreEqual(30, otherClientComponent.SnapOnAnticipationFailVariable.AuthoritativeValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
// In this case, we got an update before the RPC was processed, so we should have ignored it.
|
||||
// Anticipated client received this data for a tick earlier than its anticipation, and should have prioritized the anticipated value
|
||||
Assert.AreEqual(10, testComponent.SnapOnAnticipationFailVariable.Value);
|
||||
// However, the authoritative value still gets updated
|
||||
Assert.AreEqual(20, testComponent.SnapOnAnticipationFailVariable.AuthoritativeValue);
|
||||
|
||||
// Other client got the server value and had made no anticipation, so it applies it to the anticipated value as well.
|
||||
var otherClientComponent = GetOtherClientComponent();
|
||||
Assert.AreEqual(20, otherClientComponent.SnapOnAnticipationFailVariable.Value);
|
||||
Assert.AreEqual(20, otherClientComponent.SnapOnAnticipationFailVariable.AuthoritativeValue);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenStaleDataArrivesToReanticipatedVariable_ItIsAppliedAndReanticipated()
|
||||
{
|
||||
var testComponent = GetTestComponent();
|
||||
testComponent.ReanticipateOnAnticipationFailVariable.Anticipate(10);
|
||||
|
||||
Assert.AreEqual(10, testComponent.ReanticipateOnAnticipationFailVariable.Value);
|
||||
Assert.AreEqual(0, testComponent.ReanticipateOnAnticipationFailVariable.AuthoritativeValue);
|
||||
|
||||
var serverComponent = GetServerComponent();
|
||||
serverComponent.ReanticipateOnAnticipationFailVariable.AuthoritativeValue = 20;
|
||||
|
||||
Assert.AreEqual(20, serverComponent.ReanticipateOnAnticipationFailVariable.Value);
|
||||
Assert.AreEqual(20, serverComponent.ReanticipateOnAnticipationFailVariable.AuthoritativeValue);
|
||||
|
||||
WaitForMessageReceivedWithTimeTravel<NetworkVariableDeltaMessage>(m_ClientNetworkManagers.ToList());
|
||||
|
||||
Assert.AreEqual(25, testComponent.ReanticipateOnAnticipationFailVariable.Value);
|
||||
// However, the authoritative value still gets updated
|
||||
Assert.AreEqual(20, testComponent.ReanticipateOnAnticipationFailVariable.AuthoritativeValue);
|
||||
|
||||
// Other client got the server value and had made no anticipation, so it applies it to the anticipated value as well.
|
||||
var otherClientComponent = GetOtherClientComponent();
|
||||
Assert.AreEqual(25, otherClientComponent.ReanticipateOnAnticipationFailVariable.Value);
|
||||
Assert.AreEqual(20, otherClientComponent.ReanticipateOnAnticipationFailVariable.AuthoritativeValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Tests/Runtime/NetworkVariableAnticipationTests.cs.meta
Normal file
3
Tests/Runtime/NetworkVariableAnticipationTests.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 43cd37f850534b7db07e20281442f10d
|
||||
timeCreated: 1706288570
|
||||
File diff suppressed because it is too large
Load Diff
936
Tests/Runtime/NetworkVariableTestsHelperTypes.cs
Normal file
936
Tests/Runtime/NetworkVariableTestsHelperTypes.cs
Normal file
@@ -0,0 +1,936 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.Netcode.RuntimeTests
|
||||
{
|
||||
public class NetVarPermTestComp : NetworkBehaviour
|
||||
{
|
||||
public NetworkVariable<Vector3> OwnerWritable_Position = new NetworkVariable<Vector3>(Vector3.one, NetworkVariableBase.DefaultReadPerm, NetworkVariableWritePermission.Owner);
|
||||
public NetworkVariable<Vector3> ServerWritable_Position = new NetworkVariable<Vector3>(Vector3.one, NetworkVariableBase.DefaultReadPerm, NetworkVariableWritePermission.Server);
|
||||
public NetworkVariable<Vector3> OwnerReadWrite_Position = new NetworkVariable<Vector3>(Vector3.one, NetworkVariableReadPermission.Owner, NetworkVariableWritePermission.Owner);
|
||||
}
|
||||
|
||||
public class NetworkVariableMiddleclass<TMiddleclassName> : NetworkVariable<TMiddleclassName>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class NetworkVariableSubclass<TSubclassName> : NetworkVariableMiddleclass<TSubclassName>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class NetworkBehaviourWithNetVarArray : NetworkBehaviour
|
||||
{
|
||||
public NetworkVariable<int> Int0 = new NetworkVariable<int>();
|
||||
public NetworkVariable<int> Int1 = new NetworkVariable<int>();
|
||||
public NetworkVariable<int> Int2 = new NetworkVariable<int>();
|
||||
public NetworkVariable<int> Int3 = new NetworkVariable<int>();
|
||||
public NetworkVariable<int> Int4 = new NetworkVariable<int>();
|
||||
public NetworkVariable<int>[] AllInts = new NetworkVariable<int>[5];
|
||||
|
||||
public int InitializedFieldCount => NetworkVariableFields.Count;
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
AllInts[0] = Int0;
|
||||
AllInts[1] = Int1;
|
||||
AllInts[2] = Int2;
|
||||
AllInts[3] = Int3;
|
||||
AllInts[4] = Int4;
|
||||
}
|
||||
}
|
||||
|
||||
internal struct TypeReferencedOnlyInCustomSerialization1 : INetworkSerializeByMemcpy
|
||||
{
|
||||
public int I;
|
||||
}
|
||||
|
||||
internal struct TypeReferencedOnlyInCustomSerialization2 : INetworkSerializeByMemcpy
|
||||
{
|
||||
public int I;
|
||||
}
|
||||
|
||||
internal struct TypeReferencedOnlyInCustomSerialization3 : INetworkSerializeByMemcpy
|
||||
{
|
||||
public int I;
|
||||
}
|
||||
|
||||
internal struct TypeReferencedOnlyInCustomSerialization4 : INetworkSerializeByMemcpy
|
||||
{
|
||||
public int I;
|
||||
}
|
||||
|
||||
internal struct TypeReferencedOnlyInCustomSerialization5 : INetworkSerializeByMemcpy
|
||||
{
|
||||
public int I;
|
||||
}
|
||||
|
||||
internal struct TypeReferencedOnlyInCustomSerialization6 : INetworkSerializeByMemcpy
|
||||
{
|
||||
public int I;
|
||||
}
|
||||
|
||||
// Both T and U are serializable
|
||||
[GenerateSerializationForGenericParameter(0)]
|
||||
[GenerateSerializationForGenericParameter(1)]
|
||||
internal class CustomSerializableClass<TSerializableType1, TSerializableType2>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Only U is serializable
|
||||
[GenerateSerializationForGenericParameter(1)]
|
||||
internal class CustomSerializableBaseClass<TUnserializableType, TSerializableType>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// T is serializable, passes TypeReferencedOnlyInCustomSerialization3 as U to the subclass, making it serializable
|
||||
[GenerateSerializationForGenericParameter(0)]
|
||||
internal class CustomSerializableSubclass<TSerializableType> : CustomSerializableBaseClass<TSerializableType, TypeReferencedOnlyInCustomSerialization3>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// T is serializable, passes TypeReferencedOnlyInCustomSerialization3 as U to the subclass, making it serializable
|
||||
[GenerateSerializationForGenericParameter(0)]
|
||||
internal class CustomSerializableSubclassWithNativeArray<TSerializableType> : CustomSerializableBaseClass<TSerializableType, NativeArray<TypeReferencedOnlyInCustomSerialization3>>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal class CustomGenericSerializationTestBehaviour : NetworkBehaviour
|
||||
{
|
||||
public CustomSerializableClass<TypeReferencedOnlyInCustomSerialization1, TypeReferencedOnlyInCustomSerialization2> Value1;
|
||||
public CustomSerializableClass<NativeArray<TypeReferencedOnlyInCustomSerialization1>, NativeArray<TypeReferencedOnlyInCustomSerialization2>> Value2;
|
||||
public CustomSerializableSubclass<TypeReferencedOnlyInCustomSerialization4> Value3;
|
||||
public CustomSerializableSubclassWithNativeArray<NativeArray<TypeReferencedOnlyInCustomSerialization4>> Value4;
|
||||
}
|
||||
|
||||
[GenerateSerializationForType(typeof(TypeReferencedOnlyInCustomSerialization5))]
|
||||
[GenerateSerializationForType(typeof(NativeArray<TypeReferencedOnlyInCustomSerialization5>))]
|
||||
internal struct SomeRandomStruct
|
||||
{
|
||||
[GenerateSerializationForType(typeof(TypeReferencedOnlyInCustomSerialization6))]
|
||||
[GenerateSerializationForType(typeof(NativeArray<TypeReferencedOnlyInCustomSerialization6>))]
|
||||
public void Foo()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public struct TemplatedValueOnlyReferencedByNetworkVariableSubclass<T> : INetworkSerializeByMemcpy
|
||||
where T : unmanaged
|
||||
{
|
||||
public T Value;
|
||||
}
|
||||
|
||||
public enum ByteEnum : byte
|
||||
{
|
||||
A,
|
||||
B,
|
||||
C = byte.MaxValue
|
||||
}
|
||||
public enum SByteEnum : sbyte
|
||||
{
|
||||
A,
|
||||
B,
|
||||
C = sbyte.MaxValue
|
||||
}
|
||||
public enum ShortEnum : short
|
||||
{
|
||||
A,
|
||||
B,
|
||||
C = short.MaxValue
|
||||
}
|
||||
public enum UShortEnum : ushort
|
||||
{
|
||||
A,
|
||||
B,
|
||||
C = ushort.MaxValue
|
||||
}
|
||||
public enum IntEnum : int
|
||||
{
|
||||
A,
|
||||
B,
|
||||
C = int.MaxValue
|
||||
}
|
||||
public enum UIntEnum : uint
|
||||
{
|
||||
A,
|
||||
B,
|
||||
C = uint.MaxValue
|
||||
}
|
||||
public enum LongEnum : long
|
||||
{
|
||||
A,
|
||||
B,
|
||||
C = long.MaxValue
|
||||
}
|
||||
public enum ULongEnum : ulong
|
||||
{
|
||||
A,
|
||||
B,
|
||||
C = ulong.MaxValue
|
||||
}
|
||||
|
||||
public struct HashableNetworkVariableTestStruct : INetworkSerializeByMemcpy, IEquatable<HashableNetworkVariableTestStruct>
|
||||
{
|
||||
public byte A;
|
||||
public short B;
|
||||
public ushort C;
|
||||
public int D;
|
||||
public uint E;
|
||||
public long F;
|
||||
public ulong G;
|
||||
public bool H;
|
||||
public char I;
|
||||
public float J;
|
||||
public double K;
|
||||
|
||||
public bool Equals(HashableNetworkVariableTestStruct other)
|
||||
{
|
||||
return A == other.A && B == other.B && C == other.C && D == other.D && E == other.E && F == other.F && G == other.G && H == other.H && I == other.I && J.Equals(other.J) && K.Equals(other.K);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is HashableNetworkVariableTestStruct other && Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
var hashCode = new HashCode();
|
||||
hashCode.Add(A);
|
||||
hashCode.Add(B);
|
||||
hashCode.Add(C);
|
||||
hashCode.Add(D);
|
||||
hashCode.Add(E);
|
||||
hashCode.Add(F);
|
||||
hashCode.Add(G);
|
||||
hashCode.Add(H);
|
||||
hashCode.Add(I);
|
||||
hashCode.Add(J);
|
||||
hashCode.Add(K);
|
||||
return hashCode.ToHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public struct HashMapKeyStruct : INetworkSerializeByMemcpy, IEquatable<HashMapKeyStruct>
|
||||
{
|
||||
public byte A;
|
||||
public short B;
|
||||
public ushort C;
|
||||
public int D;
|
||||
public uint E;
|
||||
public long F;
|
||||
public ulong G;
|
||||
public bool H;
|
||||
public char I;
|
||||
public float J;
|
||||
public double K;
|
||||
|
||||
public bool Equals(HashMapKeyStruct other)
|
||||
{
|
||||
return A == other.A && B == other.B && C == other.C && D == other.D && E == other.E && F == other.F && G == other.G && H == other.H && I == other.I && J.Equals(other.J) && K.Equals(other.K);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is HashMapKeyStruct other && Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
var hashCode = new HashCode();
|
||||
hashCode.Add(A);
|
||||
hashCode.Add(B);
|
||||
hashCode.Add(C);
|
||||
hashCode.Add(D);
|
||||
hashCode.Add(E);
|
||||
hashCode.Add(F);
|
||||
hashCode.Add(G);
|
||||
hashCode.Add(H);
|
||||
hashCode.Add(I);
|
||||
hashCode.Add(J);
|
||||
hashCode.Add(K);
|
||||
return hashCode.ToHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public struct HashMapValStruct : INetworkSerializeByMemcpy, IEquatable<HashMapValStruct>
|
||||
{
|
||||
public byte A;
|
||||
public short B;
|
||||
public ushort C;
|
||||
public int D;
|
||||
public uint E;
|
||||
public long F;
|
||||
public ulong G;
|
||||
public bool H;
|
||||
public char I;
|
||||
public float J;
|
||||
public double K;
|
||||
|
||||
public bool Equals(HashMapValStruct other)
|
||||
{
|
||||
return A == other.A && B == other.B && C == other.C && D == other.D && E == other.E && F == other.F && G == other.G && H == other.H && I == other.I && J.Equals(other.J) && K.Equals(other.K);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is HashMapValStruct other && Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
var hashCode = new HashCode();
|
||||
hashCode.Add(A);
|
||||
hashCode.Add(B);
|
||||
hashCode.Add(C);
|
||||
hashCode.Add(D);
|
||||
hashCode.Add(E);
|
||||
hashCode.Add(F);
|
||||
hashCode.Add(G);
|
||||
hashCode.Add(H);
|
||||
hashCode.Add(I);
|
||||
hashCode.Add(J);
|
||||
hashCode.Add(K);
|
||||
return hashCode.ToHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public struct NetworkVariableTestStruct : INetworkSerializeByMemcpy
|
||||
{
|
||||
public byte A;
|
||||
public short B;
|
||||
public ushort C;
|
||||
public int D;
|
||||
public uint E;
|
||||
public long F;
|
||||
public ulong G;
|
||||
public bool H;
|
||||
public char I;
|
||||
public float J;
|
||||
public double K;
|
||||
|
||||
private static System.Random s_Random = new System.Random();
|
||||
|
||||
public static NetworkVariableTestStruct GetTestStruct()
|
||||
{
|
||||
var testStruct = new NetworkVariableTestStruct
|
||||
{
|
||||
A = (byte)s_Random.Next(),
|
||||
B = (short)s_Random.Next(),
|
||||
C = (ushort)s_Random.Next(),
|
||||
D = s_Random.Next(),
|
||||
E = (uint)s_Random.Next(),
|
||||
F = ((long)s_Random.Next() << 32) + s_Random.Next(),
|
||||
G = ((ulong)s_Random.Next() << 32) + (ulong)s_Random.Next(),
|
||||
H = true,
|
||||
I = '\u263a',
|
||||
J = (float)s_Random.NextDouble(),
|
||||
K = s_Random.NextDouble(),
|
||||
};
|
||||
|
||||
return testStruct;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class HashableNetworkVariableTestClass : INetworkSerializable, IEquatable<HashableNetworkVariableTestClass>
|
||||
{
|
||||
public HashableNetworkVariableTestStruct Data;
|
||||
|
||||
public bool Equals(HashableNetworkVariableTestClass other)
|
||||
{
|
||||
return Data.Equals(other.Data);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is HashableNetworkVariableTestClass other && Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Data.GetHashCode();
|
||||
}
|
||||
|
||||
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
|
||||
{
|
||||
serializer.SerializeValue(ref Data);
|
||||
}
|
||||
}
|
||||
|
||||
public class HashMapKeyClass : INetworkSerializable, IEquatable<HashMapKeyClass>
|
||||
{
|
||||
public HashMapKeyStruct Data;
|
||||
|
||||
public bool Equals(HashMapKeyClass other)
|
||||
{
|
||||
return Data.Equals(other.Data);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is HashMapKeyClass other && Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Data.GetHashCode();
|
||||
}
|
||||
|
||||
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
|
||||
{
|
||||
serializer.SerializeValue(ref Data);
|
||||
}
|
||||
}
|
||||
|
||||
public class HashMapValClass : INetworkSerializable, IEquatable<HashMapValClass>
|
||||
{
|
||||
public HashMapValStruct Data;
|
||||
|
||||
public bool Equals(HashMapValClass other)
|
||||
{
|
||||
return Data.Equals(other.Data);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is HashMapValClass other && Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Data.GetHashCode();
|
||||
}
|
||||
|
||||
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
|
||||
{
|
||||
serializer.SerializeValue(ref Data);
|
||||
}
|
||||
}
|
||||
|
||||
public class NetworkVariableTestClass : INetworkSerializable, IEquatable<NetworkVariableTestClass>
|
||||
{
|
||||
public NetworkVariableTestStruct Data;
|
||||
|
||||
public bool Equals(NetworkVariableTestClass other)
|
||||
{
|
||||
return NetworkVariableSerialization<NetworkVariableTestStruct>.AreEqual(ref Data, ref other.Data);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is NetworkVariableTestClass other && Equals(other);
|
||||
}
|
||||
|
||||
// This type is not used for hashing, we just need to implement IEquatable to verify lists match.
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
|
||||
{
|
||||
serializer.SerializeValue(ref Data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// The ILPP code for NetworkVariables to determine how to serialize them relies on them existing as fields of a NetworkBehaviour to find them.
|
||||
// Some of the tests below create NetworkVariables on the stack, so this class is here just to make sure the relevant types are all accounted for.
|
||||
public class NetVarILPPClassForTests : NetworkBehaviour
|
||||
{
|
||||
public NetworkVariable<byte> ByteVar;
|
||||
public NetworkVariable<NativeArray<byte>> ByteArrayVar;
|
||||
public NetworkVariable<List<byte>> ByteManagedListVar;
|
||||
public NetworkVariable<HashSet<byte>> ByteManagedHashSetVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<byte>> ByteListVar;
|
||||
public NetworkVariable<NativeHashSet<byte>> ByteHashSetVar;
|
||||
public NetworkVariable<NativeHashMap<byte, byte>> ByteByteHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<ulong, byte>> ULongByteHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<Vector2, byte>> Vector2ByteHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<HashMapKeyStruct, byte>> HashMapKeyStructByteHashMapVar;
|
||||
#endif
|
||||
public NetworkVariable<Dictionary<byte, byte>> ByteByteDictionaryVar;
|
||||
public NetworkVariable<Dictionary<ulong, byte>> ULongByteDictionaryVar;
|
||||
public NetworkVariable<Dictionary<Vector2, byte>> Vector2ByteDictionaryVar;
|
||||
public NetworkVariable<Dictionary<HashMapKeyClass, byte>> HashMapKeyClassByteDictionaryVar;
|
||||
|
||||
public NetworkVariable<sbyte> SbyteVar;
|
||||
public NetworkVariable<NativeArray<sbyte>> SbyteArrayVar;
|
||||
public NetworkVariable<List<sbyte>> SbyteManagedListVar;
|
||||
public NetworkVariable<HashSet<sbyte>> SbyteManagedHashSetVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<sbyte>> SbyteListVar;
|
||||
public NetworkVariable<NativeHashSet<sbyte>> SbyteHashSetVar;
|
||||
public NetworkVariable<NativeHashMap<byte, sbyte>> ByteSbyteHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<ulong, sbyte>> ULongSbyteHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<Vector2, sbyte>> Vector2SbyteHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<HashMapKeyStruct, sbyte>> HashMapKeyStructSbyteHashMapVar;
|
||||
#endif
|
||||
public NetworkVariable<Dictionary<byte, sbyte>> ByteSbyteDictionaryVar;
|
||||
public NetworkVariable<Dictionary<ulong, sbyte>> ULongSbyteDictionaryVar;
|
||||
public NetworkVariable<Dictionary<Vector2, sbyte>> Vector2SbyteDictionaryVar;
|
||||
public NetworkVariable<Dictionary<HashMapKeyClass, sbyte>> HashMapKeyClassSbyteDictionaryVar;
|
||||
|
||||
public NetworkVariable<short> ShortVar;
|
||||
public NetworkVariable<NativeArray<short>> ShortArrayVar;
|
||||
public NetworkVariable<List<short>> ShortManagedListVar;
|
||||
public NetworkVariable<HashSet<short>> ShortManagedHashSetVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<short>> ShortListVar;
|
||||
public NetworkVariable<NativeHashSet<short>> ShortHashSetVar;
|
||||
public NetworkVariable<NativeHashMap<byte, short>> ByteShortHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<ulong, short>> ULongShortHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<Vector2, short>> Vector2ShortHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<HashMapKeyStruct, short>> HashMapKeyStructShortHashMapVar;
|
||||
#endif
|
||||
public NetworkVariable<Dictionary<byte, short>> ByteShortDictionaryVar;
|
||||
public NetworkVariable<Dictionary<ulong, short>> ULongShortDictionaryVar;
|
||||
public NetworkVariable<Dictionary<Vector2, short>> Vector2ShortDictionaryVar;
|
||||
public NetworkVariable<Dictionary<HashMapKeyClass, short>> HashMapKeyClassShortDictionaryVar;
|
||||
|
||||
public NetworkVariable<ushort> UshortVar;
|
||||
public NetworkVariable<NativeArray<ushort>> UshortArrayVar;
|
||||
public NetworkVariable<List<ushort>> UshortManagedListVar;
|
||||
public NetworkVariable<HashSet<ushort>> UshortManagedHashSetVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<ushort>> UshortListVar;
|
||||
public NetworkVariable<NativeHashSet<ushort>> UshortHashSetVar;
|
||||
public NetworkVariable<NativeHashMap<byte, ushort>> ByteUshortHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<ulong, ushort>> ULongUshortHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<Vector2, ushort>> Vector2UshortHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<HashMapKeyStruct, ushort>> HashMapKeyStructUshortHashMapVar;
|
||||
#endif
|
||||
public NetworkVariable<Dictionary<byte, ushort>> ByteUshortDictionaryVar;
|
||||
public NetworkVariable<Dictionary<ulong, ushort>> ULongUshortDictionaryVar;
|
||||
public NetworkVariable<Dictionary<Vector2, ushort>> Vector2UshortDictionaryVar;
|
||||
public NetworkVariable<Dictionary<HashMapKeyClass, ushort>> HashMapKeyClassUshortDictionaryVar;
|
||||
|
||||
public NetworkVariable<int> IntVar;
|
||||
public NetworkVariable<NativeArray<int>> IntArrayVar;
|
||||
public NetworkVariable<List<int>> IntManagedListVar;
|
||||
public NetworkVariable<HashSet<int>> IntManagedHashSetVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<int>> IntListVar;
|
||||
public NetworkVariable<NativeHashSet<int>> IntHashSetVar;
|
||||
public NetworkVariable<NativeHashMap<byte, int>> ByteIntHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<ulong, int>> ULongIntHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<Vector2, int>> Vector2IntHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<HashMapKeyStruct, int>> HashMapKeyStructIntHashMapVar;
|
||||
#endif
|
||||
public NetworkVariable<Dictionary<byte, int>> ByteIntDictionaryVar;
|
||||
public NetworkVariable<Dictionary<ulong, int>> ULongIntDictionaryVar;
|
||||
public NetworkVariable<Dictionary<Vector2, int>> Vector2IntDictionaryVar;
|
||||
public NetworkVariable<Dictionary<HashMapKeyClass, int>> HashMapKeyClassIntDictionaryVar;
|
||||
|
||||
public NetworkVariable<uint> UintVar;
|
||||
public NetworkVariable<NativeArray<uint>> UintArrayVar;
|
||||
public NetworkVariable<List<uint>> UintManagedListVar;
|
||||
public NetworkVariable<HashSet<uint>> UintManagedHashSetVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<uint>> UintListVar;
|
||||
public NetworkVariable<NativeHashSet<uint>> UintHashSetVar;
|
||||
public NetworkVariable<NativeHashMap<byte, uint>> ByteUintHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<ulong, uint>> ULongUintHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<Vector2, uint>> Vector2UintHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<HashMapKeyStruct, uint>> HashMapKeyStructUintHashMapVar;
|
||||
#endif
|
||||
public NetworkVariable<Dictionary<byte, uint>> ByteUintDictionaryVar;
|
||||
public NetworkVariable<Dictionary<ulong, uint>> ULongUintDictionaryVar;
|
||||
public NetworkVariable<Dictionary<Vector2, uint>> Vector2UintDictionaryVar;
|
||||
public NetworkVariable<Dictionary<HashMapKeyClass, uint>> HashMapKeyClassUintDictionaryVar;
|
||||
|
||||
public NetworkVariable<long> LongVar;
|
||||
public NetworkVariable<NativeArray<long>> LongArrayVar;
|
||||
public NetworkVariable<List<long>> LongManagedListVar;
|
||||
public NetworkVariable<HashSet<long>> LongManagedHashSetVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<long>> LongListVar;
|
||||
public NetworkVariable<NativeHashSet<long>> LongHashSetVar;
|
||||
public NetworkVariable<NativeHashMap<byte, long>> ByteLongHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<ulong, long>> ULongLongHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<Vector2, long>> Vector2LongHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<HashMapKeyStruct, long>> HashMapKeyStructLongHashMapVar;
|
||||
#endif
|
||||
public NetworkVariable<Dictionary<byte, long>> ByteLongDictionaryVar;
|
||||
public NetworkVariable<Dictionary<ulong, long>> ULongLongDictionaryVar;
|
||||
public NetworkVariable<Dictionary<Vector2, long>> Vector2LongDictionaryVar;
|
||||
public NetworkVariable<Dictionary<HashMapKeyClass, long>> HashMapKeyClassLongDictionaryVar;
|
||||
|
||||
public NetworkVariable<ulong> UlongVar;
|
||||
public NetworkVariable<NativeArray<ulong>> UlongArrayVar;
|
||||
public NetworkVariable<List<ulong>> UlongManagedListVar;
|
||||
public NetworkVariable<HashSet<ulong>> UlongManagedHashSetVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<ulong>> UlongListVar;
|
||||
public NetworkVariable<NativeHashSet<ulong>> UlongHashSetVar;
|
||||
public NetworkVariable<NativeHashMap<byte, ulong>> ByteUlongHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<ulong, ulong>> ULongUlongHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<Vector2, ulong>> Vector2UlongHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<HashMapKeyStruct, ulong>> HashMapKeyStructUlongHashMapVar;
|
||||
#endif
|
||||
public NetworkVariable<Dictionary<byte, ulong>> ByteUlongDictionaryVar;
|
||||
public NetworkVariable<Dictionary<ulong, ulong>> ULongUlongDictionaryVar;
|
||||
public NetworkVariable<Dictionary<Vector2, ulong>> Vector2UlongDictionaryVar;
|
||||
public NetworkVariable<Dictionary<HashMapKeyClass, ulong>> HashMapKeyClassUlongDictionaryVar;
|
||||
|
||||
public NetworkVariable<bool> BoolVar;
|
||||
public NetworkVariable<NativeArray<bool>> BoolArrayVar;
|
||||
public NetworkVariable<List<bool>> BoolManagedListVar;
|
||||
public NetworkVariable<HashSet<bool>> BoolManagedHashSetVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<bool>> BoolListVar;
|
||||
public NetworkVariable<NativeHashSet<bool>> BoolHashSetVar;
|
||||
public NetworkVariable<NativeHashMap<byte, bool>> ByteBoolHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<ulong, bool>> ULongBoolHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<Vector2, bool>> Vector2BoolHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<HashMapKeyStruct, bool>> HashMapKeyStructBoolHashMapVar;
|
||||
#endif
|
||||
public NetworkVariable<Dictionary<byte, bool>> ByteBoolDictionaryVar;
|
||||
public NetworkVariable<Dictionary<ulong, bool>> ULongBoolDictionaryVar;
|
||||
public NetworkVariable<Dictionary<Vector2, bool>> Vector2BoolDictionaryVar;
|
||||
public NetworkVariable<Dictionary<HashMapKeyClass, bool>> HashMapKeyClassBoolDictionaryVar;
|
||||
|
||||
public NetworkVariable<char> CharVar;
|
||||
public NetworkVariable<NativeArray<char>> CharArrayVar;
|
||||
public NetworkVariable<List<char>> CharManagedListVar;
|
||||
public NetworkVariable<HashSet<char>> CharManagedHashSetVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<char>> CharListVar;
|
||||
public NetworkVariable<NativeHashSet<char>> CharHashSetVar;
|
||||
public NetworkVariable<NativeHashMap<byte, char>> ByteCharHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<ulong, char>> ULongCharHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<Vector2, char>> Vector2CharHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<HashMapKeyStruct, char>> HashMapKeyStructCharHashMapVar;
|
||||
#endif
|
||||
public NetworkVariable<Dictionary<byte, char>> ByteCharDictionaryVar;
|
||||
public NetworkVariable<Dictionary<ulong, char>> ULongCharDictionaryVar;
|
||||
public NetworkVariable<Dictionary<Vector2, char>> Vector2CharDictionaryVar;
|
||||
public NetworkVariable<Dictionary<HashMapKeyClass, char>> HashMapKeyClassCharDictionaryVar;
|
||||
|
||||
public NetworkVariable<float> FloatVar;
|
||||
public NetworkVariable<NativeArray<float>> FloatArrayVar;
|
||||
public NetworkVariable<List<float>> FloatManagedListVar;
|
||||
public NetworkVariable<HashSet<float>> FloatManagedHashSetVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<float>> FloatListVar;
|
||||
public NetworkVariable<NativeHashSet<float>> FloatHashSetVar;
|
||||
public NetworkVariable<NativeHashMap<byte, float>> ByteFloatHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<ulong, float>> ULongFloatHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<Vector2, float>> Vector2FloatHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<HashMapKeyStruct, float>> HashMapKeyStructFloatHashMapVar;
|
||||
#endif
|
||||
public NetworkVariable<Dictionary<byte, float>> ByteFloatDictionaryVar;
|
||||
public NetworkVariable<Dictionary<ulong, float>> ULongFloatDictionaryVar;
|
||||
public NetworkVariable<Dictionary<Vector2, float>> Vector2FloatDictionaryVar;
|
||||
public NetworkVariable<Dictionary<HashMapKeyClass, float>> HashMapKeyClassFloatDictionaryVar;
|
||||
|
||||
public NetworkVariable<double> DoubleVar;
|
||||
public NetworkVariable<NativeArray<double>> DoubleArrayVar;
|
||||
public NetworkVariable<List<double>> DoubleManagedListVar;
|
||||
public NetworkVariable<HashSet<double>> DoubleManagedHashSetVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<double>> DoubleListVar;
|
||||
public NetworkVariable<NativeHashSet<double>> DoubleHashSetVar;
|
||||
public NetworkVariable<NativeHashMap<byte, double>> ByteDoubleHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<ulong, double>> ULongDoubleHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<Vector2, double>> Vector2DoubleHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<HashMapKeyStruct, double>> HashMapKeyStructDoubleHashMapVar;
|
||||
#endif
|
||||
public NetworkVariable<Dictionary<byte, double>> ByteDoubleDictionaryVar;
|
||||
public NetworkVariable<Dictionary<ulong, double>> ULongDoubleDictionaryVar;
|
||||
public NetworkVariable<Dictionary<Vector2, double>> Vector2DoubleDictionaryVar;
|
||||
public NetworkVariable<Dictionary<HashMapKeyClass, double>> HashMapKeyClassDoubleDictionaryVar;
|
||||
|
||||
public NetworkVariable<ByteEnum> ByteEnumVar;
|
||||
public NetworkVariable<NativeArray<ByteEnum>> ByteEnumArrayVar;
|
||||
public NetworkVariable<List<ByteEnum>> ByteEnumManagedListVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<ByteEnum>> ByteEnumListVar;
|
||||
#endif
|
||||
public NetworkVariable<SByteEnum> SByteEnumVar;
|
||||
public NetworkVariable<NativeArray<SByteEnum>> SByteEnumArrayVar;
|
||||
public NetworkVariable<List<SByteEnum>> SByteEnumManagedListVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<SByteEnum>> SByteEnumListVar;
|
||||
#endif
|
||||
public NetworkVariable<ShortEnum> ShortEnumVar;
|
||||
public NetworkVariable<NativeArray<ShortEnum>> ShortEnumArrayVar;
|
||||
public NetworkVariable<List<ShortEnum>> ShortEnumManagedListVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<ShortEnum>> ShortEnumListVar;
|
||||
#endif
|
||||
public NetworkVariable<UShortEnum> UShortEnumVar;
|
||||
public NetworkVariable<NativeArray<UShortEnum>> UShortEnumArrayVar;
|
||||
public NetworkVariable<List<UShortEnum>> UShortEnumManagedListVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<UShortEnum>> UShortEnumListVar;
|
||||
#endif
|
||||
public NetworkVariable<IntEnum> IntEnumVar;
|
||||
public NetworkVariable<NativeArray<IntEnum>> IntEnumArrayVar;
|
||||
public NetworkVariable<List<IntEnum>> IntEnumManagedListVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<IntEnum>> IntEnumListVar;
|
||||
#endif
|
||||
public NetworkVariable<UIntEnum> UIntEnumVar;
|
||||
public NetworkVariable<NativeArray<UIntEnum>> UIntEnumArrayVar;
|
||||
public NetworkVariable<List<UIntEnum>> UIntEnumManagedListVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<UIntEnum>> UIntEnumListVar;
|
||||
#endif
|
||||
public NetworkVariable<LongEnum> LongEnumVar;
|
||||
public NetworkVariable<NativeArray<LongEnum>> LongEnumArrayVar;
|
||||
public NetworkVariable<List<LongEnum>> LongEnumManagedListVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<LongEnum>> LongEnumListVar;
|
||||
#endif
|
||||
public NetworkVariable<ULongEnum> ULongEnumVar;
|
||||
public NetworkVariable<NativeArray<ULongEnum>> ULongEnumArrayVar;
|
||||
public NetworkVariable<List<ULongEnum>> ULongEnumManagedListVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<ULongEnum>> ULongEnumListVar;
|
||||
#endif
|
||||
public NetworkVariable<Vector2> Vector2Var;
|
||||
public NetworkVariable<NativeArray<Vector2>> Vector2ArrayVar;
|
||||
public NetworkVariable<List<Vector2>> Vector2ManagedListVar;
|
||||
public NetworkVariable<HashSet<Vector2>> Vector2ManagedHashSetVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<Vector2>> Vector2ListVar;
|
||||
public NetworkVariable<NativeHashSet<Vector2>> Vector2HashSetVar;
|
||||
public NetworkVariable<NativeHashMap<byte, Vector2>> ByteVector2HashMapVar;
|
||||
public NetworkVariable<NativeHashMap<ulong, Vector2>> ULongVector2HashMapVar;
|
||||
public NetworkVariable<NativeHashMap<Vector2, Vector2>> Vector2Vector2HashMapVar;
|
||||
public NetworkVariable<NativeHashMap<HashMapKeyStruct, Vector2>> HashMapKeyStructVector2HashMapVar;
|
||||
#endif
|
||||
public NetworkVariable<Dictionary<byte, Vector2>> ByteVector2DictionaryVar;
|
||||
public NetworkVariable<Dictionary<ulong, Vector2>> ULongVector2DictionaryVar;
|
||||
public NetworkVariable<Dictionary<Vector2, Vector2>> Vector2Vector2DictionaryVar;
|
||||
public NetworkVariable<Dictionary<HashMapKeyClass, Vector2>> HashMapKeyClassVector2DictionaryVar;
|
||||
|
||||
public NetworkVariable<Vector3> Vector3Var;
|
||||
public NetworkVariable<NativeArray<Vector3>> Vector3ArrayVar;
|
||||
public NetworkVariable<List<Vector3>> Vector3ManagedListVar;
|
||||
public NetworkVariable<HashSet<Vector3>> Vector3ManagedHashSetVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<Vector3>> Vector3ListVar;
|
||||
public NetworkVariable<NativeHashSet<Vector3>> Vector3HashSetVar;
|
||||
public NetworkVariable<NativeHashMap<byte, Vector3>> ByteVector3HashMapVar;
|
||||
public NetworkVariable<NativeHashMap<ulong, Vector3>> ULongVector3HashMapVar;
|
||||
public NetworkVariable<NativeHashMap<Vector2, Vector3>> Vector2Vector3HashMapVar;
|
||||
public NetworkVariable<NativeHashMap<HashMapKeyStruct, Vector3>> HashMapKeyStructVector3HashMapVar;
|
||||
#endif
|
||||
public NetworkVariable<Dictionary<byte, Vector3>> ByteVector3DictionaryVar;
|
||||
public NetworkVariable<Dictionary<ulong, Vector3>> ULongVector3DictionaryVar;
|
||||
public NetworkVariable<Dictionary<Vector2, Vector3>> Vector2Vector3DictionaryVar;
|
||||
public NetworkVariable<Dictionary<HashMapKeyClass, Vector3>> HashMapKeyClassVector3DictionaryVar;
|
||||
|
||||
public NetworkVariable<Vector2Int> Vector2IntVar;
|
||||
public NetworkVariable<NativeArray<Vector2Int>> Vector2IntArrayVar;
|
||||
public NetworkVariable<List<Vector2Int>> Vector2IntManagedListVar;
|
||||
public NetworkVariable<HashSet<Vector2Int>> Vector2IntManagedHashSetVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<Vector2Int>> Vector2IntListVar;
|
||||
public NetworkVariable<NativeHashSet<Vector2Int>> Vector2IntHashSetVar;
|
||||
public NetworkVariable<NativeHashMap<byte, Vector2Int>> ByteVector2IntHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<ulong, Vector2Int>> ULongVector2IntHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<Vector2, Vector2Int>> Vector2Vector2IntHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<HashMapKeyStruct, Vector2Int>> HashMapKeyStructVector2IntHashMapVar;
|
||||
#endif
|
||||
public NetworkVariable<Dictionary<byte, Vector2Int>> ByteVector2IntDictionaryVar;
|
||||
public NetworkVariable<Dictionary<ulong, Vector2Int>> ULongVector2IntDictionaryVar;
|
||||
public NetworkVariable<Dictionary<Vector2, Vector2Int>> Vector2Vector2IntDictionaryVar;
|
||||
public NetworkVariable<Dictionary<HashMapKeyClass, Vector2Int>> HashMapKeyClassVector2IntDictionaryVar;
|
||||
|
||||
public NetworkVariable<Vector3Int> Vector3IntVar;
|
||||
public NetworkVariable<NativeArray<Vector3Int>> Vector3IntArrayVar;
|
||||
public NetworkVariable<List<Vector3Int>> Vector3IntManagedListVar;
|
||||
public NetworkVariable<HashSet<Vector3Int>> Vector3IntManagedHashSetVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<Vector3Int>> Vector3IntListVar;
|
||||
public NetworkVariable<NativeHashSet<Vector3Int>> Vector3IntHashSetVar;
|
||||
public NetworkVariable<NativeHashMap<byte, Vector3Int>> ByteVector3IntHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<ulong, Vector3Int>> ULongVector3IntHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<Vector2, Vector3Int>> Vector2Vector3IntHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<HashMapKeyStruct, Vector3Int>> HashMapKeyStructVector3IntHashMapVar;
|
||||
#endif
|
||||
public NetworkVariable<Dictionary<byte, Vector3Int>> ByteVector3IntDictionaryVar;
|
||||
public NetworkVariable<Dictionary<ulong, Vector3Int>> ULongVector3IntDictionaryVar;
|
||||
public NetworkVariable<Dictionary<Vector2, Vector3Int>> Vector2Vector3IntDictionaryVar;
|
||||
public NetworkVariable<Dictionary<HashMapKeyClass, Vector3Int>> HashMapKeyClassVector3IntDictionaryVar;
|
||||
|
||||
public NetworkVariable<Vector4> Vector4Var;
|
||||
public NetworkVariable<NativeArray<Vector4>> Vector4ArrayVar;
|
||||
public NetworkVariable<List<Vector4>> Vector4ManagedListVar;
|
||||
public NetworkVariable<HashSet<Vector4>> Vector4ManagedHashSetVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<Vector4>> Vector4ListVar;
|
||||
public NetworkVariable<NativeHashSet<Vector4>> Vector4HashSetVar;
|
||||
public NetworkVariable<NativeHashMap<byte, Vector4>> ByteVector4HashMapVar;
|
||||
public NetworkVariable<NativeHashMap<ulong, Vector4>> ULongVector4HashMapVar;
|
||||
public NetworkVariable<NativeHashMap<Vector2, Vector4>> Vector2Vector4HashMapVar;
|
||||
public NetworkVariable<NativeHashMap<HashMapKeyStruct, Vector4>> HashMapKeyStructVector4HashMapVar;
|
||||
#endif
|
||||
public NetworkVariable<Dictionary<byte, Vector4>> ByteVector4DictionaryVar;
|
||||
public NetworkVariable<Dictionary<ulong, Vector4>> ULongVector4DictionaryVar;
|
||||
public NetworkVariable<Dictionary<Vector2, Vector4>> Vector2Vector4DictionaryVar;
|
||||
public NetworkVariable<Dictionary<HashMapKeyClass, Vector4>> HashMapKeyClassVector4DictionaryVar;
|
||||
|
||||
public NetworkVariable<Quaternion> QuaternionVar;
|
||||
public NetworkVariable<NativeArray<Quaternion>> QuaternionArrayVar;
|
||||
public NetworkVariable<List<Quaternion>> QuaternionManagedListVar;
|
||||
public NetworkVariable<HashSet<Quaternion>> QuaternionManagedHashSetVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<Quaternion>> QuaternionListVar;
|
||||
public NetworkVariable<NativeHashSet<Quaternion>> QuaternionHashSetVar;
|
||||
public NetworkVariable<NativeHashMap<byte, Quaternion>> ByteQuaternionHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<ulong, Quaternion>> ULongQuaternionHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<Vector2, Quaternion>> Vector2QuaternionHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<HashMapKeyStruct, Quaternion>> HashMapKeyStructQuaternionHashMapVar;
|
||||
#endif
|
||||
public NetworkVariable<Dictionary<byte, Quaternion>> ByteQuaternionDictionaryVar;
|
||||
public NetworkVariable<Dictionary<ulong, Quaternion>> ULongQuaternionDictionaryVar;
|
||||
public NetworkVariable<Dictionary<Vector2, Quaternion>> Vector2QuaternionDictionaryVar;
|
||||
public NetworkVariable<Dictionary<HashMapKeyClass, Quaternion>> HashMapKeyClassQuaternionDictionaryVar;
|
||||
|
||||
public NetworkVariable<Color> ColorVar;
|
||||
public NetworkVariable<NativeArray<Color>> ColorArrayVar;
|
||||
public NetworkVariable<List<Color>> ColorManagedListVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<Color>> ColorListVar;
|
||||
#endif
|
||||
public NetworkVariable<Color32> Color32Var;
|
||||
public NetworkVariable<NativeArray<Color32>> Color32ArrayVar;
|
||||
public NetworkVariable<List<Color32>> Color32ManagedListVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<Color32>> Color32ListVar;
|
||||
#endif
|
||||
public NetworkVariable<Ray> RayVar;
|
||||
public NetworkVariable<NativeArray<Ray>> RayArrayVar;
|
||||
public NetworkVariable<List<Ray>> RayManagedListVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<Ray>> RayListVar;
|
||||
#endif
|
||||
public NetworkVariable<Ray2D> Ray2DVar;
|
||||
public NetworkVariable<NativeArray<Ray2D>> Ray2DArrayVar;
|
||||
public NetworkVariable<List<Ray2D>> Ray2DManagedListVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<Ray2D>> Ray2DListVar;
|
||||
#endif
|
||||
public NetworkVariable<NetworkVariableTestStruct> TestStructVar;
|
||||
public NetworkVariable<NativeArray<NetworkVariableTestStruct>> TestStructArrayVar;
|
||||
public NetworkVariable<List<NetworkVariableTestClass>> TestStructManagedListVar;
|
||||
public NetworkVariable<HashSet<HashableNetworkVariableTestClass>> TestStructManagedHashSetVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<NetworkVariableTestStruct>> TestStructListVar;
|
||||
public NetworkVariable<NativeHashSet<HashableNetworkVariableTestStruct>> TestStructHashSetVar;
|
||||
public NetworkVariable<NativeHashMap<byte, HashMapValStruct>> ByteTestStructHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<ulong, HashMapValStruct>> ULongTestStructHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<Vector2, HashMapValStruct>> Vector2TestStructHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<HashMapKeyStruct, HashMapValStruct>> HashMapKeyStructTestStructHashMapVar;
|
||||
#endif
|
||||
public NetworkVariable<Dictionary<byte, HashMapValClass>> ByteTestStructDictionaryVar;
|
||||
public NetworkVariable<Dictionary<ulong, HashMapValClass>> ULongTestStructDictionaryVar;
|
||||
public NetworkVariable<Dictionary<Vector2, HashMapValClass>> Vector2TestStructDictionaryVar;
|
||||
public NetworkVariable<Dictionary<HashMapKeyClass, HashMapValClass>> HashMapKeyClassTestStructDictionaryVar;
|
||||
|
||||
|
||||
public NetworkVariable<FixedString32Bytes> FixedStringVar;
|
||||
public NetworkVariable<NativeArray<FixedString32Bytes>> FixedStringArrayVar;
|
||||
public NetworkVariable<List<FixedString32Bytes>> FixedStringManagedListVar;
|
||||
public NetworkVariable<HashSet<FixedString32Bytes>> FixedStringManagedHashSetVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<FixedString32Bytes>> FixedStringListVar;
|
||||
public NetworkVariable<NativeHashSet<FixedString32Bytes>> FixedStringHashSetVar;
|
||||
public NetworkVariable<NativeHashMap<byte, FixedString32Bytes>> ByteFixedStringHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<ulong, FixedString32Bytes>> ULongFixedStringHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<Vector2, FixedString32Bytes>> Vector2FixedStringHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<HashMapKeyStruct, FixedString32Bytes>> HashMapKeyStructFixedStringHashMapVar;
|
||||
#endif
|
||||
public NetworkVariable<Dictionary<byte, FixedString32Bytes>> ByteFixedStringDictionaryVar;
|
||||
public NetworkVariable<Dictionary<ulong, FixedString32Bytes>> ULongFixedStringDictionaryVar;
|
||||
public NetworkVariable<Dictionary<Vector2, FixedString32Bytes>> Vector2FixedStringDictionaryVar;
|
||||
public NetworkVariable<Dictionary<HashMapKeyClass, FixedString32Bytes>> HashMapKeyClassFixedStringDictionaryVar;
|
||||
|
||||
|
||||
public NetworkVariable<UnmanagedNetworkSerializableType> UnmanagedNetworkSerializableTypeVar;
|
||||
public NetworkVariable<HashSet<UnmanagedNetworkSerializableType>> UnmanagedNetworkSerializableManagedHashSetVar;
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public NetworkVariable<NativeList<UnmanagedNetworkSerializableType>> UnmanagedNetworkSerializableListVar;
|
||||
public NetworkVariable<NativeHashSet<UnmanagedNetworkSerializableType>> UnmanagedNetworkSerializableHashSetVar;
|
||||
public NetworkVariable<NativeHashMap<byte, UnmanagedNetworkSerializableType>> ByteUnmanagedNetworkSerializableHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<ulong, UnmanagedNetworkSerializableType>> ULongUnmanagedNetworkSerializableHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<Vector2, UnmanagedNetworkSerializableType>> Vector2UnmanagedNetworkSerializableHashMapVar;
|
||||
public NetworkVariable<NativeHashMap<HashMapKeyStruct, UnmanagedNetworkSerializableType>> HashMapKeyStructUnmanagedNetworkSerializableHashMapVar;
|
||||
#endif
|
||||
public NetworkVariable<Dictionary<byte, UnmanagedNetworkSerializableType>> ByteUnmanagedNetworkSerializableDictionaryVar;
|
||||
public NetworkVariable<Dictionary<ulong, UnmanagedNetworkSerializableType>> ULongUnmanagedNetworkSerializableDictionaryVar;
|
||||
public NetworkVariable<Dictionary<Vector2, UnmanagedNetworkSerializableType>> Vector2UnmanagedNetworkSerializableDictionaryVar;
|
||||
public NetworkVariable<Dictionary<HashMapKeyClass, UnmanagedNetworkSerializableType>> HashMapKeyClassUnmanagedNetworkSerializableDictionaryVar;
|
||||
|
||||
public NetworkVariable<NativeArray<UnmanagedNetworkSerializableType>> UnmanagedNetworkSerializableArrayVar;
|
||||
public NetworkVariable<List<UnmanagedNetworkSerializableType>> UnmanagedNetworkSerializableManagedListVar;
|
||||
|
||||
public NetworkVariable<ManagedNetworkSerializableType> ManagedNetworkSerializableTypeVar;
|
||||
|
||||
public NetworkVariable<string> StringVar;
|
||||
public NetworkVariable<Guid> GuidVar;
|
||||
public NetworkVariableSubclass<TemplatedValueOnlyReferencedByNetworkVariableSubclass<int>> SubclassVar;
|
||||
}
|
||||
|
||||
public class TemplateNetworkBehaviourType<T> : NetworkBehaviour
|
||||
{
|
||||
public NetworkVariable<T> TheVar;
|
||||
}
|
||||
|
||||
public class IntermediateNetworkBehavior<T> : TemplateNetworkBehaviourType<T>
|
||||
{
|
||||
public NetworkVariable<T> TheVar2;
|
||||
}
|
||||
|
||||
public class ClassHavingNetworkBehaviour : IntermediateNetworkBehavior<TestClass>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Please do not reference TestClass_ReferencedOnlyByTemplateNetworkBehavourType anywhere other than here!
|
||||
public class ClassHavingNetworkBehaviour2 : TemplateNetworkBehaviourType<TestClass_ReferencedOnlyByTemplateNetworkBehavourType>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class StructHavingNetworkBehaviour : TemplateNetworkBehaviourType<TestStruct>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public struct StructUsedOnlyInNetworkList : IEquatable<StructUsedOnlyInNetworkList>, INetworkSerializeByMemcpy
|
||||
{
|
||||
public int Value;
|
||||
|
||||
public bool Equals(StructUsedOnlyInNetworkList other)
|
||||
{
|
||||
return Value == other.Value;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is StructUsedOnlyInNetworkList other && Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
3
Tests/Runtime/NetworkVariableTestsHelperTypes.cs.meta
Normal file
3
Tests/Runtime/NetworkVariableTestsHelperTypes.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a580aaafc247486193f372174a99fae4
|
||||
timeCreated: 1705098783
|
||||
138
Tests/Runtime/NetworkVariableTraitsTests.cs
Normal file
138
Tests/Runtime/NetworkVariableTraitsTests.cs
Normal file
@@ -0,0 +1,138 @@
|
||||
using NUnit.Framework;
|
||||
using Unity.Netcode.TestHelpers.Runtime;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace Unity.Netcode.RuntimeTests
|
||||
{
|
||||
public class NetworkVariableTraitsComponent : NetworkBehaviour
|
||||
{
|
||||
public NetworkVariable<float> TheVariable = new NetworkVariable<float>();
|
||||
}
|
||||
|
||||
public class NetworkVariableTraitsTests : NetcodeIntegrationTest
|
||||
{
|
||||
protected override int NumberOfClients => 2;
|
||||
|
||||
protected override bool m_EnableTimeTravel => true;
|
||||
protected override bool m_SetupIsACoroutine => false;
|
||||
protected override bool m_TearDownIsACoroutine => false;
|
||||
|
||||
protected override void OnPlayerPrefabGameObjectCreated()
|
||||
{
|
||||
m_PlayerPrefab.AddComponent<NetworkVariableTraitsComponent>();
|
||||
}
|
||||
|
||||
public NetworkVariableTraitsComponent GetTestComponent()
|
||||
{
|
||||
return m_ClientNetworkManagers[0].LocalClient.PlayerObject.GetComponent<NetworkVariableTraitsComponent>();
|
||||
}
|
||||
|
||||
public NetworkVariableTraitsComponent GetServerComponent()
|
||||
{
|
||||
foreach (var obj in Object.FindObjectsByType<NetworkVariableTraitsComponent>(FindObjectsSortMode.None))
|
||||
{
|
||||
if (obj.NetworkManager == m_ServerNetworkManager && obj.OwnerClientId == m_ClientNetworkManagers[0].LocalClientId)
|
||||
{
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenNewValueIsLessThanThreshold_VariableIsNotSerialized()
|
||||
{
|
||||
var serverComponent = GetServerComponent();
|
||||
var testComponent = GetTestComponent();
|
||||
serverComponent.TheVariable.CheckExceedsDirtinessThreshold = (in float value, in float newValue) => Mathf.Abs(newValue - value) >= 0.1;
|
||||
|
||||
serverComponent.TheVariable.Value = 0.05f;
|
||||
|
||||
TimeTravel(2, 120);
|
||||
|
||||
Assert.AreEqual(0.05f, serverComponent.TheVariable.Value); ;
|
||||
Assert.AreEqual(0, testComponent.TheVariable.Value); ;
|
||||
}
|
||||
[Test]
|
||||
public void WhenNewValueIsGreaterThanThreshold_VariableIsSerialized()
|
||||
{
|
||||
var serverComponent = GetServerComponent();
|
||||
var testComponent = GetTestComponent();
|
||||
serverComponent.TheVariable.CheckExceedsDirtinessThreshold = (in float value, in float newValue) => Mathf.Abs(newValue - value) >= 0.1;
|
||||
|
||||
serverComponent.TheVariable.Value = 0.15f;
|
||||
|
||||
TimeTravel(2, 120);
|
||||
|
||||
Assert.AreEqual(0.15f, serverComponent.TheVariable.Value); ;
|
||||
Assert.AreEqual(0.15f, testComponent.TheVariable.Value); ;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenNewValueIsLessThanThresholdButMaxTimeHasPassed_VariableIsSerialized()
|
||||
{
|
||||
var serverComponent = GetServerComponent();
|
||||
var testComponent = GetTestComponent();
|
||||
serverComponent.TheVariable.CheckExceedsDirtinessThreshold = (in float value, in float newValue) => Mathf.Abs(newValue - value) >= 0.1;
|
||||
serverComponent.TheVariable.SetUpdateTraits(new NetworkVariableUpdateTraits { MaxSecondsBetweenUpdates = 2 });
|
||||
serverComponent.TheVariable.LastUpdateSent = m_ServerNetworkManager.NetworkTimeSystem.LocalTime;
|
||||
|
||||
serverComponent.TheVariable.Value = 0.05f;
|
||||
|
||||
TimeTravel(1 / 60f * 119, 119);
|
||||
|
||||
Assert.AreEqual(0.05f, serverComponent.TheVariable.Value); ;
|
||||
Assert.AreEqual(0, testComponent.TheVariable.Value); ;
|
||||
|
||||
TimeTravel(1 / 60f * 4, 4);
|
||||
|
||||
Assert.AreEqual(0.05f, serverComponent.TheVariable.Value); ;
|
||||
Assert.AreEqual(0.05f, testComponent.TheVariable.Value); ;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenNewValueIsGreaterThanThresholdButMinTimeHasNotPassed_VariableIsNotSerialized()
|
||||
{
|
||||
var serverComponent = GetServerComponent();
|
||||
var testComponent = GetTestComponent();
|
||||
serverComponent.TheVariable.CheckExceedsDirtinessThreshold = (in float value, in float newValue) => Mathf.Abs(newValue - value) >= 0.1;
|
||||
serverComponent.TheVariable.SetUpdateTraits(new NetworkVariableUpdateTraits { MinSecondsBetweenUpdates = 2 });
|
||||
serverComponent.TheVariable.LastUpdateSent = m_ServerNetworkManager.NetworkTimeSystem.LocalTime;
|
||||
|
||||
serverComponent.TheVariable.Value = 0.15f;
|
||||
|
||||
TimeTravel(1 / 60f * 119, 119);
|
||||
|
||||
Assert.AreEqual(0.15f, serverComponent.TheVariable.Value); ;
|
||||
Assert.AreEqual(0, testComponent.TheVariable.Value); ;
|
||||
|
||||
TimeTravel(1 / 60f * 4, 4);
|
||||
|
||||
Assert.AreEqual(0.15f, serverComponent.TheVariable.Value); ;
|
||||
Assert.AreEqual(0.15f, testComponent.TheVariable.Value); ;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenNoThresholdIsSetButMinTimeHasNotPassed_VariableIsNotSerialized()
|
||||
{
|
||||
var serverComponent = GetServerComponent();
|
||||
var testComponent = GetTestComponent();
|
||||
serverComponent.TheVariable.SetUpdateTraits(new NetworkVariableUpdateTraits { MinSecondsBetweenUpdates = 2 });
|
||||
serverComponent.TheVariable.LastUpdateSent = m_ServerNetworkManager.NetworkTimeSystem.LocalTime;
|
||||
|
||||
serverComponent.TheVariable.Value = 0.15f;
|
||||
|
||||
TimeTravel(1 / 60f * 119, 119);
|
||||
|
||||
Assert.AreEqual(0.15f, serverComponent.TheVariable.Value); ;
|
||||
Assert.AreEqual(0, testComponent.TheVariable.Value); ;
|
||||
|
||||
TimeTravel(1 / 60f * 4, 4);
|
||||
|
||||
Assert.AreEqual(0.15f, serverComponent.TheVariable.Value); ;
|
||||
Assert.AreEqual(0.15f, testComponent.TheVariable.Value); ;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Tests/Runtime/NetworkVariableTraitsTests.cs.meta
Normal file
3
Tests/Runtime/NetworkVariableTraitsTests.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c4ca75209dbd43f48930e4887392bafd
|
||||
timeCreated: 1706826268
|
||||
@@ -112,6 +112,16 @@ namespace Unity.Netcode.RuntimeTests
|
||||
protected override IEnumerator OnSetup()
|
||||
{
|
||||
WorkingUserNetworkVariableComponentBase.Reset();
|
||||
|
||||
UserNetworkVariableSerialization<MyTypeOne>.WriteValue = null;
|
||||
UserNetworkVariableSerialization<MyTypeOne>.ReadValue = null;
|
||||
UserNetworkVariableSerialization<MyTypeOne>.DuplicateValue = null;
|
||||
UserNetworkVariableSerialization<MyTypeTwo>.WriteValue = null;
|
||||
UserNetworkVariableSerialization<MyTypeTwo>.ReadValue = null;
|
||||
UserNetworkVariableSerialization<MyTypeTwo>.DuplicateValue = null;
|
||||
UserNetworkVariableSerialization<MyTypeThree>.WriteValue = null;
|
||||
UserNetworkVariableSerialization<MyTypeThree>.ReadValue = null;
|
||||
UserNetworkVariableSerialization<MyTypeThree>.DuplicateValue = null;
|
||||
return base.OnSetup();
|
||||
}
|
||||
|
||||
@@ -217,5 +227,36 @@ namespace Unity.Netcode.RuntimeTests
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
protected override IEnumerator OnTearDown()
|
||||
{
|
||||
// These have to get set to SOMETHING, otherwise we will get an exception thrown because Object.Destroy()
|
||||
// calls __initializeNetworkVariables, and the network variable initialization attempts to call FallbackSerializer<T>,
|
||||
// which throws an exception if any of these values are null. They don't have to DO anything, they just have to
|
||||
// be non-null to keep the test from failing during teardown.
|
||||
// None of this is related to what's being tested above, and in reality, these values being null is an invalid
|
||||
// use case. But one of the tests is explicitly testing that invalid use case, and the values are being set
|
||||
// to null in OnSetup to ensure test isolation. This wouldn't be a situation a user would have to think about
|
||||
// in a real world use case.
|
||||
UserNetworkVariableSerialization<MyTypeOne>.WriteValue = (FastBufferWriter writer, in MyTypeOne value) => { };
|
||||
UserNetworkVariableSerialization<MyTypeOne>.ReadValue = (FastBufferReader reader, out MyTypeOne value) => { value = new MyTypeOne(); };
|
||||
UserNetworkVariableSerialization<MyTypeOne>.DuplicateValue = (in MyTypeOne value, ref MyTypeOne duplicatedValue) =>
|
||||
{
|
||||
duplicatedValue = value;
|
||||
};
|
||||
UserNetworkVariableSerialization<MyTypeTwo>.WriteValue = (FastBufferWriter writer, in MyTypeTwo value) => { };
|
||||
UserNetworkVariableSerialization<MyTypeTwo>.ReadValue = (FastBufferReader reader, out MyTypeTwo value) => { value = new MyTypeTwo(); };
|
||||
UserNetworkVariableSerialization<MyTypeTwo>.DuplicateValue = (in MyTypeTwo value, ref MyTypeTwo duplicatedValue) =>
|
||||
{
|
||||
duplicatedValue = value;
|
||||
};
|
||||
UserNetworkVariableSerialization<MyTypeThree>.WriteValue = (FastBufferWriter writer, in MyTypeThree value) => { };
|
||||
UserNetworkVariableSerialization<MyTypeThree>.ReadValue = (FastBufferReader reader, out MyTypeThree value) => { value = new MyTypeThree(); };
|
||||
UserNetworkVariableSerialization<MyTypeThree>.DuplicateValue = (in MyTypeThree value, ref MyTypeThree duplicatedValue) =>
|
||||
{
|
||||
duplicatedValue = value;
|
||||
};
|
||||
return base.OnTearDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -17,6 +17,8 @@ namespace Unity.Netcode.RuntimeTests
|
||||
{
|
||||
private class TestNetworkBehaviour : NetworkBehaviour
|
||||
{
|
||||
public static bool ReceivedRPC;
|
||||
|
||||
public NetworkVariable<NetworkBehaviourReference> TestVariable = new NetworkVariable<NetworkBehaviourReference>();
|
||||
|
||||
public TestNetworkBehaviour RpcReceivedBehaviour;
|
||||
@@ -25,6 +27,7 @@ namespace Unity.Netcode.RuntimeTests
|
||||
public void SendReferenceServerRpc(NetworkBehaviourReference value)
|
||||
{
|
||||
RpcReceivedBehaviour = (TestNetworkBehaviour)value;
|
||||
ReceivedRPC = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,8 +60,43 @@ namespace Unity.Netcode.RuntimeTests
|
||||
Assert.AreEqual(testNetworkBehaviour, testNetworkBehaviour.RpcReceivedBehaviour);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator TestSerializeNull([Values] bool initializeWithNull)
|
||||
{
|
||||
TestNetworkBehaviour.ReceivedRPC = false;
|
||||
using var networkObjectContext = UnityObjectContext.CreateNetworkObject();
|
||||
var testNetworkBehaviour = networkObjectContext.Object.gameObject.AddComponent<TestNetworkBehaviour>();
|
||||
networkObjectContext.Object.Spawn();
|
||||
|
||||
using var otherObjectContext = UnityObjectContext.CreateNetworkObject();
|
||||
otherObjectContext.Object.Spawn();
|
||||
|
||||
// If not initializing with null, then use the default constructor with no assigned NetworkBehaviour
|
||||
if (!initializeWithNull)
|
||||
{
|
||||
testNetworkBehaviour.SendReferenceServerRpc(new NetworkBehaviourReference());
|
||||
}
|
||||
else // Otherwise, initialize and pass in null as the reference
|
||||
{
|
||||
testNetworkBehaviour.SendReferenceServerRpc(new NetworkBehaviourReference(null));
|
||||
}
|
||||
|
||||
// wait for rpc completion
|
||||
float t = 0;
|
||||
while (!TestNetworkBehaviour.ReceivedRPC)
|
||||
{
|
||||
t += Time.deltaTime;
|
||||
if (t > 5f)
|
||||
{
|
||||
new AssertionException("RPC with NetworkBehaviour reference hasn't been received");
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
// validate
|
||||
Assert.AreEqual(null, testNetworkBehaviour.RpcReceivedBehaviour);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator TestRpcImplicitNetworkBehaviour()
|
||||
@@ -89,6 +127,7 @@ namespace Unity.Netcode.RuntimeTests
|
||||
Assert.AreEqual(testNetworkBehaviour, testNetworkBehaviour.RpcReceivedBehaviour);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void TestNetworkVariable()
|
||||
{
|
||||
@@ -131,15 +170,6 @@ namespace Unity.Netcode.RuntimeTests
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FailSerializeNullBehaviour()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() =>
|
||||
{
|
||||
NetworkBehaviourReference outReference = null;
|
||||
});
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
//Stop, shutdown, and destroy
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace Unity.Netcode.RuntimeTests
|
||||
{
|
||||
private class TestNetworkBehaviour : NetworkBehaviour
|
||||
{
|
||||
public static bool ReceivedRPC;
|
||||
public NetworkVariable<NetworkObjectReference> TestVariable = new NetworkVariable<NetworkObjectReference>();
|
||||
|
||||
public NetworkObject RpcReceivedNetworkObject;
|
||||
@@ -28,6 +29,7 @@ namespace Unity.Netcode.RuntimeTests
|
||||
[ServerRpc]
|
||||
public void SendReferenceServerRpc(NetworkObjectReference value)
|
||||
{
|
||||
ReceivedRPC = true;
|
||||
RpcReceivedGameObject = value;
|
||||
RpcReceivedNetworkObject = value;
|
||||
}
|
||||
@@ -150,6 +152,60 @@ namespace Unity.Netcode.RuntimeTests
|
||||
Assert.AreEqual(networkObject, result);
|
||||
}
|
||||
|
||||
public enum NetworkObjectConstructorTypes
|
||||
{
|
||||
None,
|
||||
NullNetworkObject,
|
||||
NullGameObject
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator TestSerializeNull([Values] NetworkObjectConstructorTypes networkObjectConstructorTypes)
|
||||
{
|
||||
TestNetworkBehaviour.ReceivedRPC = false;
|
||||
using var networkObjectContext = UnityObjectContext.CreateNetworkObject();
|
||||
var testNetworkBehaviour = networkObjectContext.Object.gameObject.AddComponent<TestNetworkBehaviour>();
|
||||
networkObjectContext.Object.Spawn();
|
||||
|
||||
switch (networkObjectConstructorTypes)
|
||||
{
|
||||
case NetworkObjectConstructorTypes.None:
|
||||
{
|
||||
testNetworkBehaviour.SendReferenceServerRpc(new NetworkObjectReference());
|
||||
break;
|
||||
}
|
||||
case NetworkObjectConstructorTypes.NullNetworkObject:
|
||||
{
|
||||
testNetworkBehaviour.SendReferenceServerRpc(new NetworkObjectReference((NetworkObject)null));
|
||||
break;
|
||||
}
|
||||
case NetworkObjectConstructorTypes.NullGameObject:
|
||||
{
|
||||
testNetworkBehaviour.SendReferenceServerRpc(new NetworkObjectReference((GameObject)null));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// wait for rpc completion
|
||||
float t = 0;
|
||||
while (!TestNetworkBehaviour.ReceivedRPC)
|
||||
{
|
||||
|
||||
t += Time.deltaTime;
|
||||
if (t > 5f)
|
||||
{
|
||||
new AssertionException("RPC with NetworkBehaviour reference hasn't been received");
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
// validate
|
||||
Assert.AreEqual(null, testNetworkBehaviour.RpcReceivedNetworkObject);
|
||||
Assert.AreEqual(null, testNetworkBehaviour.RpcReceivedGameObject);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator TestRpc()
|
||||
{
|
||||
@@ -305,24 +361,6 @@ namespace Unity.Netcode.RuntimeTests
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FailSerializeNullNetworkObject()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() =>
|
||||
{
|
||||
NetworkObjectReference outReference = (NetworkObject)null;
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FailSerializeNullGameObject()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() =>
|
||||
{
|
||||
NetworkObjectReference outReference = (GameObject)null;
|
||||
});
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
//Stop, shutdown, and destroy
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#if !MULTIPLAYER_TOOLS && !NGO_MINIMALPROJECT
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
@@ -7,6 +9,7 @@ using NUnit.Framework;
|
||||
using Unity.Collections;
|
||||
using Unity.Netcode.TestHelpers.Runtime;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using Object = UnityEngine.Object;
|
||||
using Random = System.Random;
|
||||
|
||||
@@ -24,6 +27,7 @@ namespace Unity.Netcode.RuntimeTests.UniversalRpcTests
|
||||
public string Received = string.Empty;
|
||||
public Tuple<int, bool, float, string> ReceivedParams = null;
|
||||
public ulong ReceivedFrom = ulong.MaxValue;
|
||||
public int ReceivedCount;
|
||||
|
||||
public void OnRpcReceived()
|
||||
{
|
||||
@@ -32,6 +36,7 @@ namespace Unity.Netcode.RuntimeTests.UniversalRpcTests
|
||||
|
||||
var currentMethod = sf.GetMethod();
|
||||
Received = currentMethod.Name;
|
||||
ReceivedCount++;
|
||||
}
|
||||
public void OnRpcReceivedWithParams(int a, bool b, float f, string s)
|
||||
{
|
||||
@@ -40,6 +45,7 @@ namespace Unity.Netcode.RuntimeTests.UniversalRpcTests
|
||||
|
||||
var currentMethod = sf.GetMethod();
|
||||
Received = currentMethod.Name;
|
||||
ReceivedCount++;
|
||||
ReceivedParams = new Tuple<int, bool, float, string>(a, b, f, s);
|
||||
}
|
||||
|
||||
@@ -448,6 +454,9 @@ namespace Unity.Netcode.RuntimeTests.UniversalRpcTests
|
||||
|
||||
public class UniversalRpcTestsBase : NetcodeIntegrationTest
|
||||
{
|
||||
public static int YieldCheck = 0;
|
||||
public const int YieldCycleCount = 10;
|
||||
|
||||
protected override int NumberOfClients => 2;
|
||||
|
||||
public UniversalRpcTestsBase(HostOrServer hostOrServer) : base(hostOrServer)
|
||||
@@ -488,6 +497,7 @@ namespace Unity.Netcode.RuntimeTests.UniversalRpcTests
|
||||
|
||||
protected override void OnInlineTearDown()
|
||||
{
|
||||
MockTransport.ClearQueues();
|
||||
Clear();
|
||||
}
|
||||
|
||||
@@ -496,6 +506,7 @@ namespace Unity.Netcode.RuntimeTests.UniversalRpcTests
|
||||
foreach (var obj in Object.FindObjectsByType<UniversalRpcNetworkBehaviour>(FindObjectsSortMode.None))
|
||||
{
|
||||
obj.Received = string.Empty;
|
||||
obj.ReceivedCount = 0;
|
||||
obj.ReceivedParams = null;
|
||||
obj.ReceivedFrom = ulong.MaxValue;
|
||||
}
|
||||
@@ -528,10 +539,11 @@ namespace Unity.Netcode.RuntimeTests.UniversalRpcTests
|
||||
return m_PlayerNetworkObjects[onClient][ownerClientId].GetComponent<UniversalRpcNetworkBehaviour>();
|
||||
}
|
||||
|
||||
protected void VerifyLocalReceived(ulong objectOwner, ulong sender, string name, bool verifyReceivedFrom)
|
||||
protected void VerifyLocalReceived(ulong objectOwner, ulong sender, string name, bool verifyReceivedFrom, int expectedReceived = 1)
|
||||
{
|
||||
var obj = GetPlayerObject(objectOwner, sender);
|
||||
Assert.AreEqual(name, obj.Received);
|
||||
Assert.That(obj.ReceivedCount, Is.EqualTo(expectedReceived));
|
||||
Assert.IsNull(obj.ReceivedParams);
|
||||
if (verifyReceivedFrom)
|
||||
{
|
||||
@@ -543,6 +555,7 @@ namespace Unity.Netcode.RuntimeTests.UniversalRpcTests
|
||||
{
|
||||
var obj = GetPlayerObject(objectOwner, sender);
|
||||
Assert.AreEqual(name, obj.Received);
|
||||
Assert.That(obj.ReceivedCount, Is.EqualTo(1));
|
||||
Assert.IsNotNull(obj.ReceivedParams);
|
||||
Assert.AreEqual(i, obj.ReceivedParams.Item1);
|
||||
Assert.AreEqual(b, obj.ReceivedParams.Item2);
|
||||
@@ -556,17 +569,18 @@ namespace Unity.Netcode.RuntimeTests.UniversalRpcTests
|
||||
{
|
||||
UniversalRpcNetworkBehaviour playerObject = GetPlayerObject(objectOwner, client);
|
||||
Assert.AreEqual(string.Empty, playerObject.Received);
|
||||
Assert.That(playerObject.ReceivedCount, Is.EqualTo(0));
|
||||
Assert.IsNull(playerObject.ReceivedParams);
|
||||
}
|
||||
}
|
||||
|
||||
protected void VerifyRemoteReceived(ulong objectOwner, ulong sender, string message, ulong[] receivedBy, bool verifyReceivedFrom, bool waitForMessages = true)
|
||||
protected void VerifyRemoteReceived(ulong objectOwner, ulong sender, string message, ulong[] receivedBy, bool verifyReceivedFrom, bool waitForMessages = true, int expectedReceived = 1)
|
||||
{
|
||||
foreach (var client in receivedBy)
|
||||
{
|
||||
if (client == sender)
|
||||
{
|
||||
VerifyLocalReceived(objectOwner, sender, message, verifyReceivedFrom);
|
||||
VerifyLocalReceived(objectOwner, sender, message, verifyReceivedFrom, expectedReceived);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -628,6 +642,7 @@ namespace Unity.Netcode.RuntimeTests.UniversalRpcTests
|
||||
{
|
||||
UniversalRpcNetworkBehaviour playerObject = GetPlayerObject(objectOwner, client);
|
||||
Assert.AreEqual(message, playerObject.Received);
|
||||
Assert.That(playerObject.ReceivedCount, Is.EqualTo(expectedReceived));
|
||||
Assert.IsNull(playerObject.ReceivedParams);
|
||||
if (verifyReceivedFrom)
|
||||
{
|
||||
@@ -701,6 +716,7 @@ namespace Unity.Netcode.RuntimeTests.UniversalRpcTests
|
||||
{
|
||||
UniversalRpcNetworkBehaviour playerObject = GetPlayerObject(objectOwner, client);
|
||||
Assert.AreEqual(message, playerObject.Received);
|
||||
Assert.That(playerObject.ReceivedCount, Is.EqualTo(1));
|
||||
|
||||
Assert.IsNotNull(playerObject.ReceivedParams);
|
||||
Assert.AreEqual(i, playerObject.ReceivedParams.Item1);
|
||||
@@ -1159,27 +1175,40 @@ namespace Unity.Netcode.RuntimeTests.UniversalRpcTests
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSendingWithSingleOverride(
|
||||
[Values] SendTo defaultSendTo,
|
||||
[Values(0u, 1u, 2u)] ulong recipient,
|
||||
[Values(0u, 1u, 2u)] ulong objectOwner,
|
||||
[Values(0u, 1u, 2u)] ulong sender
|
||||
)
|
||||
[UnityTest]
|
||||
public IEnumerator TestSendingWithSingleOverride()
|
||||
{
|
||||
var sendMethodName = $"DefaultTo{defaultSendTo}AllowOverrideRpc";
|
||||
foreach (var defaultSendTo in Enum.GetValues(typeof(SendTo)))
|
||||
{
|
||||
for (ulong recipient = 0u; recipient <= 2u; ++recipient)
|
||||
{
|
||||
for (ulong objectOwner = 0u; objectOwner <= 2u; ++objectOwner)
|
||||
{
|
||||
for (ulong sender = 0u; sender <= 2u; ++sender)
|
||||
{
|
||||
if (++YieldCheck % YieldCycleCount == 0)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
OnInlineSetup();
|
||||
var sendMethodName = $"DefaultTo{defaultSendTo}AllowOverrideRpc";
|
||||
|
||||
var senderObject = GetPlayerObject(objectOwner, sender);
|
||||
var target = senderObject.RpcTarget.Single(recipient, RpcTargetUse.Temp);
|
||||
var sendMethod = senderObject.GetType().GetMethod(sendMethodName);
|
||||
sendMethod.Invoke(senderObject, new object[] { (RpcParams)target });
|
||||
var senderObject = GetPlayerObject(objectOwner, sender);
|
||||
var target = senderObject.RpcTarget.Single(recipient, RpcTargetUse.Temp);
|
||||
var sendMethod = senderObject.GetType().GetMethod(sendMethodName);
|
||||
sendMethod.Invoke(senderObject, new object[] { (RpcParams)target });
|
||||
|
||||
VerifyRemoteReceived(objectOwner, sender, sendMethodName, new[] { recipient }, false);
|
||||
VerifyNotReceived(objectOwner, s_ClientIds.Where(c => recipient != c).ToArray());
|
||||
VerifyRemoteReceived(objectOwner, sender, sendMethodName, new[] { recipient }, false);
|
||||
VerifyNotReceived(objectOwner, s_ClientIds.Where(c => recipient != c).ToArray());
|
||||
|
||||
// Pass some time to make sure that no other client ever receives this
|
||||
TimeTravel(1f, 30);
|
||||
VerifyNotReceived(objectOwner, s_ClientIds.Where(c => recipient != c).ToArray());
|
||||
// Pass some time to make sure that no other client ever receives this
|
||||
TimeTravel(1f, 30);
|
||||
VerifyNotReceived(objectOwner, s_ClientIds.Where(c => recipient != c).ToArray());
|
||||
OnInlineTearDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1193,27 +1222,40 @@ namespace Unity.Netcode.RuntimeTests.UniversalRpcTests
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSendingWithSingleNotOverride(
|
||||
[Values] SendTo defaultSendTo,
|
||||
[Values(0u, 1u, 2u)] ulong recipient,
|
||||
[Values(0u, 1u, 2u)] ulong objectOwner,
|
||||
[Values(0u, 1u, 2u)] ulong sender
|
||||
)
|
||||
[UnityTest]
|
||||
public IEnumerator TestSendingWithSingleNotOverride()
|
||||
{
|
||||
var sendMethodName = $"DefaultTo{defaultSendTo}AllowOverrideRpc";
|
||||
foreach (var defaultSendTo in Enum.GetValues(typeof(SendTo)))
|
||||
{
|
||||
for (ulong recipient = 0u; recipient <= 2u; ++recipient)
|
||||
{
|
||||
for (ulong objectOwner = 0u; objectOwner <= 2u; ++objectOwner)
|
||||
{
|
||||
for (ulong sender = 0u; sender <= 2u; ++sender)
|
||||
{
|
||||
if (++YieldCheck % YieldCycleCount == 0)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
OnInlineSetup();
|
||||
var sendMethodName = $"DefaultTo{defaultSendTo}AllowOverrideRpc";
|
||||
|
||||
var senderObject = GetPlayerObject(objectOwner, sender);
|
||||
var target = senderObject.RpcTarget.Not(recipient, RpcTargetUse.Temp);
|
||||
var sendMethod = senderObject.GetType().GetMethod(sendMethodName);
|
||||
sendMethod.Invoke(senderObject, new object[] { (RpcParams)target });
|
||||
var senderObject = GetPlayerObject(objectOwner, sender);
|
||||
var target = senderObject.RpcTarget.Not(recipient, RpcTargetUse.Temp);
|
||||
var sendMethod = senderObject.GetType().GetMethod(sendMethodName);
|
||||
sendMethod.Invoke(senderObject, new object[] { (RpcParams)target });
|
||||
|
||||
VerifyRemoteReceived(objectOwner, sender, sendMethodName, s_ClientIds.Where(c => recipient != c).ToArray(), false);
|
||||
VerifyNotReceived(objectOwner, new[] { recipient });
|
||||
VerifyRemoteReceived(objectOwner, sender, sendMethodName, s_ClientIds.Where(c => recipient != c).ToArray(), false);
|
||||
VerifyNotReceived(objectOwner, new[] { recipient });
|
||||
|
||||
// Pass some time to make sure that no other client ever receives this
|
||||
TimeTravel(1f, 30);
|
||||
VerifyNotReceived(objectOwner, new[] { recipient });
|
||||
// Pass some time to make sure that no other client ever receives this
|
||||
TimeTravel(1f, 30);
|
||||
VerifyNotReceived(objectOwner, new[] { recipient });
|
||||
OnInlineTearDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1243,56 +1285,80 @@ namespace Unity.Netcode.RuntimeTests.UniversalRpcTests
|
||||
List
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSendingWithGroupOverride(
|
||||
[Values] SendTo defaultSendTo,
|
||||
[ValueSource(nameof(RecipientGroups))] ulong[] recipient,
|
||||
[Values(0u, 1u, 2u)] ulong objectOwner,
|
||||
[Values(0u, 1u, 2u)] ulong sender,
|
||||
[Values] AllocationType allocationType
|
||||
)
|
||||
// Extending timeout since the added yield return causes this test to commonly timeout
|
||||
[Timeout(600000)]
|
||||
[UnityTest]
|
||||
public IEnumerator TestSendingWithGroupOverride()
|
||||
{
|
||||
var sendMethodName = $"DefaultTo{defaultSendTo}AllowOverrideRpc";
|
||||
|
||||
var senderObject = GetPlayerObject(objectOwner, sender);
|
||||
BaseRpcTarget target = null;
|
||||
switch (allocationType)
|
||||
var waitFor = new WaitForFixedUpdate();
|
||||
foreach (var defaultSendTo in Enum.GetValues(typeof(SendTo)))
|
||||
{
|
||||
case AllocationType.Array:
|
||||
target = senderObject.RpcTarget.Group(recipient, RpcTargetUse.Temp);
|
||||
break;
|
||||
case AllocationType.List:
|
||||
target = senderObject.RpcTarget.Group(recipient.ToList(), RpcTargetUse.Temp);
|
||||
break;
|
||||
case AllocationType.NativeArray:
|
||||
var arr = new NativeArray<ulong>(recipient, Allocator.Temp);
|
||||
target = senderObject.RpcTarget.Group(arr, RpcTargetUse.Temp);
|
||||
arr.Dispose();
|
||||
break;
|
||||
case AllocationType.NativeList:
|
||||
// For some reason on 2020.3, calling list.AsArray() and passing that to the next function
|
||||
// causes Allocator.Temp allocations to become invalid somehow. This is not an issue on later
|
||||
// versions of Unity.
|
||||
var list = new NativeList<ulong>(recipient.Length, Allocator.TempJob);
|
||||
foreach (var id in recipient)
|
||||
m_EnableVerboseDebug = true;
|
||||
VerboseDebug($"Processing: {defaultSendTo}");
|
||||
m_EnableVerboseDebug = false;
|
||||
|
||||
foreach (var recipient in RecipientGroups)
|
||||
{
|
||||
for (ulong objectOwner = 0u; objectOwner <= 2u; ++objectOwner)
|
||||
{
|
||||
list.Add(id);
|
||||
for (ulong sender = 0u; sender <= 2u; ++sender)
|
||||
{
|
||||
yield return waitFor;
|
||||
foreach (var allocationType in Enum.GetValues(typeof(AllocationType)))
|
||||
{
|
||||
//if (++YieldCheck % YieldCycleCount == 0)
|
||||
//{
|
||||
// yield return null;
|
||||
//}
|
||||
OnInlineSetup();
|
||||
var sendMethodName = $"DefaultTo{defaultSendTo}AllowOverrideRpc";
|
||||
|
||||
var senderObject = GetPlayerObject(objectOwner, sender);
|
||||
BaseRpcTarget target = null;
|
||||
switch (allocationType)
|
||||
{
|
||||
case AllocationType.Array:
|
||||
target = senderObject.RpcTarget.Group(recipient, RpcTargetUse.Temp);
|
||||
break;
|
||||
case AllocationType.List:
|
||||
target = senderObject.RpcTarget.Group(recipient.ToList(), RpcTargetUse.Temp);
|
||||
break;
|
||||
case AllocationType.NativeArray:
|
||||
var arr = new NativeArray<ulong>(recipient, Allocator.Temp);
|
||||
target = senderObject.RpcTarget.Group(arr, RpcTargetUse.Temp);
|
||||
arr.Dispose();
|
||||
break;
|
||||
case AllocationType.NativeList:
|
||||
// For some reason on 2020.3, calling list.AsArray() and passing that to the next function
|
||||
// causes Allocator.Temp allocations to become invalid somehow. This is not an issue on later
|
||||
// versions of Unity.
|
||||
var list = new NativeList<ulong>(recipient.Length, Allocator.TempJob);
|
||||
foreach (var id in recipient)
|
||||
{
|
||||
list.Add(id);
|
||||
}
|
||||
|
||||
target = senderObject.RpcTarget.Group(list, RpcTargetUse.Temp);
|
||||
list.Dispose();
|
||||
break;
|
||||
}
|
||||
|
||||
var sendMethod = senderObject.GetType().GetMethod(sendMethodName);
|
||||
sendMethod.Invoke(senderObject, new object[] { (RpcParams)target });
|
||||
|
||||
VerifyRemoteReceived(objectOwner, sender, sendMethodName, s_ClientIds.Where(c => recipient.Contains(c)).ToArray(), false);
|
||||
VerifyNotReceived(objectOwner, s_ClientIds.Where(c => !recipient.Contains(c)).ToArray());
|
||||
|
||||
// Pass some time to make sure that no other client ever receives this
|
||||
TimeTravel(1f, 30);
|
||||
VerifyNotReceived(objectOwner, s_ClientIds.Where(c => !recipient.Contains(c)).ToArray());
|
||||
OnInlineTearDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
target = senderObject.RpcTarget.Group(list, RpcTargetUse.Temp);
|
||||
list.Dispose();
|
||||
break;
|
||||
}
|
||||
}
|
||||
var sendMethod = senderObject.GetType().GetMethod(sendMethodName);
|
||||
sendMethod.Invoke(senderObject, new object[] { (RpcParams)target });
|
||||
|
||||
VerifyRemoteReceived(objectOwner, sender, sendMethodName, s_ClientIds.Where(c => recipient.Contains(c)).ToArray(), false);
|
||||
VerifyNotReceived(objectOwner, s_ClientIds.Where(c => !recipient.Contains(c)).ToArray());
|
||||
|
||||
// Pass some time to make sure that no other client ever receives this
|
||||
TimeTravel(1f, 30);
|
||||
VerifyNotReceived(objectOwner, s_ClientIds.Where(c => !recipient.Contains(c)).ToArray());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[TestFixture(HostOrServer.Host)]
|
||||
@@ -1320,54 +1386,78 @@ namespace Unity.Netcode.RuntimeTests.UniversalRpcTests
|
||||
List
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSendingWithGroupNotOverride(
|
||||
[Values] SendTo defaultSendTo,
|
||||
[ValueSource(nameof(RecipientGroups))] ulong[] recipient,
|
||||
[Values(0u, 1u, 2u)] ulong objectOwner,
|
||||
[Values(0u, 1u, 2u)] ulong sender,
|
||||
[Values] AllocationType allocationType
|
||||
)
|
||||
// Extending timeout since the added yield return causes this test to commonly timeout
|
||||
[Timeout(600000)]
|
||||
[UnityTest]
|
||||
public IEnumerator TestSendingWithGroupNotOverride()
|
||||
{
|
||||
var sendMethodName = $"DefaultTo{defaultSendTo}AllowOverrideRpc";
|
||||
|
||||
var senderObject = GetPlayerObject(objectOwner, sender);
|
||||
BaseRpcTarget target = null;
|
||||
switch (allocationType)
|
||||
var waitFor = new WaitForFixedUpdate();
|
||||
foreach (var defaultSendTo in Enum.GetValues(typeof(SendTo)))
|
||||
{
|
||||
case AllocationType.Array:
|
||||
target = senderObject.RpcTarget.Not(recipient, RpcTargetUse.Temp);
|
||||
break;
|
||||
case AllocationType.List:
|
||||
target = senderObject.RpcTarget.Not(recipient.ToList(), RpcTargetUse.Temp);
|
||||
break;
|
||||
case AllocationType.NativeArray:
|
||||
var arr = new NativeArray<ulong>(recipient, Allocator.Temp);
|
||||
target = senderObject.RpcTarget.Not(arr, RpcTargetUse.Temp);
|
||||
arr.Dispose();
|
||||
break;
|
||||
case AllocationType.NativeList:
|
||||
// For some reason on 2020.3, calling list.AsArray() and passing that to the next function
|
||||
// causes Allocator.Temp allocations to become invalid somehow. This is not an issue on later
|
||||
// versions of Unity.
|
||||
var list = new NativeList<ulong>(recipient.Length, Allocator.TempJob);
|
||||
foreach (var id in recipient)
|
||||
m_EnableVerboseDebug = true;
|
||||
VerboseDebug($"Processing: {defaultSendTo}");
|
||||
m_EnableVerboseDebug = false;
|
||||
foreach (var recipient in RecipientGroups)
|
||||
{
|
||||
for (ulong objectOwner = 0u; objectOwner <= 2u; ++objectOwner)
|
||||
{
|
||||
list.Add(id);
|
||||
for (ulong sender = 0u; sender <= 2u; ++sender)
|
||||
{
|
||||
yield return waitFor;
|
||||
|
||||
foreach (var allocationType in Enum.GetValues(typeof(AllocationType)))
|
||||
{
|
||||
//if (++YieldCheck % YieldCycleCount == 0)
|
||||
//{
|
||||
// yield return waitFor;
|
||||
//}
|
||||
|
||||
OnInlineSetup();
|
||||
var sendMethodName = $"DefaultTo{defaultSendTo}AllowOverrideRpc";
|
||||
|
||||
var senderObject = GetPlayerObject(objectOwner, sender);
|
||||
BaseRpcTarget target = null;
|
||||
switch (allocationType)
|
||||
{
|
||||
case AllocationType.Array:
|
||||
target = senderObject.RpcTarget.Not(recipient, RpcTargetUse.Temp);
|
||||
break;
|
||||
case AllocationType.List:
|
||||
target = senderObject.RpcTarget.Not(recipient.ToList(), RpcTargetUse.Temp);
|
||||
break;
|
||||
case AllocationType.NativeArray:
|
||||
var arr = new NativeArray<ulong>(recipient, Allocator.Temp);
|
||||
target = senderObject.RpcTarget.Not(arr, RpcTargetUse.Temp);
|
||||
arr.Dispose();
|
||||
break;
|
||||
case AllocationType.NativeList:
|
||||
// For some reason on 2020.3, calling list.AsArray() and passing that to the next function
|
||||
// causes Allocator.Temp allocations to become invalid somehow. This is not an issue on later
|
||||
// versions of Unity.
|
||||
var list = new NativeList<ulong>(recipient.Length, Allocator.TempJob);
|
||||
foreach (var id in recipient)
|
||||
{
|
||||
list.Add(id);
|
||||
}
|
||||
target = senderObject.RpcTarget.Not(list, RpcTargetUse.Temp);
|
||||
list.Dispose();
|
||||
break;
|
||||
}
|
||||
var sendMethod = senderObject.GetType().GetMethod(sendMethodName);
|
||||
sendMethod.Invoke(senderObject, new object[] { (RpcParams)target });
|
||||
|
||||
VerifyRemoteReceived(objectOwner, sender, sendMethodName, s_ClientIds.Where(c => !recipient.Contains(c)).ToArray(), false);
|
||||
VerifyNotReceived(objectOwner, s_ClientIds.Where(c => recipient.Contains(c)).ToArray());
|
||||
|
||||
// Pass some time to make sure that no other client ever receives this
|
||||
TimeTravel(1f, 30);
|
||||
VerifyNotReceived(objectOwner, s_ClientIds.Where(c => recipient.Contains(c)).ToArray());
|
||||
OnInlineTearDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
target = senderObject.RpcTarget.Not(list, RpcTargetUse.Temp);
|
||||
list.Dispose();
|
||||
break;
|
||||
}
|
||||
}
|
||||
var sendMethod = senderObject.GetType().GetMethod(sendMethodName);
|
||||
sendMethod.Invoke(senderObject, new object[] { (RpcParams)target });
|
||||
|
||||
VerifyRemoteReceived(objectOwner, sender, sendMethodName, s_ClientIds.Where(c => !recipient.Contains(c)).ToArray(), false);
|
||||
VerifyNotReceived(objectOwner, s_ClientIds.Where(c => recipient.Contains(c)).ToArray());
|
||||
|
||||
// Pass some time to make sure that no other client ever receives this
|
||||
TimeTravel(1f, 30);
|
||||
VerifyNotReceived(objectOwner, s_ClientIds.Where(c => recipient.Contains(c)).ToArray());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1391,223 +1481,180 @@ namespace Unity.Netcode.RuntimeTests.UniversalRpcTests
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
// All the test cases that involve sends that will be delivered locally
|
||||
[TestCase(SendTo.Everyone, 0u, 0u)]
|
||||
[TestCase(SendTo.Everyone, 0u, 1u)]
|
||||
[TestCase(SendTo.Everyone, 0u, 2u)]
|
||||
[TestCase(SendTo.Everyone, 1u, 0u)]
|
||||
[TestCase(SendTo.Everyone, 1u, 1u)]
|
||||
[TestCase(SendTo.Everyone, 1u, 2u)]
|
||||
[TestCase(SendTo.Everyone, 2u, 0u)]
|
||||
[TestCase(SendTo.Everyone, 2u, 1u)]
|
||||
[TestCase(SendTo.Everyone, 2u, 2u)]
|
||||
[TestCase(SendTo.Me, 0u, 0u)]
|
||||
[TestCase(SendTo.Me, 0u, 1u)]
|
||||
[TestCase(SendTo.Me, 0u, 2u)]
|
||||
[TestCase(SendTo.Me, 1u, 0u)]
|
||||
[TestCase(SendTo.Me, 1u, 1u)]
|
||||
[TestCase(SendTo.Me, 1u, 2u)]
|
||||
[TestCase(SendTo.Me, 2u, 0u)]
|
||||
[TestCase(SendTo.Me, 2u, 1u)]
|
||||
[TestCase(SendTo.Me, 2u, 2u)]
|
||||
[TestCase(SendTo.Owner, 0u, 0u)]
|
||||
[TestCase(SendTo.Owner, 1u, 1u)]
|
||||
[TestCase(SendTo.Owner, 2u, 2u)]
|
||||
[TestCase(SendTo.Server, 0u, 0u)]
|
||||
[TestCase(SendTo.Server, 1u, 0u)]
|
||||
[TestCase(SendTo.Server, 2u, 0u)]
|
||||
[TestCase(SendTo.NotOwner, 0u, 1u)]
|
||||
[TestCase(SendTo.NotOwner, 0u, 2u)]
|
||||
[TestCase(SendTo.NotOwner, 1u, 0u)]
|
||||
[TestCase(SendTo.NotOwner, 1u, 2u)]
|
||||
[TestCase(SendTo.NotOwner, 2u, 0u)]
|
||||
[TestCase(SendTo.NotOwner, 2u, 1u)]
|
||||
[TestCase(SendTo.NotServer, 0u, 1u)]
|
||||
[TestCase(SendTo.NotServer, 0u, 2u)]
|
||||
[TestCase(SendTo.NotServer, 1u, 1u)]
|
||||
[TestCase(SendTo.NotServer, 1u, 2u)]
|
||||
[TestCase(SendTo.NotServer, 2u, 1u)]
|
||||
[TestCase(SendTo.NotServer, 2u, 2u)]
|
||||
[TestCase(SendTo.ClientsAndHost, 0u, 0u)]
|
||||
[TestCase(SendTo.ClientsAndHost, 0u, 1u)]
|
||||
[TestCase(SendTo.ClientsAndHost, 0u, 2u)]
|
||||
[TestCase(SendTo.ClientsAndHost, 1u, 0u)]
|
||||
[TestCase(SendTo.ClientsAndHost, 1u, 1u)]
|
||||
[TestCase(SendTo.ClientsAndHost, 1u, 2u)]
|
||||
[TestCase(SendTo.ClientsAndHost, 2u, 0u)]
|
||||
[TestCase(SendTo.ClientsAndHost, 2u, 1u)]
|
||||
[TestCase(SendTo.ClientsAndHost, 2u, 2u)]
|
||||
public void TestDeferLocal(
|
||||
SendTo defaultSendTo,
|
||||
ulong objectOwner,
|
||||
ulong sender
|
||||
)
|
||||
private struct TestData
|
||||
{
|
||||
if (defaultSendTo == SendTo.ClientsAndHost && sender == 0u && !m_ServerNetworkManager.IsHost)
|
||||
public SendTo SendTo;
|
||||
public ulong ObjectOwner;
|
||||
public ulong Sender;
|
||||
|
||||
public TestData(SendTo sendTo, ulong objectOwner, ulong sender)
|
||||
{
|
||||
// Not calling Assert.Ignore() because Unity will mark the whole block of tests as ignored
|
||||
// Just consider this case a success...
|
||||
return;
|
||||
SendTo = sendTo;
|
||||
ObjectOwner = objectOwner;
|
||||
Sender = sender;
|
||||
}
|
||||
var sendMethodName = $"DefaultTo{defaultSendTo}DeferLocalRpc";
|
||||
var verifyMethodName = $"VerifySentTo{defaultSendTo}";
|
||||
var senderObject = GetPlayerObject(objectOwner, sender);
|
||||
var sendMethod = senderObject.GetType().GetMethod(sendMethodName);
|
||||
sendMethod.Invoke(senderObject, new object[] { new RpcParams() });
|
||||
|
||||
VerifyNotReceived(objectOwner, new[] { sender });
|
||||
// Should be received on the next frame
|
||||
SimulateOneFrame();
|
||||
VerifyLocalReceived(objectOwner, sender, sendMethodName, false);
|
||||
|
||||
var verifyMethod = GetType().GetMethod(verifyMethodName);
|
||||
verifyMethod.Invoke(this, new object[] { objectOwner, sender, sendMethodName });
|
||||
}
|
||||
|
||||
[Test]
|
||||
// All the test cases that involve sends that will be delivered locally
|
||||
[TestCase(SendTo.Everyone, 0u, 0u)]
|
||||
[TestCase(SendTo.Everyone, 0u, 1u)]
|
||||
[TestCase(SendTo.Everyone, 0u, 2u)]
|
||||
[TestCase(SendTo.Everyone, 1u, 0u)]
|
||||
[TestCase(SendTo.Everyone, 1u, 1u)]
|
||||
[TestCase(SendTo.Everyone, 1u, 2u)]
|
||||
[TestCase(SendTo.Everyone, 2u, 0u)]
|
||||
[TestCase(SendTo.Everyone, 2u, 1u)]
|
||||
[TestCase(SendTo.Everyone, 2u, 2u)]
|
||||
[TestCase(SendTo.Me, 0u, 0u)]
|
||||
[TestCase(SendTo.Me, 0u, 1u)]
|
||||
[TestCase(SendTo.Me, 0u, 2u)]
|
||||
[TestCase(SendTo.Me, 1u, 0u)]
|
||||
[TestCase(SendTo.Me, 1u, 1u)]
|
||||
[TestCase(SendTo.Me, 1u, 2u)]
|
||||
[TestCase(SendTo.Me, 2u, 0u)]
|
||||
[TestCase(SendTo.Me, 2u, 1u)]
|
||||
[TestCase(SendTo.Me, 2u, 2u)]
|
||||
[TestCase(SendTo.Owner, 0u, 0u)]
|
||||
[TestCase(SendTo.Owner, 1u, 1u)]
|
||||
[TestCase(SendTo.Owner, 2u, 2u)]
|
||||
[TestCase(SendTo.Server, 0u, 0u)]
|
||||
[TestCase(SendTo.Server, 1u, 0u)]
|
||||
[TestCase(SendTo.Server, 2u, 0u)]
|
||||
[TestCase(SendTo.NotOwner, 0u, 1u)]
|
||||
[TestCase(SendTo.NotOwner, 0u, 2u)]
|
||||
[TestCase(SendTo.NotOwner, 1u, 0u)]
|
||||
[TestCase(SendTo.NotOwner, 1u, 2u)]
|
||||
[TestCase(SendTo.NotOwner, 2u, 0u)]
|
||||
[TestCase(SendTo.NotOwner, 2u, 1u)]
|
||||
[TestCase(SendTo.NotServer, 0u, 1u)]
|
||||
[TestCase(SendTo.NotServer, 0u, 2u)]
|
||||
[TestCase(SendTo.NotServer, 1u, 1u)]
|
||||
[TestCase(SendTo.NotServer, 1u, 2u)]
|
||||
[TestCase(SendTo.NotServer, 2u, 1u)]
|
||||
[TestCase(SendTo.NotServer, 2u, 2u)]
|
||||
[TestCase(SendTo.ClientsAndHost, 0u, 0u)]
|
||||
[TestCase(SendTo.ClientsAndHost, 0u, 1u)]
|
||||
[TestCase(SendTo.ClientsAndHost, 0u, 2u)]
|
||||
[TestCase(SendTo.ClientsAndHost, 1u, 0u)]
|
||||
[TestCase(SendTo.ClientsAndHost, 1u, 1u)]
|
||||
[TestCase(SendTo.ClientsAndHost, 1u, 2u)]
|
||||
[TestCase(SendTo.ClientsAndHost, 2u, 0u)]
|
||||
[TestCase(SendTo.ClientsAndHost, 2u, 1u)]
|
||||
[TestCase(SendTo.ClientsAndHost, 2u, 2u)]
|
||||
public void TestDeferLocalOverrideToTrue(
|
||||
SendTo defaultSendTo,
|
||||
ulong objectOwner,
|
||||
ulong sender
|
||||
)
|
||||
private static TestData[] s_LocalDeliveryTestCases =
|
||||
{
|
||||
if (defaultSendTo == SendTo.ClientsAndHost && sender == 0u && !m_ServerNetworkManager.IsHost)
|
||||
new TestData(SendTo.Everyone, 0u, 0u),
|
||||
new TestData(SendTo.Everyone, 0u, 1u),
|
||||
new TestData(SendTo.Everyone, 0u, 2u),
|
||||
new TestData(SendTo.Everyone, 1u, 0u),
|
||||
new TestData(SendTo.Everyone, 1u, 1u),
|
||||
new TestData(SendTo.Everyone, 1u, 2u),
|
||||
new TestData(SendTo.Everyone, 2u, 0u),
|
||||
new TestData(SendTo.Everyone, 2u, 1u),
|
||||
new TestData(SendTo.Everyone, 2u, 2u),
|
||||
new TestData(SendTo.Me, 0u, 0u),
|
||||
new TestData(SendTo.Me, 0u, 1u),
|
||||
new TestData(SendTo.Me, 0u, 2u),
|
||||
new TestData(SendTo.Me, 1u, 0u),
|
||||
new TestData(SendTo.Me, 1u, 1u),
|
||||
new TestData(SendTo.Me, 1u, 2u),
|
||||
new TestData(SendTo.Me, 2u, 0u),
|
||||
new TestData(SendTo.Me, 2u, 1u),
|
||||
new TestData(SendTo.Me, 2u, 2u),
|
||||
new TestData(SendTo.Owner, 0u, 0u),
|
||||
new TestData(SendTo.Owner, 1u, 1u),
|
||||
new TestData(SendTo.Owner, 2u, 2u),
|
||||
new TestData(SendTo.Server, 0u, 0u),
|
||||
new TestData(SendTo.Server, 1u, 0u),
|
||||
new TestData(SendTo.Server, 2u, 0u),
|
||||
new TestData(SendTo.NotOwner, 0u, 1u),
|
||||
new TestData(SendTo.NotOwner, 0u, 2u),
|
||||
new TestData(SendTo.NotOwner, 1u, 0u),
|
||||
new TestData(SendTo.NotOwner, 1u, 2u),
|
||||
new TestData(SendTo.NotOwner, 2u, 0u),
|
||||
new TestData(SendTo.NotOwner, 2u, 1u),
|
||||
new TestData(SendTo.NotServer, 0u, 1u),
|
||||
new TestData(SendTo.NotServer, 0u, 2u),
|
||||
new TestData(SendTo.NotServer, 1u, 1u),
|
||||
new TestData(SendTo.NotServer, 1u, 2u),
|
||||
new TestData(SendTo.NotServer, 2u, 1u),
|
||||
new TestData(SendTo.NotServer, 2u, 2u),
|
||||
new TestData(SendTo.ClientsAndHost, 0u, 0u),
|
||||
new TestData(SendTo.ClientsAndHost, 0u, 1u),
|
||||
new TestData(SendTo.ClientsAndHost, 0u, 2u),
|
||||
new TestData(SendTo.ClientsAndHost, 1u, 0u),
|
||||
new TestData(SendTo.ClientsAndHost, 1u, 1u),
|
||||
new TestData(SendTo.ClientsAndHost, 1u, 2u),
|
||||
new TestData(SendTo.ClientsAndHost, 2u, 0u),
|
||||
new TestData(SendTo.ClientsAndHost, 2u, 1u),
|
||||
new TestData(SendTo.ClientsAndHost, 2u, 2u),
|
||||
};
|
||||
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator TestDeferLocal()
|
||||
{
|
||||
foreach (var testCase in s_LocalDeliveryTestCases)
|
||||
{
|
||||
// Not calling Assert.Ignore() because Unity will mark the whole block of tests as ignored
|
||||
// Just consider this case a success...
|
||||
return;
|
||||
if (++YieldCheck % YieldCycleCount == 0)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
OnInlineSetup();
|
||||
var defaultSendTo = testCase.SendTo;
|
||||
var sender = testCase.Sender;
|
||||
var objectOwner = testCase.ObjectOwner;
|
||||
|
||||
if (defaultSendTo == SendTo.ClientsAndHost && sender == 0u && !m_ServerNetworkManager.IsHost)
|
||||
{
|
||||
// Not calling Assert.Ignore() because Unity will mark the whole block of tests as ignored
|
||||
// Just consider this case a success...
|
||||
yield break;
|
||||
}
|
||||
|
||||
var sendMethodName = $"DefaultTo{defaultSendTo}DeferLocalRpc";
|
||||
var verifyMethodName = $"VerifySentTo{defaultSendTo}";
|
||||
var senderObject = GetPlayerObject(objectOwner, sender);
|
||||
var sendMethod = senderObject.GetType().GetMethod(sendMethodName);
|
||||
sendMethod.Invoke(senderObject, new object[] { new RpcParams() });
|
||||
|
||||
VerifyNotReceived(objectOwner, new[] { sender });
|
||||
// Should be received on the next frame
|
||||
SimulateOneFrame();
|
||||
VerifyLocalReceived(objectOwner, sender, sendMethodName, false);
|
||||
|
||||
var verifyMethod = GetType().GetMethod(verifyMethodName);
|
||||
verifyMethod.Invoke(this, new object[] { objectOwner, sender, sendMethodName });
|
||||
OnInlineTearDown();
|
||||
}
|
||||
var sendMethodName = $"DefaultTo{defaultSendTo}WithRpcParamsRpc";
|
||||
var verifyMethodName = $"VerifySentTo{defaultSendTo}";
|
||||
var senderObject = GetPlayerObject(objectOwner, sender);
|
||||
var sendMethod = senderObject.GetType().GetMethod(sendMethodName);
|
||||
sendMethod.Invoke(senderObject, new object[] { (RpcParams)LocalDeferMode.Defer });
|
||||
|
||||
VerifyNotReceived(objectOwner, new[] { sender });
|
||||
// Should be received on the next frame
|
||||
SimulateOneFrame();
|
||||
VerifyLocalReceived(objectOwner, sender, sendMethodName, false);
|
||||
|
||||
var verifyMethod = GetType().GetMethod(verifyMethodName);
|
||||
verifyMethod.Invoke(this, new object[] { objectOwner, sender, sendMethodName });
|
||||
}
|
||||
|
||||
[Test]
|
||||
// All the test cases that involve sends that will be delivered locally
|
||||
[TestCase(SendTo.Everyone, 0u, 0u)]
|
||||
[TestCase(SendTo.Everyone, 0u, 1u)]
|
||||
[TestCase(SendTo.Everyone, 0u, 2u)]
|
||||
[TestCase(SendTo.Everyone, 1u, 0u)]
|
||||
[TestCase(SendTo.Everyone, 1u, 1u)]
|
||||
[TestCase(SendTo.Everyone, 1u, 2u)]
|
||||
[TestCase(SendTo.Everyone, 2u, 0u)]
|
||||
[TestCase(SendTo.Everyone, 2u, 1u)]
|
||||
[TestCase(SendTo.Everyone, 2u, 2u)]
|
||||
[TestCase(SendTo.Me, 0u, 0u)]
|
||||
[TestCase(SendTo.Me, 0u, 1u)]
|
||||
[TestCase(SendTo.Me, 0u, 2u)]
|
||||
[TestCase(SendTo.Me, 1u, 0u)]
|
||||
[TestCase(SendTo.Me, 1u, 1u)]
|
||||
[TestCase(SendTo.Me, 1u, 2u)]
|
||||
[TestCase(SendTo.Me, 2u, 0u)]
|
||||
[TestCase(SendTo.Me, 2u, 1u)]
|
||||
[TestCase(SendTo.Me, 2u, 2u)]
|
||||
[TestCase(SendTo.Owner, 0u, 0u)]
|
||||
[TestCase(SendTo.Owner, 1u, 1u)]
|
||||
[TestCase(SendTo.Owner, 2u, 2u)]
|
||||
[TestCase(SendTo.Server, 0u, 0u)]
|
||||
[TestCase(SendTo.Server, 1u, 0u)]
|
||||
[TestCase(SendTo.Server, 2u, 0u)]
|
||||
[TestCase(SendTo.NotOwner, 0u, 1u)]
|
||||
[TestCase(SendTo.NotOwner, 0u, 2u)]
|
||||
[TestCase(SendTo.NotOwner, 1u, 0u)]
|
||||
[TestCase(SendTo.NotOwner, 1u, 2u)]
|
||||
[TestCase(SendTo.NotOwner, 2u, 0u)]
|
||||
[TestCase(SendTo.NotOwner, 2u, 1u)]
|
||||
[TestCase(SendTo.NotServer, 0u, 1u)]
|
||||
[TestCase(SendTo.NotServer, 0u, 2u)]
|
||||
[TestCase(SendTo.NotServer, 1u, 1u)]
|
||||
[TestCase(SendTo.NotServer, 1u, 2u)]
|
||||
[TestCase(SendTo.NotServer, 2u, 1u)]
|
||||
[TestCase(SendTo.NotServer, 2u, 2u)]
|
||||
[TestCase(SendTo.ClientsAndHost, 0u, 0u)]
|
||||
[TestCase(SendTo.ClientsAndHost, 0u, 1u)]
|
||||
[TestCase(SendTo.ClientsAndHost, 0u, 2u)]
|
||||
[TestCase(SendTo.ClientsAndHost, 1u, 0u)]
|
||||
[TestCase(SendTo.ClientsAndHost, 1u, 1u)]
|
||||
[TestCase(SendTo.ClientsAndHost, 1u, 2u)]
|
||||
[TestCase(SendTo.ClientsAndHost, 2u, 0u)]
|
||||
[TestCase(SendTo.ClientsAndHost, 2u, 1u)]
|
||||
[TestCase(SendTo.ClientsAndHost, 2u, 2u)]
|
||||
public void TestDeferLocalOverrideToFalse(
|
||||
SendTo defaultSendTo,
|
||||
ulong objectOwner,
|
||||
ulong sender
|
||||
)
|
||||
[UnityTest]
|
||||
public IEnumerator TestDeferLocalOverrideToTrue()
|
||||
{
|
||||
if (defaultSendTo == SendTo.ClientsAndHost && sender == 0u && !m_ServerNetworkManager.IsHost)
|
||||
foreach (var testCase in s_LocalDeliveryTestCases)
|
||||
{
|
||||
// Not calling Assert.Ignore() because Unity will mark the whole block of tests as ignored
|
||||
// Just consider this case a success...
|
||||
return;
|
||||
if (++YieldCheck % YieldCycleCount == 0)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
OnInlineSetup();
|
||||
var defaultSendTo = testCase.SendTo;
|
||||
var sender = testCase.Sender;
|
||||
var objectOwner = testCase.ObjectOwner;
|
||||
|
||||
if (defaultSendTo == SendTo.ClientsAndHost && sender == 0u && !m_ServerNetworkManager.IsHost)
|
||||
{
|
||||
// Not calling Assert.Ignore() because Unity will mark the whole block of tests as ignored
|
||||
// Just consider this case a success...
|
||||
yield break;
|
||||
}
|
||||
|
||||
var sendMethodName = $"DefaultTo{defaultSendTo}WithRpcParamsRpc";
|
||||
var verifyMethodName = $"VerifySentTo{defaultSendTo}";
|
||||
var senderObject = GetPlayerObject(objectOwner, sender);
|
||||
var sendMethod = senderObject.GetType().GetMethod(sendMethodName);
|
||||
sendMethod.Invoke(senderObject, new object[] { (RpcParams)LocalDeferMode.Defer });
|
||||
|
||||
VerifyNotReceived(objectOwner, new[] { sender });
|
||||
// Should be received on the next frame
|
||||
SimulateOneFrame();
|
||||
VerifyLocalReceived(objectOwner, sender, sendMethodName, false);
|
||||
|
||||
var verifyMethod = GetType().GetMethod(verifyMethodName);
|
||||
verifyMethod.Invoke(this, new object[] { objectOwner, sender, sendMethodName });
|
||||
OnInlineTearDown();
|
||||
}
|
||||
var sendMethodName = $"DefaultTo{defaultSendTo}DeferLocalRpc";
|
||||
var verifyMethodName = $"VerifySentTo{defaultSendTo}";
|
||||
var senderObject = GetPlayerObject(objectOwner, sender);
|
||||
var sendMethod = senderObject.GetType().GetMethod(sendMethodName);
|
||||
sendMethod.Invoke(senderObject, new object[] { (RpcParams)LocalDeferMode.SendImmediate });
|
||||
}
|
||||
|
||||
VerifyLocalReceived(objectOwner, sender, sendMethodName, false);
|
||||
[UnityTest]
|
||||
public IEnumerator TestDeferLocalOverrideToFalse()
|
||||
{
|
||||
foreach (var testCase in s_LocalDeliveryTestCases)
|
||||
{
|
||||
if (++YieldCheck % YieldCycleCount == 0)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
OnInlineSetup();
|
||||
var defaultSendTo = testCase.SendTo;
|
||||
var sender = testCase.Sender;
|
||||
var objectOwner = testCase.ObjectOwner;
|
||||
|
||||
var verifyMethod = GetType().GetMethod(verifyMethodName);
|
||||
verifyMethod.Invoke(this, new object[] { objectOwner, sender, sendMethodName });
|
||||
if (defaultSendTo == SendTo.ClientsAndHost && sender == 0u && !m_ServerNetworkManager.IsHost)
|
||||
{
|
||||
// Not calling Assert.Ignore() because Unity will mark the whole block of tests as ignored
|
||||
// Just consider this case a success...
|
||||
yield break;
|
||||
}
|
||||
|
||||
var sendMethodName = $"DefaultTo{defaultSendTo}DeferLocalRpc";
|
||||
var verifyMethodName = $"VerifySentTo{defaultSendTo}";
|
||||
var senderObject = GetPlayerObject(objectOwner, sender);
|
||||
var sendMethod = senderObject.GetType().GetMethod(sendMethodName);
|
||||
sendMethod.Invoke(senderObject, new object[] { (RpcParams)LocalDeferMode.SendImmediate });
|
||||
|
||||
VerifyLocalReceived(objectOwner, sender, sendMethodName, false);
|
||||
|
||||
var verifyMethod = GetType().GetMethod(verifyMethodName);
|
||||
verifyMethod.Invoke(this, new object[] { objectOwner, sender, sendMethodName });
|
||||
OnInlineTearDown();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1636,17 +1683,20 @@ namespace Unity.Netcode.RuntimeTests.UniversalRpcTests
|
||||
|
||||
VerifyNotReceived(NetworkManager.ServerClientId, s_ClientIds);
|
||||
|
||||
for (var i = 0; i < 10; ++i)
|
||||
var clientListExpected = 1;
|
||||
var serverListExpected = 2;
|
||||
for (var i = 1; i <= 10; ++i)
|
||||
{
|
||||
WaitForMessageReceivedWithTimeTravel<RpcMessage>(clientList);
|
||||
VerifyRemoteReceived(NetworkManager.ServerClientId, NetworkManager.ServerClientId, nameof(UniversalRpcNetworkBehaviour.MutualRecursionClientRpc), clientIdArray, false, false);
|
||||
VerifyRemoteReceived(NetworkManager.ServerClientId, NetworkManager.ServerClientId, nameof(UniversalRpcNetworkBehaviour.MutualRecursionClientRpc), clientIdArray, false, false, clientListExpected);
|
||||
VerifyNotReceived(NetworkManager.ServerClientId, serverIdArray);
|
||||
clientListExpected *= 2;
|
||||
|
||||
Clear();
|
||||
|
||||
WaitForMessageReceivedWithTimeTravel<RpcMessage>(serverList);
|
||||
VerifyRemoteReceived(NetworkManager.ServerClientId, NetworkManager.ServerClientId, nameof(UniversalRpcNetworkBehaviour.MutualRecursionServerRpc), serverIdArray, false, false);
|
||||
VerifyRemoteReceived(NetworkManager.ServerClientId, NetworkManager.ServerClientId, nameof(UniversalRpcNetworkBehaviour.MutualRecursionServerRpc), serverIdArray, false, false, serverListExpected);
|
||||
VerifyNotReceived(NetworkManager.ServerClientId, clientIdArray);
|
||||
serverListExpected *= 2;
|
||||
|
||||
Clear();
|
||||
}
|
||||
@@ -1915,3 +1965,4 @@ namespace Unity.Netcode.RuntimeTests.UniversalRpcTests
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -12,12 +12,20 @@
|
||||
"Unity.Networking.Transport",
|
||||
"ClientNetworkTransform",
|
||||
"Unity.Netcode.TestHelpers.Runtime",
|
||||
"Unity.Mathematics"
|
||||
"Unity.Mathematics",
|
||||
"UnityEngine.TestRunner",
|
||||
"UnityEditor.TestRunner"
|
||||
],
|
||||
"optionalUnityReferences": [
|
||||
"TestAssemblies"
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": true,
|
||||
"overrideReferences": true,
|
||||
"precompiledReferences": [
|
||||
"nunit.framework.dll"
|
||||
],
|
||||
"autoReferenced": false,
|
||||
"defineConstraints": [
|
||||
"UNITY_INCLUDE_TESTS",
|
||||
"UNITY_INCLUDE_TESTS"
|
||||
],
|
||||
"versionDefines": [
|
||||
@@ -46,5 +54,6 @@
|
||||
"expression": "2.0.0-exp",
|
||||
"define": "UTP_TRANSPORT_2_0_ABOVE"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
Reference in New Issue
Block a user