com.unity.netcode.gameobjects@1.0.0-pre.7
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.0.0-pre.7] - 2022-04-01 ### Added - Added editor only check prior to entering into play mode if the currently open and active scene is in the build list and if not displays a dialog box asking the user if they would like to automatically add it prior to entering into play mode. (#1828) - Added `UnityTransport` implementation and `com.unity.transport` package dependency (#1823) - Added `NetworkVariableWritePermission` to `NetworkVariableBase` and implemented `Owner` client writable netvars. (#1762) - `UnityTransport` settings can now be set programmatically. (#1845) - `FastBufferWriter` and Reader IsInitialized property. (#1859) ### Changed - Updated `UnityTransport` dependency on `com.unity.transport` to 1.0.0 (#1849) ### Removed - Removed `SnapshotSystem` (#1852) - Removed `com.unity.modules.animation`, `com.unity.modules.physics` and `com.unity.modules.physics2d` dependencies from the package (#1812) - Removed `com.unity.collections` dependency from the package (#1849) ### Fixed - Fixed in-scene placed NetworkObjects not being found/ignored after a client disconnects and then reconnects. (#1850) - Fixed issue where `UnityTransport` send queues were not flushed when calling `DisconnectLocalClient` or `DisconnectRemoteClient`. (#1847) - Fixed NetworkBehaviour dependency verification check for an existing NetworkObject not searching from root parent transform relative GameObject. (#1841) - Fixed issue where entries were not being removed from the NetworkSpawnManager.OwnershipToObjectsTable. (#1838) - Fixed ClientRpcs would always send to all connected clients by default as opposed to only sending to the NetworkObject's Observers list by default. (#1836) - Fixed clarity for NetworkSceneManager client side notification when it receives a scene hash value that does not exist in its local hash table. (#1828) - Fixed client throws a key not found exception when it times out using UNet or UTP. (#1821) - Fixed network variable updates are no longer limited to 32,768 bytes when NetworkConfig.EnsureNetworkVariableLengthSafety is enabled. The limits are now determined by what the transport can send in a message. (#1811) - Fixed in-scene NetworkObjects get destroyed if a client fails to connect and shuts down the NetworkManager. (#1809) - Fixed user never being notified in the editor that a NetworkBehaviour requires a NetworkObject to function properly. (#1808) - Fixed PlayerObjects and dynamically spawned NetworkObjects not being added to the NetworkClient's OwnedObjects (#1801) - Fixed issue where NetworkManager would continue starting even if the NetworkTransport selected failed. (#1780) - Fixed issue when spawning new player if an already existing player exists it does not remove IsPlayer from the previous player (#1779) - Fixed lack of notification that NetworkManager and NetworkObject cannot be added to the same GameObject with in-editor notifications (#1777) - Fixed parenting warning printing for false positives (#1855)
This commit is contained in:
@@ -6,9 +6,229 @@ using NUnit.Framework;
|
||||
using Unity.Collections;
|
||||
using Unity.Netcode.TestHelpers.Runtime;
|
||||
using Random = UnityEngine.Random;
|
||||
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);
|
||||
}
|
||||
|
||||
[TestFixtureSource(nameof(TestDataSource))]
|
||||
public class NetworkVariablePermissionTests : NetcodeIntegrationTest
|
||||
{
|
||||
public static IEnumerable<TestFixtureData> TestDataSource()
|
||||
{
|
||||
foreach (HostOrServer hostOrServer in Enum.GetValues(typeof(HostOrServer)))
|
||||
{
|
||||
yield return new TestFixtureData(hostOrServer);
|
||||
}
|
||||
}
|
||||
|
||||
protected override int NumberOfClients => 3;
|
||||
|
||||
public NetworkVariablePermissionTests(HostOrServer hostOrServer)
|
||||
: base(hostOrServer)
|
||||
{
|
||||
}
|
||||
|
||||
private GameObject m_TestObjPrefab;
|
||||
private ulong m_TestObjId = 0;
|
||||
|
||||
protected override void OnServerAndClientsCreated()
|
||||
{
|
||||
m_TestObjPrefab = CreateNetworkObjectPrefab($"[{nameof(NetworkVariablePermissionTests)}.{nameof(m_TestObjPrefab)}]");
|
||||
var testComp = m_TestObjPrefab.AddComponent<NetVarPermTestComp>();
|
||||
}
|
||||
|
||||
protected override IEnumerator OnServerAndClientsConnected()
|
||||
{
|
||||
m_TestObjId = SpawnObject(m_TestObjPrefab, m_ServerNetworkManager).GetComponent<NetworkObject>().NetworkObjectId;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
private IEnumerator WaitForPositionsAreEqual(NetworkVariable<Vector3> netvar, Vector3 expected)
|
||||
{
|
||||
yield return WaitForConditionOrTimeOut(() => netvar.Value == expected);
|
||||
Assert.IsFalse(s_GlobalTimeoutHelper.TimedOut);
|
||||
}
|
||||
|
||||
private IEnumerator WaitForOwnerWritableAreEqualOnAll()
|
||||
{
|
||||
yield return WaitForConditionOrTimeOut(CheckOwnerWritableAreEqualOnAll);
|
||||
Assert.IsFalse(s_GlobalTimeoutHelper.TimedOut);
|
||||
}
|
||||
|
||||
private bool CheckOwnerWritableAreEqualOnAll()
|
||||
{
|
||||
var testObjServer = m_ServerNetworkManager.SpawnManager.SpawnedObjects[m_TestObjId];
|
||||
var testCompServer = testObjServer.GetComponent<NetVarPermTestComp>();
|
||||
foreach (var clientNetworkManager in m_ClientNetworkManagers)
|
||||
{
|
||||
var testObjClient = clientNetworkManager.SpawnManager.SpawnedObjects[m_TestObjId];
|
||||
var testCompClient = testObjClient.GetComponent<NetVarPermTestComp>();
|
||||
if (testObjServer.OwnerClientId != testObjClient.OwnerClientId ||
|
||||
testCompServer.OwnerWritable_Position.Value != testCompClient.OwnerWritable_Position.Value ||
|
||||
testCompServer.OwnerWritable_Position.ReadPerm != testCompClient.OwnerWritable_Position.ReadPerm ||
|
||||
testCompServer.OwnerWritable_Position.WritePerm != testCompClient.OwnerWritable_Position.WritePerm)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private IEnumerator WaitForServerWritableAreEqualOnAll()
|
||||
{
|
||||
yield return WaitForConditionOrTimeOut(CheckServerWritableAreEqualOnAll);
|
||||
Assert.IsFalse(s_GlobalTimeoutHelper.TimedOut);
|
||||
}
|
||||
|
||||
private bool CheckServerWritableAreEqualOnAll()
|
||||
{
|
||||
var testObjServer = m_ServerNetworkManager.SpawnManager.SpawnedObjects[m_TestObjId];
|
||||
var testCompServer = testObjServer.GetComponent<NetVarPermTestComp>();
|
||||
foreach (var clientNetworkManager in m_ClientNetworkManagers)
|
||||
{
|
||||
var testObjClient = clientNetworkManager.SpawnManager.SpawnedObjects[m_TestObjId];
|
||||
var testCompClient = testObjClient.GetComponent<NetVarPermTestComp>();
|
||||
if (testCompServer.ServerWritable_Position.Value != testCompClient.ServerWritable_Position.Value ||
|
||||
testCompServer.ServerWritable_Position.ReadPerm != testCompClient.ServerWritable_Position.ReadPerm ||
|
||||
testCompServer.ServerWritable_Position.WritePerm != testCompClient.ServerWritable_Position.WritePerm)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator ServerChangesOwnerWritableNetVar()
|
||||
{
|
||||
yield return WaitForOwnerWritableAreEqualOnAll();
|
||||
|
||||
var testObjServer = m_ServerNetworkManager.SpawnManager.SpawnedObjects[m_TestObjId];
|
||||
var testCompServer = testObjServer.GetComponent<NetVarPermTestComp>();
|
||||
|
||||
var oldValue = testCompServer.OwnerWritable_Position.Value;
|
||||
var newValue = oldValue + new Vector3(Random.Range(0, 100.0f), Random.Range(0, 100.0f), Random.Range(0, 100.0f));
|
||||
|
||||
testCompServer.OwnerWritable_Position.Value = newValue;
|
||||
yield return WaitForPositionsAreEqual(testCompServer.OwnerWritable_Position, newValue);
|
||||
|
||||
yield return WaitForOwnerWritableAreEqualOnAll();
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator ServerChangesServerWritableNetVar()
|
||||
{
|
||||
yield return WaitForServerWritableAreEqualOnAll();
|
||||
|
||||
var testObjServer = m_ServerNetworkManager.SpawnManager.SpawnedObjects[m_TestObjId];
|
||||
var testCompServer = testObjServer.GetComponent<NetVarPermTestComp>();
|
||||
|
||||
var oldValue = testCompServer.ServerWritable_Position.Value;
|
||||
var newValue = oldValue + new Vector3(Random.Range(0, 100.0f), Random.Range(0, 100.0f), Random.Range(0, 100.0f));
|
||||
|
||||
testCompServer.ServerWritable_Position.Value = newValue;
|
||||
yield return WaitForPositionsAreEqual(testCompServer.ServerWritable_Position, newValue);
|
||||
|
||||
yield return WaitForServerWritableAreEqualOnAll();
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator ClientChangesOwnerWritableNetVar()
|
||||
{
|
||||
yield return WaitForOwnerWritableAreEqualOnAll();
|
||||
|
||||
var testObjServer = m_ServerNetworkManager.SpawnManager.SpawnedObjects[m_TestObjId];
|
||||
|
||||
int clientManagerIndex = m_ClientNetworkManagers.Length - 1;
|
||||
var newOwnerClientId = m_ClientNetworkManagers[clientManagerIndex].LocalClientId;
|
||||
testObjServer.ChangeOwnership(newOwnerClientId);
|
||||
yield return NetcodeIntegrationTestHelpers.WaitForTicks(m_ServerNetworkManager, 2);
|
||||
|
||||
yield return WaitForOwnerWritableAreEqualOnAll();
|
||||
|
||||
var testObjClient = m_ClientNetworkManagers[clientManagerIndex].SpawnManager.SpawnedObjects[m_TestObjId];
|
||||
var testCompClient = testObjClient.GetComponent<NetVarPermTestComp>();
|
||||
|
||||
var oldValue = testCompClient.OwnerWritable_Position.Value;
|
||||
var newValue = oldValue + new Vector3(Random.Range(0, 100.0f), Random.Range(0, 100.0f), Random.Range(0, 100.0f));
|
||||
|
||||
testCompClient.OwnerWritable_Position.Value = newValue;
|
||||
yield return WaitForPositionsAreEqual(testCompClient.OwnerWritable_Position, newValue);
|
||||
|
||||
yield return WaitForOwnerWritableAreEqualOnAll();
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator ClientCannotChangeServerWritableNetVar()
|
||||
{
|
||||
yield return WaitForServerWritableAreEqualOnAll();
|
||||
|
||||
var testObjServer = m_ServerNetworkManager.SpawnManager.SpawnedObjects[m_TestObjId];
|
||||
var testCompServer = testObjServer.GetComponent<NetVarPermTestComp>();
|
||||
|
||||
int clientManagerIndex = m_ClientNetworkManagers.Length - 1;
|
||||
var newOwnerClientId = m_ClientNetworkManagers[clientManagerIndex].LocalClientId;
|
||||
testObjServer.ChangeOwnership(newOwnerClientId);
|
||||
yield return NetcodeIntegrationTestHelpers.WaitForTicks(m_ServerNetworkManager, 2);
|
||||
|
||||
yield return WaitForServerWritableAreEqualOnAll();
|
||||
|
||||
var testObjClient = m_ClientNetworkManagers[clientManagerIndex].SpawnManager.SpawnedObjects[m_TestObjId];
|
||||
var testCompClient = testObjClient.GetComponent<NetVarPermTestComp>();
|
||||
|
||||
var oldValue = testCompClient.ServerWritable_Position.Value;
|
||||
var newValue = oldValue + new Vector3(Random.Range(0, 100.0f), Random.Range(0, 100.0f), Random.Range(0, 100.0f));
|
||||
|
||||
Assert.That(() => testCompClient.ServerWritable_Position.Value = newValue, Throws.TypeOf<InvalidOperationException>());
|
||||
yield return WaitForPositionsAreEqual(testCompServer.ServerWritable_Position, oldValue);
|
||||
|
||||
yield return WaitForServerWritableAreEqualOnAll();
|
||||
|
||||
testCompServer.ServerWritable_Position.Value = newValue;
|
||||
yield return WaitForPositionsAreEqual(testCompServer.ServerWritable_Position, newValue);
|
||||
|
||||
yield return WaitForServerWritableAreEqualOnAll();
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator ServerCannotChangeOwnerWritableNetVar()
|
||||
{
|
||||
yield return WaitForOwnerWritableAreEqualOnAll();
|
||||
|
||||
var testObjServer = m_ServerNetworkManager.SpawnManager.SpawnedObjects[m_TestObjId];
|
||||
var testCompServer = testObjServer.GetComponent<NetVarPermTestComp>();
|
||||
|
||||
int clientManagerIndex = m_ClientNetworkManagers.Length - 1;
|
||||
var newOwnerClientId = m_ClientNetworkManagers[clientManagerIndex].LocalClientId;
|
||||
testObjServer.ChangeOwnership(newOwnerClientId);
|
||||
yield return NetcodeIntegrationTestHelpers.WaitForTicks(m_ServerNetworkManager, 2);
|
||||
|
||||
yield return WaitForOwnerWritableAreEqualOnAll();
|
||||
|
||||
var oldValue = testCompServer.OwnerWritable_Position.Value;
|
||||
var newValue = oldValue + new Vector3(Random.Range(0, 100.0f), Random.Range(0, 100.0f), Random.Range(0, 100.0f));
|
||||
|
||||
Assert.That(() => testCompServer.OwnerWritable_Position.Value = newValue, Throws.TypeOf<InvalidOperationException>());
|
||||
yield return WaitForPositionsAreEqual(testCompServer.OwnerWritable_Position, oldValue);
|
||||
|
||||
yield return WaitForOwnerWritableAreEqualOnAll();
|
||||
|
||||
var testObjClient = m_ClientNetworkManagers[clientManagerIndex].SpawnManager.SpawnedObjects[m_TestObjId];
|
||||
var testCompClient = testObjClient.GetComponent<NetVarPermTestComp>();
|
||||
|
||||
testCompClient.OwnerWritable_Position.Value = newValue;
|
||||
yield return WaitForPositionsAreEqual(testCompClient.OwnerWritable_Position, newValue);
|
||||
|
||||
yield return WaitForOwnerWritableAreEqualOnAll();
|
||||
}
|
||||
}
|
||||
|
||||
public struct TestStruct : INetworkSerializable, IEquatable<TestStruct>
|
||||
{
|
||||
public uint SomeInt;
|
||||
@@ -95,8 +315,6 @@ namespace Unity.Netcode.RuntimeTests
|
||||
private const int k_TestVal2 = 222;
|
||||
private const int k_TestVal3 = 333;
|
||||
|
||||
private const int k_TestKey1 = 0x0f0f;
|
||||
|
||||
private static List<NetworkVariableTest> s_ClientNetworkVariableTestInstances = new List<NetworkVariableTest>();
|
||||
public static void ClientNetworkVariableTestSpawned(NetworkVariableTest networkVariableTest)
|
||||
{
|
||||
@@ -111,7 +329,7 @@ namespace Unity.Netcode.RuntimeTests
|
||||
|
||||
private NetworkListTestPredicate m_NetworkListPredicateHandler;
|
||||
|
||||
private bool m_EnsureLengthSafety;
|
||||
private readonly bool m_EnsureLengthSafety;
|
||||
|
||||
public NetworkVariableTests(bool ensureLengthSafety)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user