Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ Additional documentation and release notes are available at [Multiplayer Documen

### Changed

- Changed `NetworkClient.SessionModeTypes` to `NetworkClient.NetworkTopologyTypes`. (#2875)
- Changed `NetworkClient.SessionModeType` to `NetworkClient.NetworkTopologyType`. (#2875)
- Changed `NetworkConfig.SessionMode` to `NeworkConfig.NetworkTopology`. (#2875)


## [2.0.0-exp.2] - 2024-04-02

Expand Down
17 changes: 13 additions & 4 deletions com.unity.netcode.gameobjects/Editor/NetworkManagerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public class NetworkManagerEditor : UnityEditor.Editor
private SerializedProperty m_ProtocolVersionProperty;
private SerializedProperty m_NetworkTransportProperty;
private SerializedProperty m_TickRateProperty;
private SerializedProperty m_SessionModeProperty;
#if MULTIPLAYER_SDK_INSTALLED
private SerializedProperty m_NetworkTopologyProperty;
#endif
private SerializedProperty m_ClientConnectionBufferTimeoutProperty;
private SerializedProperty m_ConnectionApprovalProperty;
private SerializedProperty m_EnsureNetworkVariableLengthSafetyProperty;
Expand Down Expand Up @@ -100,7 +102,9 @@ private void Initialize()
m_ProtocolVersionProperty = m_NetworkConfigProperty.FindPropertyRelative("ProtocolVersion");
m_NetworkTransportProperty = m_NetworkConfigProperty.FindPropertyRelative("NetworkTransport");
m_TickRateProperty = m_NetworkConfigProperty.FindPropertyRelative("TickRate");
m_SessionModeProperty = m_NetworkConfigProperty.FindPropertyRelative("SessionMode");
#if MULTIPLAYER_SDK_INSTALLED
m_NetworkTopologyProperty = m_NetworkConfigProperty.FindPropertyRelative("NetworkTopology");
#endif
m_ClientConnectionBufferTimeoutProperty = m_NetworkConfigProperty.FindPropertyRelative("ClientConnectionBufferTimeout");
m_ConnectionApprovalProperty = m_NetworkConfigProperty.FindPropertyRelative("ConnectionApproval");
m_EnsureNetworkVariableLengthSafetyProperty = m_NetworkConfigProperty.FindPropertyRelative("EnsureNetworkVariableLengthSafety");
Expand Down Expand Up @@ -138,7 +142,9 @@ private void CheckNullProperties()
m_ProtocolVersionProperty = m_NetworkConfigProperty.FindPropertyRelative("ProtocolVersion");
m_NetworkTransportProperty = m_NetworkConfigProperty.FindPropertyRelative("NetworkTransport");
m_TickRateProperty = m_NetworkConfigProperty.FindPropertyRelative("TickRate");
m_SessionModeProperty = m_NetworkConfigProperty.FindPropertyRelative("SessionMode");
#if MULTIPLAYER_SDK_INSTALLED
m_NetworkTopologyProperty = m_NetworkConfigProperty.FindPropertyRelative("NetworkTopology");
#endif
m_ClientConnectionBufferTimeoutProperty = m_NetworkConfigProperty.FindPropertyRelative("ClientConnectionBufferTimeout");
m_ConnectionApprovalProperty = m_NetworkConfigProperty.FindPropertyRelative("ConnectionApproval");
m_EnsureNetworkVariableLengthSafetyProperty = m_NetworkConfigProperty.FindPropertyRelative("EnsureNetworkVariableLengthSafety");
Expand Down Expand Up @@ -177,9 +183,12 @@ public override void OnInspectorGUI()
serializedObject.Update();
EditorGUILayout.PropertyField(m_RunInBackgroundProperty);
EditorGUILayout.PropertyField(m_LogLevelProperty);
EditorGUILayout.PropertyField(m_SessionModeProperty);

EditorGUILayout.Space();
EditorGUILayout.LabelField("Network Settings", EditorStyles.boldLabel);
#if MULTIPLAYER_SDK_INSTALLED
EditorGUILayout.PropertyField(m_NetworkTopologyProperty);
#endif
EditorGUILayout.PropertyField(m_ProtocolVersionProperty);
EditorGUILayout.PropertyField(m_NetworkTransportProperty);
if (m_NetworkTransportProperty.objectReferenceValue == null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Collections.Generic;
#if MULTIPLAYER_SDK_INSTALLED
using System.Linq;
#endif
using UnityEditor;
using UnityEngine;

Expand Down Expand Up @@ -144,7 +146,9 @@ private void OnDestroy()
}
}


// Keeping this here just in case, but it appears that in Unity 6 the visual bugs with
// enum flags is resolved
#if BYPASS_DEFAULT_ENUM_DRAWER && MULTIPLAYER_SDK_INSTALLED
[CustomPropertyDrawer(typeof(NetworkObject.OwnershipStatus))]
public class NetworkObjectOwnership : PropertyDrawer
{
Expand Down Expand Up @@ -188,4 +192,5 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
EditorGUI.EndProperty();
}
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
"name": "com.unity.transport",
"expression": "2.0",
"define": "UTP_TRANSPORT_2_0_ABOVE"
},
{
"name": "com.unity.services.multiplayer",
"expression": "0.2.0",
"define": "MULTIPLAYER_SDK_INSTALLED"
}
],
"noEngineReferences": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ public class NetworkConfig
/// </summary>
public const int RttWindowSize = 64; // number of slots to use for RTT computations (max number of in-flight packets)

[Tooltip("Determines if the network session will run in client-server or distributed authority mode.")]
public SessionModeTypes SessionMode;
[Tooltip("Determines whether to use the client-server or distributed authority network topology.")]
public NetworkTopologyTypes NetworkTopology;

[HideInInspector]
public bool UseCMBService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Unity.Netcode
{

public enum SessionModeTypes
public enum NetworkTopologyTypes
{
ClientServer,
DistributedAuthority
Expand Down Expand Up @@ -41,7 +41,7 @@ public class NetworkClient
/// </summary>
internal bool IsApproved { get; set; }

public SessionModeTypes SessionModeType { get; internal set; }
public NetworkTopologyTypes NetworkTopologyType { get; internal set; }

public bool DAHost { get; internal set; }

Expand Down Expand Up @@ -77,9 +77,9 @@ internal bool SetRole(bool isServer, bool isClient, NetworkManager networkManage
if (networkManager != null)
{
SpawnManager = networkManager.SpawnManager;
SessionModeType = networkManager.NetworkConfig.SessionMode;
NetworkTopologyType = networkManager.NetworkConfig.NetworkTopology;

if (SessionModeType == SessionModeTypes.DistributedAuthority)
if (NetworkTopologyType == NetworkTopologyTypes.DistributedAuthority)
{
DAHost = IsClient && IsServer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public bool DistributedAuthorityMode
{
get
{
return NetworkConfig.SessionMode == SessionModeTypes.DistributedAuthority;
return NetworkConfig.NetworkTopology == NetworkTopologyTypes.DistributedAuthority;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,11 @@ public void DeferDespawn(int tickOffset, bool destroy = true)

/// <summary>
/// Determines whether a NetworkObject can be distributed to other clients during
/// a <see cref="SessionModeTypes.DistributedAuthority"/> session.
/// a <see cref="NetworkTopologyTypes.DistributedAuthority"/> session.
/// </summary>
#if !MULTIPLAYER_SDK_INSTALLED
[HideInInspector]
#endif
[SerializeField]
internal OwnershipStatus Ownership = OwnershipStatus.Distributable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ public bool ActiveSceneSynchronizationEnabled

/// <summary>
/// Returns the currently loaded scenes that are synchronized with the session owner or server depending upon the selected
/// NetworkManager session mode.
/// network topology.
/// </summary>
/// <remarks>
/// The <see cref="SceneManager"/> scenes loaded returns all scenes loaded where this returns only the scenes that have been
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected Vector3 GetRandomVector3(float min, float max)
return new Vector3(Random.Range(min, max), Random.Range(min, max), Random.Range(min, max));
}

public IntegrationTestWithApproximation(SessionModeTypes sessionModeType) : base(sessionModeType) { }
public IntegrationTestWithApproximation(NetworkTopologyTypes networkTopologyType) : base(networkTopologyType) { }

public IntegrationTestWithApproximation(HostOrServer hostOrServer) : base(hostOrServer) { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,21 @@ public enum HostOrServer

protected bool m_UseHost = true;
protected bool m_DistributedAuthority;
protected SessionModeTypes m_SessionModeType = SessionModeTypes.ClientServer;
protected NetworkTopologyTypes m_NetworkTopologyType = NetworkTopologyTypes.ClientServer;

protected virtual bool UseCMBService()
{
return false;
}

protected virtual SessionModeTypes OnGetSessionmode()
protected virtual NetworkTopologyTypes OnGetNetworkTopologyType()
{
return m_SessionModeType;
return m_NetworkTopologyType;
}

protected void SetDistributedAuthorityProperties(NetworkManager networkManager)
{
networkManager.NetworkConfig.SessionMode = m_SessionModeType;
networkManager.NetworkConfig.NetworkTopology = m_NetworkTopologyType;
networkManager.NetworkConfig.AutoSpawnPlayerPrefabClientSide = m_DistributedAuthority;
networkManager.NetworkConfig.UseCMBService = UseCMBService() && m_DistributedAuthority;
}
Expand Down Expand Up @@ -1567,7 +1567,7 @@ protected GameObject CreateNetworkObjectPrefab(string baseName)
Assert.IsFalse(m_ServerNetworkManager.IsListening, prefabCreateAssertError);
var prefabObject = NetcodeIntegrationTestHelpers.CreateNetworkObjectPrefab(baseName, m_ServerNetworkManager, m_ClientNetworkManagers);
// DANGO-TODO: Ownership flags could require us to change this
// For testing purposes, we default to true for the distribute ownership property when in distirbuted authority session mode.
// For testing purposes, we default to true for the distribute ownership property when in a distirbuted authority network topology.
prefabObject.GetComponent<NetworkObject>().Ownership |= NetworkObject.OwnershipStatus.Distributable;
return prefabObject;
}
Expand Down Expand Up @@ -1605,7 +1605,7 @@ private GameObject SpawnObject(NetworkObject prefabNetworkObject, NetworkManager
var newInstance = Object.Instantiate(prefabNetworkObject.gameObject);
var networkObjectToSpawn = newInstance.GetComponent<NetworkObject>();

if (owner.NetworkConfig.SessionMode == SessionModeTypes.DistributedAuthority)
if (owner.NetworkConfig.NetworkTopology == NetworkTopologyTypes.DistributedAuthority)
{
networkObjectToSpawn.NetworkManagerOwner = owner; // Required to assure the client does the spawning
if (isPlayerObject)
Expand Down Expand Up @@ -1687,15 +1687,15 @@ private List<GameObject> SpawnObjects(NetworkObject prefabNetworkObject, Network
/// </summary>
public NetcodeIntegrationTest()
{
m_SessionModeType = OnGetSessionmode();
m_DistributedAuthority = OnGetSessionmode() == SessionModeTypes.DistributedAuthority;
m_NetworkTopologyType = OnGetNetworkTopologyType();
m_DistributedAuthority = m_NetworkTopologyType == NetworkTopologyTypes.DistributedAuthority;
NetworkMessageManager.EnableMessageOrderConsoleLog = false;
}

public NetcodeIntegrationTest(SessionModeTypes sessionMode)
public NetcodeIntegrationTest(NetworkTopologyTypes networkTopologyType)
{
m_SessionModeType = sessionMode;
m_DistributedAuthority = OnGetSessionmode() == SessionModeTypes.DistributedAuthority;
m_NetworkTopologyType = networkTopologyType;
m_DistributedAuthority = m_NetworkTopologyType == NetworkTopologyTypes.DistributedAuthority;
}

/// <summary>
Expand All @@ -1717,8 +1717,8 @@ public NetcodeIntegrationTest(SessionModeTypes sessionMode)
public NetcodeIntegrationTest(HostOrServer hostOrServer)
{
m_UseHost = hostOrServer == HostOrServer.Host || hostOrServer == HostOrServer.DAHost;
m_SessionModeType = hostOrServer == HostOrServer.DAHost ? SessionModeTypes.DistributedAuthority : SessionModeTypes.ClientServer;
m_DistributedAuthority = OnGetSessionmode() == SessionModeTypes.DistributedAuthority;
m_NetworkTopologyType = hostOrServer == HostOrServer.DAHost ? NetworkTopologyTypes.DistributedAuthority : NetworkTopologyTypes.ClientServer;
m_DistributedAuthority = OnGetNetworkTopologyType() == NetworkTopologyTypes.DistributedAuthority;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class DistributedAuthorityCodecTests : NetcodeIntegrationTest
// Use the CMB Service for all tests
protected override bool UseCMBService() => true;

// Set the session mode to distributed authority for all tests
protected override SessionModeTypes OnGetSessionmode() => SessionModeTypes.DistributedAuthority;
// Set the network topology to distributed authority for all tests
protected override NetworkTopologyTypes OnGetNetworkTopologyType() => NetworkTopologyTypes.DistributedAuthority;

private CodecTestHooks m_ClientCodecHook;
private NetworkManager Client => m_ClientNetworkManagers[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public void Changed(NetworkListEvent<int> listEvent)
}
}

[TestFixture(SessionModeTypes.DistributedAuthority)]
[TestFixture(SessionModeTypes.ClientServer)]
[TestFixture(NetworkTopologyTypes.DistributedAuthority)]
[TestFixture(NetworkTopologyTypes.ClientServer)]
public class NetworkListChangedTests : NetcodeIntegrationTest
{
protected override int NumberOfClients => 2;
Expand All @@ -57,7 +57,7 @@ public class NetworkListChangedTests : NetcodeIntegrationTest

private NetworkObject m_NetSpawnedObject1;

public NetworkListChangedTests(SessionModeTypes sessionModeType) : base(sessionModeType) { }
public NetworkListChangedTests(NetworkTopologyTypes networkTopologyType) : base(networkTopologyType) { }

protected override void OnServerAndClientsCreated()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public struct NetVarCombinationTypes
/// <summary>
/// Server and Distributed Authority modes require at least 1 client while the host does not.
/// </summary>
/// [Session Mode][Number of Clients][First NetVar Type][Second NetVar Type]
/// [Host or Server mode][Number of Clients][First NetVar Type][Second NetVar Type]
[TestFixture(HostOrServer.DAHost, 1, NetVarContainer.NetVarsToCheck.One, NetVarContainer.NetVarsToCheck.One)]
[TestFixture(HostOrServer.DAHost, 1, NetVarContainer.NetVarsToCheck.One, NetVarContainer.NetVarsToCheck.Two)]
[TestFixture(HostOrServer.DAHost, 1, NetVarContainer.NetVarsToCheck.Two, NetVarContainer.NetVarsToCheck.Two)]
Expand Down Expand Up @@ -202,15 +202,15 @@ protected override void OnServerAndClientsCreated()
// GameObject of this prefab
var netVarContainer = m_PrefabToSpawn.AddComponent<NetVarContainer>();
netVarContainer.NumberOfNetVarsToCheck = m_NetVarCombinationTypes.FirstType;
if (m_SessionModeType == SessionModeTypes.DistributedAuthority)
if (m_NetworkTopologyType == NetworkTopologyTypes.DistributedAuthority)
{
netVarContainer.SetOwnerWrite();
}

netVarContainer.ValueToSetNetVarTo = NetVarValueToSet;
netVarContainer = m_PrefabToSpawn.AddComponent<NetVarContainer>();

if (m_SessionModeType == SessionModeTypes.DistributedAuthority)
if (m_NetworkTopologyType == NetworkTopologyTypes.DistributedAuthority)
{
netVarContainer.SetOwnerWrite();
}
Expand Down Expand Up @@ -243,7 +243,7 @@ public IEnumerator BehaviourUpdaterAllTests([Values(1, 2)] int numToSpawn)
// the appropriate number of NetworkObjects with the NetVarContainer behaviour
var numberOfObjectsToSpawn = numToSpawn * NumberOfClients;

var authority = m_SessionModeType == SessionModeTypes.DistributedAuthority ? m_ClientNetworkManagers[0] : m_ServerNetworkManager;
var authority = m_NetworkTopologyType == NetworkTopologyTypes.DistributedAuthority ? m_ClientNetworkManagers[0] : m_ServerNetworkManager;

// spawn the objects
for (int i = 0; i < numToSpawn; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ namespace Unity.Netcode.RuntimeTests
/// - Client destroy spawned => throw exception.
/// </summary>

[TestFixture(SessionModeTypes.DistributedAuthority)]
[TestFixture(SessionModeTypes.ClientServer)]
[TestFixture(NetworkTopologyTypes.DistributedAuthority)]
[TestFixture(NetworkTopologyTypes.ClientServer)]
public class NetworkObjectDestroyTests : NetcodeIntegrationTest
{
protected override int NumberOfClients => 2;

public NetworkObjectDestroyTests(SessionModeTypes sessionModeType) : base(sessionModeType) { }
public NetworkObjectDestroyTests(NetworkTopologyTypes networkTopologyType) : base(networkTopologyType) { }

/// <summary>
/// Tests that a server can destroy a NetworkObject and that it gets despawned correctly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace Unity.Netcode.RuntimeTests
{
[TestFixture(SessionModeTypes.DistributedAuthority)]
[TestFixture(SessionModeTypes.ClientServer)]
[TestFixture(NetworkTopologyTypes.DistributedAuthority)]
[TestFixture(NetworkTopologyTypes.ClientServer)]
public class NetworkObjectOnSpawnTests : NetcodeIntegrationTest
{
private GameObject m_TestNetworkObjectPrefab;
Expand All @@ -29,7 +29,7 @@ public enum ObserverTestTypes
private const string k_WithObserversError = "Not all clients spawned the";
private const string k_WithoutObserversError = "A client spawned the";

public NetworkObjectOnSpawnTests(SessionModeTypes sessionModeType) : base(sessionModeType) { }
public NetworkObjectOnSpawnTests(NetworkTopologyTypes networkTopologyType) : base(networkTopologyType) { }

protected override void OnServerAndClientsCreated()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

namespace Unity.Netcode.RuntimeTests
{
[TestFixture(SessionModeTypes.DistributedAuthority)]
[TestFixture(SessionModeTypes.ClientServer)]
[TestFixture(NetworkTopologyTypes.DistributedAuthority)]
[TestFixture(NetworkTopologyTypes.ClientServer)]
public class NetworkObjectOwnershipPropertiesTests : NetcodeIntegrationTest
{
private class DummyNetworkBehaviour : NetworkBehaviour
Expand All @@ -30,7 +30,7 @@ private class DummyNetworkBehaviour : NetworkBehaviour
private bool m_InitialOwnerOwnedBySever;
private bool m_TargetOwnerOwnedBySever;

public NetworkObjectOwnershipPropertiesTests(SessionModeTypes sessionModeType) : base(sessionModeType) { }
public NetworkObjectOwnershipPropertiesTests(NetworkTopologyTypes networkTopologyType) : base(networkTopologyType) { }

protected override IEnumerator OnTearDown()
{
Expand Down
Loading