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)
122 lines
4.7 KiB
C#
122 lines
4.7 KiB
C#
using System.Collections;
|
|
using Unity.Netcode.Components;
|
|
using NUnit.Framework;
|
|
using UnityEngine;
|
|
using UnityEngine.TestTools;
|
|
using Unity.Netcode.TestHelpers.Runtime;
|
|
|
|
|
|
namespace Unity.Netcode.RuntimeTests
|
|
{
|
|
public class TransformInterpolationObject : NetworkBehaviour
|
|
{
|
|
public bool CheckPosition;
|
|
public bool IsMoving;
|
|
public bool IsFixed;
|
|
|
|
private void Update()
|
|
{
|
|
// Since the local position is transformed from local to global and vice-versa on the server and client
|
|
// it may accumulate some error. We allow an error of 0.01 over the range of 1000 used in this test.
|
|
// This requires precision to 5 digits, so it doesn't weaken the test, while preventing spurious failures
|
|
const float maxRoundingError = 0.01f;
|
|
|
|
// Check the position of the nested object on the client
|
|
if (CheckPosition)
|
|
{
|
|
if (transform.position.y < -maxRoundingError || transform.position.y > 100.0f + maxRoundingError)
|
|
{
|
|
Debug.LogError($"Interpolation failure. transform.position.y is {transform.position.y}. Should be between 0.0 and 100.0");
|
|
}
|
|
}
|
|
|
|
// Move the nested object on the server
|
|
if (IsMoving)
|
|
{
|
|
var y = Time.realtimeSinceStartup;
|
|
while (y > 10.0f)
|
|
{
|
|
y -= 10.0f;
|
|
}
|
|
|
|
// change the space between local and global every second
|
|
GetComponent<NetworkTransform>().InLocalSpace = ((int)y % 2 == 0);
|
|
|
|
transform.position = new Vector3(0.0f, y * 10, 0.0f);
|
|
}
|
|
|
|
// On the server, make sure to keep the parent object at a fixed position
|
|
if (IsFixed)
|
|
{
|
|
transform.position = new Vector3(1000.0f, 1000.0f, 1000.0f);
|
|
}
|
|
}
|
|
}
|
|
|
|
public class TransformInterpolationTests : NetcodeIntegrationTest
|
|
{
|
|
protected override int NumberOfClients => 1;
|
|
|
|
private ulong m_ClientId0;
|
|
private GameObject m_PrefabToSpawn;
|
|
|
|
private NetworkObject m_AsNetworkObject;
|
|
private NetworkObject m_SpawnedObjectOnClient;
|
|
|
|
protected override void OnServerAndClientsCreated()
|
|
{
|
|
m_PrefabToSpawn = CreateNetworkObjectPrefab("InterpTestObject");
|
|
m_PrefabToSpawn.AddComponent<NetworkTransform>();
|
|
m_PrefabToSpawn.AddComponent<TransformInterpolationObject>();
|
|
}
|
|
|
|
private IEnumerator RefreshNetworkObjects()
|
|
{
|
|
var clientId = m_ClientNetworkManagers[0].LocalClientId;
|
|
yield return WaitForConditionOrTimeOut(() => s_GlobalNetworkObjects.ContainsKey(clientId) &&
|
|
s_GlobalNetworkObjects[clientId].ContainsKey(m_AsNetworkObject.NetworkObjectId));
|
|
|
|
Assert.False(s_GlobalTimeoutHelper.TimedOut, $"Timed out waiting for client side {nameof(NetworkObject)} ID of {m_AsNetworkObject.NetworkObjectId}");
|
|
m_SpawnedObjectOnClient = s_GlobalNetworkObjects[clientId][m_AsNetworkObject.NetworkObjectId];
|
|
// make sure the objects are set with the right network manager
|
|
m_SpawnedObjectOnClient.NetworkManagerOwner = m_ClientNetworkManagers[0];
|
|
}
|
|
|
|
[UnityTest]
|
|
public IEnumerator TransformInterpolationTest()
|
|
{
|
|
m_ClientId0 = m_ClientNetworkManagers[0].LocalClientId;
|
|
|
|
// create an object
|
|
var spawnedObject = Object.Instantiate(m_PrefabToSpawn);
|
|
var baseObject = Object.Instantiate(m_PrefabToSpawn);
|
|
baseObject.GetComponent<NetworkObject>().NetworkManagerOwner = m_ServerNetworkManager;
|
|
baseObject.GetComponent<NetworkObject>().Spawn();
|
|
|
|
m_AsNetworkObject = spawnedObject.GetComponent<NetworkObject>();
|
|
m_AsNetworkObject.NetworkManagerOwner = m_ServerNetworkManager;
|
|
|
|
m_AsNetworkObject.TrySetParent(baseObject);
|
|
|
|
m_AsNetworkObject.Spawn();
|
|
|
|
yield return RefreshNetworkObjects();
|
|
|
|
m_AsNetworkObject.TrySetParent(baseObject);
|
|
|
|
baseObject.GetComponent<TransformInterpolationObject>().IsFixed = true;
|
|
spawnedObject.GetComponent<TransformInterpolationObject>().IsMoving = true;
|
|
|
|
// Give two seconds for the object to settle
|
|
yield return new WaitForSeconds(2.0f);
|
|
|
|
m_SpawnedObjectOnClient.GetComponent<TransformInterpolationObject>().CheckPosition = true;
|
|
|
|
// Test that interpolation works correctly for 10 seconds
|
|
// Increasing this duration gives you the opportunity to go check in the Editor how the objects are setup
|
|
// and how they move
|
|
yield return new WaitForSeconds(10.0f);
|
|
}
|
|
}
|
|
}
|