diff --git a/Examples/OverridingScenesAndPrefabs/Assets/Scripts/NetworkManagerBootstrapper.cs b/Examples/OverridingScenesAndPrefabs/Assets/Scripts/NetworkManagerBootstrapper.cs index 2edccff2e6..0122bb3c7a 100644 --- a/Examples/OverridingScenesAndPrefabs/Assets/Scripts/NetworkManagerBootstrapper.cs +++ b/Examples/OverridingScenesAndPrefabs/Assets/Scripts/NetworkManagerBootstrapper.cs @@ -499,7 +499,7 @@ private void StartDedicatedServer() // Set the application frame rate to like 30 to reduce frame processing overhead Application.targetFrameRate = 30; - Debug.Log($"[Pre-Init] Server Address Endpoint: {m_UnityTransport.ConnectionData.ServerEndPoint}"); + Debug.Log($"[Pre-Init] Server Address Endpoint: {m_UnityTransport.ConnectionData.Address}:{m_UnityTransport.ConnectionData.Port}"); Debug.Log($"[Pre-Init] Server Listen Endpoint: {m_UnityTransport.ConnectionData.ListenEndPoint}"); // Setup your IP and port sepcific to your DGS //unityTransport.SetConnectionData(ListenAddress, ListenPort, ListenAddress); @@ -527,7 +527,7 @@ private void StartDedicatedServer() private void ServerStarted() { Debug.Log("Dedicated Server Started!"); - Debug.Log($"[Started] Server Address Endpoint: {m_UnityTransport.ConnectionData.ServerEndPoint}"); + Debug.Log($"[Started] Server Address Endpoint: {m_UnityTransport.ConnectionData.Address}:{m_UnityTransport.ConnectionData.Port}"); Debug.Log($"[Started] Server Listen Endpoint: {m_UnityTransport.ConnectionData.ListenEndPoint}"); Debug.Log("==============================================================="); Debug.Log("[X] Exits session (Shutdown) | [ESC] Exits application instance"); diff --git a/com.unity.netcode.gameobjects/CHANGELOG.md b/com.unity.netcode.gameobjects/CHANGELOG.md index ceaff931bb..bb03999610 100644 --- a/com.unity.netcode.gameobjects/CHANGELOG.md +++ b/com.unity.netcode.gameobjects/CHANGELOG.md @@ -20,6 +20,8 @@ Additional documentation and release notes are available at [Multiplayer Documen ### Deprecated +- Several APIs that were already marked `[Obsolete]` with a warning now raise a compile error instead (they are not removed yet). + ### Removed ### Fixed diff --git a/com.unity.netcode.gameobjects/Documentation~/advanced-topics/transports.md b/com.unity.netcode.gameobjects/Documentation~/advanced-topics/transports.md index 783f0f633c..842af7ded1 100644 --- a/com.unity.netcode.gameobjects/Documentation~/advanced-topics/transports.md +++ b/com.unity.netcode.gameobjects/Documentation~/advanced-topics/transports.md @@ -1,6 +1,6 @@ # Transports -Unity Netcode for GameObjects (Netcode) uses Unity Transport by default and supports UNet Transport (deprecated) up to Unity 2022.2 version. +Unity Netcode for GameObjects (Netcode) uses Unity Transport by default and also provides a single player transport. ## So what is a transport layer? @@ -18,11 +18,13 @@ A transport layer can provide: Netcode's default transport Unity Transport is an entire transport layer that you can use to add multiplayer and network features to your project with or without Netcode. Refer to the Transport [documentation](https://docs.unity3d.com/Packages/com.unity.transport@latest) for more information and how to [install](https://docs.unity3d.com/Packages/com.unity.transport@latest?subfolder=/manual/install.html). -## Unity's UNet Transport Layer API +Netcode provides a [UnityTransport](xref:Unity.Netcode.Transports.UTP.UnityTransport) implementation for easy transport integration with Netcode. -UNet is a deprecated solution that is no longer supported after Unity 2022.2. Unity Transport Package is the default transport for Netcode for GameObjects. We recommend transitioning to Unity Transport as soon as possible. +## Single player transport -### Community Transports or Writing Your Own +Netcode also provides a [single player transport](./singleplayer.md) that allows for easy switching between multiplayer and single player configurations. + +## Community Transports or Writing Your Own You can use any of the community contributed custom transport implementations or write your own. diff --git a/com.unity.netcode.gameobjects/Documentation~/command-line-arguments.md b/com.unity.netcode.gameobjects/Documentation~/command-line-arguments.md index 1f5552e312..581c04cf0a 100644 --- a/com.unity.netcode.gameobjects/Documentation~/command-line-arguments.md +++ b/com.unity.netcode.gameobjects/Documentation~/command-line-arguments.md @@ -23,40 +23,22 @@ You can define additional custom command-line arguments and retrieve them throug ## Example The following code shows you an example of defining and then reading a custom command-line argument. -``` -private const string k_OverrideArg = "-argName"; - -private bool ParseCommandLineOptions(out string command) -{ - if (CommandLineOptions.Instance.GetArg(k_OverrideArg) is string argValue) - { - command = argValue; - return true; - } - command = default; - return false; -} -``` + +[!code-cs[](../Tests/Runtime/DocumentationCodeSamples/Configuration/CommandLineOptionsDocsTests.cs#DefineAndRead)] Usage example: -``` -if (ParseCommandLineOptions(out var command)) -{ - // Your logic here -} -``` +[!code-cs[](../Tests/Runtime/DocumentationCodeSamples/Configuration/CommandLineOptionsDocsTests.cs#Usage)] ## Override connection data -If you want to ignore the connection port provided through command-line arguments, you can override it by using the optional `forceOverride` parameter in: +By default, the command line provided connection port and ip address take precedence over runtime configured values when using the [Unity transport](./advanced-topics/transports.md#unity-transport-package). -``` -UnityTransport.SetConnectionData(string ip, ushort port, string listenAddress, bool forceOverride); -``` +> [!NOTE] +> When the [Unity dedicated server package](https://docs.unity3d.com/Documentation/Manual/dedicated-server.html) is installed, Unity transport will use the port and ip address provided by the dedicated server package. -Setting `forceOverride` to `true` ensures that the values you pass to `SetConnectionData` override any values specified via command-line arguments. +If you want to ignore the connection port provided through command-line arguments, you can override it by setting the `forceOverrideCommandLineArgs` parameter of UnityTransport's [`SetConnectionData`](xref:Unity.Netcode.Transports.UTP.UnityTransport.SetConnectionData(System.Boolean,System.String,System.UInt16,System.String)). Setting `forceOverrideCommandLineArgs` to `true` ensures that the values you pass to `SetConnectionData` will override any values specified via command-line arguments. ## Additional resources -- [Command-line arguments in the Unity Manual](https://docs.unity3d.com/6000.2/Documentation/Manual/CommandLineArguments.html) +- [Command-line arguments in the Unity Manual](https://docs.unity3d.com/Documentation/Manual/CommandLineArguments.html) diff --git a/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs b/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs index 3918b03da8..0714f554dd 100644 --- a/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs +++ b/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs @@ -617,11 +617,6 @@ private void CreateNetworkVariableTypeInitializers(AssemblyDefinition assembly, private const string k_RpcAttribute_Delivery = nameof(RpcAttribute.Delivery); private const string k_RpcAttribute_InvokePermission = nameof(RpcAttribute.InvokePermission); -#pragma warning disable CS0618 // Type or member is obsolete - // Need to ignore the obsolete warning as the obsolete behaviour still needs to work - private const string k_ServerRpcAttribute_RequireOwnership = nameof(ServerRpcAttribute.RequireOwnership); -#pragma warning restore CS0618 // Type or member is obsolete - private const string k_RpcParams_Server = nameof(__RpcParams.Server); private const string k_RpcParams_Client = nameof(__RpcParams.Client); private const string k_RpcParams_Ext = nameof(__RpcParams.Ext); @@ -1502,10 +1497,6 @@ private void ProcessNetworkBehaviour(TypeDefinition typeDefinition, string[] ass { switch (attrField.Name) { - case k_ServerRpcAttribute_RequireOwnership: - var requireOwnership = attrField.Argument.Type == rpcHandler.Module.TypeSystem.Boolean && (bool)attrField.Argument.Value; - invokePermission = requireOwnership ? RpcInvokePermission.Owner : RpcInvokePermission.Everyone; - break; case k_RpcAttribute_InvokePermission: invokePermission = (RpcInvokePermission)attrField.Argument.Value; break; @@ -1692,28 +1683,6 @@ private CustomAttribute CheckAndGetRpcAttribute(MethodDefinition methodDefinitio return null; } - bool hasInvokePermission = false, hasRequireOwnership = false; - - foreach (var argument in rpcAttribute.Fields) - { - switch (argument.Name) - { - case k_ServerRpcAttribute_RequireOwnership: - hasRequireOwnership = true; - break; - case k_RpcAttribute_InvokePermission: - hasInvokePermission = true; - break; - } - } - - if (hasInvokePermission && hasRequireOwnership) - { - m_Diagnostics.AddError($"{methodDefinition.Name} cannot declare both RequireOwnership and InvokePermission!"); - return null; - } - - // Checks for IsSerializable are moved to later as the check is now done by dynamically seeing if any valid // serializer OR extension method exists for it. return rpcAttribute; @@ -2180,7 +2149,6 @@ private void InjectWriteAndCallBlocks(MethodDefinition methodDefinition, CustomA var isServerRpc = rpcAttribute.AttributeType.FullName == CodeGenHelpers.ServerRpcAttribute_FullName; var isClientRpc = rpcAttribute.AttributeType.FullName == CodeGenHelpers.ClientRpcAttribute_FullName; var isGenericRpc = rpcAttribute.AttributeType.FullName == CodeGenHelpers.RpcAttribute_FullName; - var requireOwnership = true; // default value MUST be == `ServerRpcAttribute.RequireOwnership` var rpcDelivery = RpcDelivery.Reliable; // default value MUST be == `RpcAttribute.Delivery` var defaultTarget = SendTo.Everyone; var allowTargetOverride = false; @@ -2196,9 +2164,6 @@ private void InjectWriteAndCallBlocks(MethodDefinition methodDefinition, CustomA case k_RpcAttribute_Delivery: rpcDelivery = (RpcDelivery)attrField.Argument.Value; break; - case k_ServerRpcAttribute_RequireOwnership: - requireOwnership = attrField.Argument.Type == typeSystem.Boolean && (bool)attrField.Argument.Value; - break; case nameof(RpcAttribute.AllowTargetOverride): allowTargetOverride = attrField.Argument.Type == typeSystem.Boolean && (bool)attrField.Argument.Value; break; @@ -2320,7 +2285,8 @@ private void InjectWriteAndCallBlocks(MethodDefinition methodDefinition, CustomA { // ServerRpc - if (requireOwnership) + // Require ownership check. + // Only the owner of an object can send a ServerRPC { var roReturnInstr = processor.Create(OpCodes.Ret); var roLastInstr = processor.Create(OpCodes.Nop); @@ -2347,7 +2313,7 @@ private void InjectWriteAndCallBlocks(MethodDefinition methodDefinition, CustomA instructions.Add(processor.Create(OpCodes.Brfalse, logNextInstr)); // Debug.LogError(...); - instructions.Add(processor.Create(OpCodes.Ldstr, "Only the owner can invoke a ServerRpc that requires ownership!")); + instructions.Add(processor.Create(OpCodes.Ldstr, "Only the owner can invoke a ServerRpc!")); instructions.Add(processor.Create(OpCodes.Call, m_Debug_LogError_MethodRef)); instructions.Add(logNextInstr); @@ -2963,16 +2929,6 @@ private MethodDefinition GenerateStaticHandler(MethodDefinition methodDefinition var processor = rpcHandler.Body.GetILProcessor(); var isServerRpc = rpcAttribute.AttributeType.FullName == CodeGenHelpers.ServerRpcAttribute_FullName; - var requireOwnership = true; // default value MUST be == `ServerRpcAttribute.RequireOwnership` - foreach (var attrField in rpcAttribute.Fields) - { - switch (attrField.Name) - { - case k_ServerRpcAttribute_RequireOwnership: - requireOwnership = attrField.Argument.Type == typeSystem.Boolean && (bool)attrField.Argument.Value; - break; - } - } rpcHandler.Body.InitLocals = true; // NetworkManager networkManager; @@ -2999,7 +2955,7 @@ private MethodDefinition GenerateStaticHandler(MethodDefinition methodDefinition processor.Append(lastInstr); } - if (isServerRpc && requireOwnership) + if (isServerRpc) { var roReturnInstr = processor.Create(OpCodes.Ret); var roLastInstr = processor.Create(OpCodes.Nop); @@ -3028,7 +2984,7 @@ private MethodDefinition GenerateStaticHandler(MethodDefinition methodDefinition processor.Emit(OpCodes.Brfalse, logNextInstr); // Debug.LogError(...); - processor.Emit(OpCodes.Ldstr, "Only the owner can invoke a ServerRpc that requires ownership!"); + processor.Emit(OpCodes.Ldstr, "Only the owner can invoke a ServerRpc!"); processor.Emit(OpCodes.Call, m_Debug_LogError_MethodRef); processor.Append(logNextInstr); diff --git a/com.unity.netcode.gameobjects/Editor/CodeGen/RuntimeAccessModifiersILPP.cs b/com.unity.netcode.gameobjects/Editor/CodeGen/RuntimeAccessModifiersILPP.cs index fa15a7251f..edd6ada1b0 100644 --- a/com.unity.netcode.gameobjects/Editor/CodeGen/RuntimeAccessModifiersILPP.cs +++ b/com.unity.netcode.gameobjects/Editor/CodeGen/RuntimeAccessModifiersILPP.cs @@ -47,9 +47,6 @@ public override ILPostProcessResult Process(ICompiledAssembly compiledAssembly) switch (typeDefinition.Name) { - case nameof(NetworkManager): - ProcessNetworkManager(typeDefinition, compiledAssembly.Defines); - break; case nameof(NetworkBehaviour): ProcessNetworkBehaviour(typeDefinition); break; @@ -90,46 +87,6 @@ public override ILPostProcessResult Process(ICompiledAssembly compiledAssembly) return new ILPostProcessResult(new InMemoryAssembly(pe.ToArray(), pdb.ToArray()), m_Diagnostics); } - // TODO: Deprecate... - // This is changing accessibility for values that are no longer used, but since our validator runs - // after ILPP and sees those values as public, they cannot be removed until a major version change. - private void ProcessNetworkManager(TypeDefinition typeDefinition, string[] assemblyDefines) - { - foreach (var fieldDefinition in typeDefinition.Fields) - { -#pragma warning disable CS0618 // Type or member is obsolete - if (fieldDefinition.Name == nameof(NetworkManager.__rpc_func_table)) -#pragma warning restore CS0618 // Type or member is obsolete - { - fieldDefinition.IsPublic = true; - } - -#pragma warning disable CS0618 // Type or member is obsolete - if (fieldDefinition.Name == nameof(NetworkManager.RpcReceiveHandler)) -#pragma warning restore CS0618 // Type or member is obsolete - { - fieldDefinition.IsPublic = true; - } - -#pragma warning disable CS0618 // Type or member is obsolete - if (fieldDefinition.Name == nameof(NetworkManager.__rpc_name_table)) -#pragma warning restore CS0618 // Type or member is obsolete - { - fieldDefinition.IsPublic = true; - } - } - - foreach (var nestedTypeDefinition in typeDefinition.NestedTypes) - { -#pragma warning disable CS0618 // Type or member is obsolete - if (nestedTypeDefinition.Name == nameof(NetworkManager.RpcReceiveHandler)) -#pragma warning restore CS0618 // Type or member is obsolete - { - nestedTypeDefinition.IsNestedPublic = true; - } - } - } - private void ProcessNetworkBehaviour(TypeDefinition typeDefinition) { foreach (var nestedType in typeDefinition.NestedTypes) diff --git a/com.unity.netcode.gameobjects/Editor/NetworkObjectEditor.cs b/com.unity.netcode.gameobjects/Editor/NetworkObjectEditor.cs index d5dd23b09d..2d3c7baafe 100644 --- a/com.unity.netcode.gameobjects/Editor/NetworkObjectEditor.cs +++ b/com.unity.netcode.gameobjects/Editor/NetworkObjectEditor.cs @@ -101,10 +101,6 @@ public override void OnInspectorGUI() EditorGUILayout.Toggle(nameof(NetworkObject.IsOwner), m_NetworkObject.IsOwner); EditorGUILayout.Toggle(nameof(NetworkObject.IsOwnedByServer), m_NetworkObject.IsOwnedByServer); EditorGUILayout.Toggle(nameof(NetworkObject.IsPlayerObject), m_NetworkObject.IsPlayerObject); -#pragma warning disable CS0618 // Type or member is obsolete - // TODO-3.x: Update name in 3.x branch - EditorGUILayout.Toggle(nameof(NetworkObject.IsSceneObject), m_NetworkObject.InScenePlaced); -#pragma warning restore CS0618 // Type or member is obsolete EditorGUILayout.Toggle(nameof(NetworkObject.DestroyWithScene), m_NetworkObject.DestroyWithScene); EditorGUILayout.TextField(nameof(NetworkObject.NetworkManager), m_NetworkObject.NetworkManager == null ? "null" : m_NetworkObject.NetworkManager.gameObject.name); GUI.enabled = guiEnabled; diff --git a/com.unity.netcode.gameobjects/Runtime/Components/Interpolator/BufferedLinearInterpolator.cs b/com.unity.netcode.gameobjects/Runtime/Components/Interpolator/BufferedLinearInterpolator.cs index 4cee25748e..d38090550e 100644 --- a/com.unity.netcode.gameobjects/Runtime/Components/Interpolator/BufferedLinearInterpolator.cs +++ b/com.unity.netcode.gameobjects/Runtime/Components/Interpolator/BufferedLinearInterpolator.cs @@ -59,28 +59,28 @@ private float GetPrecision() /// /// This is replaced by the of type . /// - [Obsolete("This list is no longer used and will be deprecated.", false)] + [Obsolete("This list is no longer used and will be deprecated.", true)] protected internal readonly List m_Buffer = new List(); /// /// ** Deprecating ** /// The starting value of type to interpolate from. /// - [Obsolete("This property will be deprecated.", false)] + [Obsolete("This property will be deprecated.", true)] protected internal T m_InterpStartValue; /// /// ** Deprecating ** /// The current value of type . /// - [Obsolete("This property will be deprecated.", false)] + [Obsolete("This property will be deprecated.", true)] protected internal T m_CurrentInterpValue; /// /// ** Deprecating ** /// The end (or target) value of type to interpolate towards. /// - [Obsolete("This property will be deprecated.", false)] + [Obsolete("This property will be deprecated.", true)] protected internal T m_InterpEndValue; #endregion @@ -651,7 +651,7 @@ public T Update(float deltaTime, double renderTime, double serverTime) /// time since call /// current server time /// The newly interpolated value of type 'T' - [Obsolete("This method is being deprecated due to it being only used for internal testing purposes.", false)] + [Obsolete("This method is being deprecated due to it being only used for internal testing purposes.", true)] public T Update(float deltaTime, NetworkTime serverTime) { return UpdateInternal(deltaTime, serverTime); diff --git a/com.unity.netcode.gameobjects/Runtime/Components/NetworkTransform.cs b/com.unity.netcode.gameobjects/Runtime/Components/NetworkTransform.cs index 9f4b04d368..a61ddc2468 100644 --- a/com.unity.netcode.gameobjects/Runtime/Components/NetworkTransform.cs +++ b/com.unity.netcode.gameobjects/Runtime/Components/NetworkTransform.cs @@ -3861,17 +3861,6 @@ protected void Initialize() #region PARENTING AND OWNERSHIP /// - public override void OnLostOwnership() - { - base.OnLostOwnership(); - } - - /// - public override void OnGainedOwnership() - { - base.OnGainedOwnership(); - } - /// protected override void OnOwnershipChanged(ulong previous, ulong current) { // If we were the previous owner or the newly assigned owner then reinitialize diff --git a/com.unity.netcode.gameobjects/Runtime/Configuration/CommandLineOptions.cs b/com.unity.netcode.gameobjects/Runtime/Configuration/CommandLineOptions.cs index 67878b125a..4ae6e7e6f3 100644 --- a/com.unity.netcode.gameobjects/Runtime/Configuration/CommandLineOptions.cs +++ b/com.unity.netcode.gameobjects/Runtime/Configuration/CommandLineOptions.cs @@ -12,7 +12,7 @@ public class CommandLineOptions /// /// Command-line options singleton /// - [Obsolete("Not used anymore replaced by TryGetArg")] + [Obsolete("Not used anymore replaced by TryGetArg", true)] public static CommandLineOptions Instance { get @@ -38,7 +38,7 @@ private set /// /// The name of the argument /// Value of the command line argument passed in. - [Obsolete("Not used anymore replaced by TryGetArg")] + [Obsolete("Not used anymore replaced by TryGetArg", true)] public string GetArg(string arg) { var argIndex = k_CommandLineArguments.IndexOf(arg); diff --git a/com.unity.netcode.gameobjects/Runtime/Connection/NetworkConnectionManager.cs b/com.unity.netcode.gameobjects/Runtime/Connection/NetworkConnectionManager.cs index 3ff131131f..f614843cef 100644 --- a/com.unity.netcode.gameobjects/Runtime/Connection/NetworkConnectionManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/Connection/NetworkConnectionManager.cs @@ -1026,7 +1026,6 @@ internal void HandleConnectionApproval(ulong ownerClientId, bool createPlayerObj if (NetworkManager.SpawnManager.AuthorityLocalSpawn( playerObject, NetworkManager.SpawnManager.GetNetworkObjectId(), - sceneObject: false, playerObject: true, ownerClientId, destroyWithScene: false)) @@ -1189,11 +1188,6 @@ internal void CreateAndSpawnPlayer(ulong ownerId) return; } -#pragma warning disable CS0618 // Type or member is obsolete - // Obsolete with warning means we need the underlying behaviour to keep existing - // TODO: remove in the 3.x branch - networkObject.SetSceneObjectStatus(false); -#pragma warning restore CS0618 // Type or member is obsolete networkObject.NetworkManagerOwner = NetworkManager; networkObject.SpawnAsPlayerObject(ownerId, networkObject.DestroyWithScene); } diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs index e024765a72..b05578fed0 100644 --- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs +++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs @@ -335,11 +335,7 @@ internal FastBufferWriter __beginSendRpc(uint rpcMethodId, RpcParams rpcParams, throw new RpcException("This RPC can only be sent by the server."); } -#pragma warning disable CS0618 // Type or member is obsolete - var requireOwnership = attributeParams.RequireOwnership; -#pragma warning restore CS0618 // Type or member is obsolete - - if ((requireOwnership || attributeParams.InvokePermission == RpcInvokePermission.Owner) && !IsOwner) + if (attributeParams.InvokePermission == RpcInvokePermission.Owner && !IsOwner) { throw new RpcException("This RPC can only be sent by its owner."); } diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs index 0a3fee02d7..748175ff1f 100644 --- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs @@ -65,25 +65,6 @@ private static void ResetStaticsOnLoad() public bool NetworkManagerExpanded; #endif - // TODO: Deprecate... - // The following internal values are not used, but because ILPP makes them public in the assembly, they cannot - // be removed thanks to our semver validation. -#pragma warning disable IDE1006 // disable naming rule violation check - - // RuntimeAccessModifiersILPP will make this `public` - [Obsolete("This field is no longer used and will be removed in a future version.")] - internal delegate void RpcReceiveHandler(NetworkBehaviour behaviour, FastBufferReader reader, __RpcParams parameters); - - // RuntimeAccessModifiersILPP will make this `public` - [Obsolete("This field is no longer used and will be removed in a future version.")] - internal static readonly Dictionary __rpc_func_table = new Dictionary(); - - // RuntimeAccessModifiersILPP will make this `public` (legacy table should be removed in v3.x.x) - [Obsolete("This field is no longer used and will be removed in a future version.")] - internal static readonly Dictionary __rpc_name_table = new Dictionary(); - -#pragma warning restore IDE1006 // restore naming rule violation check - #if DEBUG private static List s_SerializedType = new List(); // This is used to control the serialized type not optimized messaging for integration test purposes diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs index 94364a217a..2ec3eedacf 100644 --- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs +++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs @@ -347,12 +347,6 @@ private void CheckForInScenePlaced() } } -#pragma warning disable CS0618 // Type or member is obsolete - // Obsolete with warning means we need the underlying behaviour to keep existing - // TODO-3.x: remove in the 3.x branch - SetSceneObjectStatus(true); -#pragma warning restore CS0618 // Type or member is obsolete - // We go ahead and set this for "typical in-scene placed" usage patterns so this is serialized InScenePlaced = true; @@ -1323,10 +1317,9 @@ public bool HasOwnershipStatus(OwnershipStatus status) /// This method is marked for deprecation.
/// Use instead. /// - [Obsolete("Use InScenePlaced instead")] + [Obsolete("Use InScenePlaced instead", true)] public bool? IsSceneObject { get; internal set; } - /// /// The serialized value. /// @@ -1361,10 +1354,9 @@ internal set /// /// Only use this when using custom scene loading /// When true, marks this as a scene-instantiated object; when false, marks it as runtime-instantiated - [Obsolete("SetSceneObjectStatus is now calculated during the build.")] + [Obsolete("SetSceneObjectStatus is now calculated during the build.", true)] public void SetSceneObjectStatus(bool isSceneObject = false) { - IsSceneObject = isSceneObject; } /// @@ -1990,12 +1982,6 @@ private void SpawnInternal(bool destroyWithScene, ulong ownerClientId, bool play return; } - // Calculate the legacy IsSceneObject value as the public field is obsolete with warning - // We can't break the public behavior of the field. -#pragma warning disable CS0618 // Type or member is obsolete - var legacyIsSceneObject = IsSceneObject.HasValue && IsSceneObject.Value; -#pragma warning restore CS0618 // Type or member is obsolete - // If the initial state of the GameObject was disabled and InScenePlaced is marked, // then spawn it as in-scene placed. // Otherwise: @@ -2012,7 +1998,7 @@ private void SpawnInternal(bool destroyWithScene, ulong ownerClientId, bool play InScenePlaced = false; } - if (!NetworkManagerOwner.SpawnManager.AuthorityLocalSpawn(this, NetworkManagerOwner.SpawnManager.GetNetworkObjectId(), legacyIsSceneObject, playerObject, ownerClientId, destroyWithScene)) + if (!NetworkManagerOwner.SpawnManager.AuthorityLocalSpawn(this, NetworkManagerOwner.SpawnManager.GetNetworkObjectId(), playerObject, ownerClientId, destroyWithScene)) { if (NetworkManagerOwner.LogLevel <= LogLevel.Normal) { diff --git a/com.unity.netcode.gameobjects/Runtime/Exceptions/NotListeningException.cs b/com.unity.netcode.gameobjects/Runtime/Exceptions/NotListeningException.cs index 9c2c52e520..14f1b6808c 100644 --- a/com.unity.netcode.gameobjects/Runtime/Exceptions/NotListeningException.cs +++ b/com.unity.netcode.gameobjects/Runtime/Exceptions/NotListeningException.cs @@ -5,7 +5,7 @@ namespace Unity.Netcode /// /// Exception thrown when the operation require NetworkManager to be listening. /// - [Obsolete("Not used anymore.")] + [Obsolete("Not used anymore.", true)] public class NotListeningException : Exception { /// diff --git a/com.unity.netcode.gameobjects/Runtime/Messaging/RpcAttributes.cs b/com.unity.netcode.gameobjects/Runtime/Messaging/RpcAttributes.cs index 59555210c3..0182aa88fe 100644 --- a/com.unity.netcode.gameobjects/Runtime/Messaging/RpcAttributes.cs +++ b/com.unity.netcode.gameobjects/Runtime/Messaging/RpcAttributes.cs @@ -62,7 +62,7 @@ public struct RpcAttributeParams /// /// Deprecated in favor of . /// - [Obsolete("RequireOwnership is deprecated. Please use InvokePermission instead.")] + [Obsolete("RequireOwnership is deprecated. Please use InvokePermission instead.", true)] public bool RequireOwnership; /// @@ -98,7 +98,7 @@ public struct RpcAttributeParams /// /// Deprecated in favor of . /// - [Obsolete("RequireOwnership is deprecated. Please use InvokePermission = RpcInvokePermission.Owner or InvokePermission = RpcInvokePermission.Everyone instead.")] + [Obsolete("RequireOwnership is deprecated. Please use InvokePermission = RpcInvokePermission.Owner or InvokePermission = RpcInvokePermission.Everyone instead.", true)] public bool RequireOwnership; /// @@ -151,7 +151,7 @@ public class ServerRpcAttribute : RpcAttribute /// [Rpc(SendTo.Server, InvokePermission = RpcInvokePermission.Owner)] /// /// - [Obsolete("ServerRpc with RequireOwnership is deprecated. Use [Rpc(SendTo.Server, InvokePermission = RpcInvokePermission.Everyone)] or [Rpc(SendTo.Server, InvokePermission = RpcInvokePermission.Owner)] instead.)]")] + [Obsolete("ServerRpc with RequireOwnership is deprecated. Use [Rpc(SendTo.Server, InvokePermission = RpcInvokePermission.Everyone)] or [Rpc(SendTo.Server, InvokePermission = RpcInvokePermission.Owner)] instead.)]", true)] public new bool RequireOwnership; /// diff --git a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs index acf139b0d1..731ba2bc36 100644 --- a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs +++ b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs @@ -686,7 +686,7 @@ private void HandleAddListEvent(NetworkListEvent listEvent) /// /// This method should not be used. It is left over from a previous interface /// - [Obsolete("This property is no longer used and will be removed in a future version.")] + [Obsolete("This property is no longer used and will be removed in a future version.", true)] public int LastModifiedTick => NetworkTickSystem.NoTick; /// diff --git a/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs b/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs index 15f8b5afe4..8ee61a95ab 100644 --- a/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs @@ -1842,7 +1842,7 @@ private void OnSessionOwnerLoadedScene(uint sceneEventId, Scene scene) { // All in-scene placed NetworkObjects default to being owned by the server NetworkManager.SpawnManager.AuthorityLocalSpawn(keyValuePairBySceneHandle.Value, - NetworkManager.SpawnManager.GetNetworkObjectId(), true, false, NetworkManager.LocalClientId, true); + NetworkManager.SpawnManager.GetNetworkObjectId(), false, NetworkManager.LocalClientId, true); } } } diff --git a/com.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs b/com.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs index b0a3c6b6b0..ad465c4d9c 100644 --- a/com.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs @@ -452,7 +452,7 @@ private bool TryGetNetworkClient(ulong clientId, out NetworkClient networkClient /// /// not used /// not used - [Obsolete("This method is no longer used and will be removed in a future version.")] + [Obsolete("This method is no longer used and will be removed in a future version.", true)] protected virtual void InternalOnOwnershipChanged(ulong perviousOwner, ulong newOwner) { @@ -1110,7 +1110,7 @@ internal NetworkObject CreateLocalNetworkObject(NetworkObject.SerializedObject s /// Distributed Authority: /// All clients can invoke this method. /// - internal bool AuthorityLocalSpawn([NotNull] NetworkObject networkObject, ulong networkId, bool sceneObject, bool playerObject, ulong ownerClientId, bool destroyWithScene) + internal bool AuthorityLocalSpawn([NotNull] NetworkObject networkObject, ulong networkId, bool playerObject, ulong ownerClientId, bool destroyWithScene) { if (networkObject.IsSpawned) { @@ -1158,7 +1158,7 @@ internal bool AuthorityLocalSpawn([NotNull] NetworkObject networkObject, ulong n } - if (!SpawnNetworkObjectLocallyCommon(networkObject, networkId, sceneObject, playerObject, ownerClientId, destroyWithScene)) + if (!SpawnNetworkObjectLocallyCommon(networkObject, networkId, playerObject, ownerClientId, destroyWithScene)) { if (NetworkManager.LogLevel <= LogLevel.Error) { @@ -1254,13 +1254,13 @@ internal bool NonAuthorityLocalSpawn(in NetworkObject.SerializedObject serialize // being told we do not have a parent, then we want to clear the latest parent so it is not automatically // "re-parented" to the original parent. This can happen if not unloading the scene and the parenting of // the in-scene placed Networkobject changes several times over different sessions. - if (serializedObject.IsSceneObject && !serializedObject.HasParent && networkObject.GetNetworkParenting().HasValue) + if (networkObject.InScenePlaced && !serializedObject.HasParent && networkObject.GetNetworkParenting().HasValue) { networkObject.ClearNetworkParenting(); } // Do not invoke Pre spawn here (SynchronizeNetworkBehaviours needs to be invoked prior to this) - var succeeded = SpawnNetworkObjectLocallyCommon(networkObject, serializedObject.NetworkObjectId, serializedObject.IsSceneObject, serializedObject.IsPlayerObject, serializedObject.OwnerClientId, destroyWithScene); + var succeeded = SpawnNetworkObjectLocallyCommon(networkObject, serializedObject.NetworkObjectId, serializedObject.IsPlayerObject, serializedObject.OwnerClientId, destroyWithScene); if (!succeeded) { // Don't need to log here as SpawnNetworkObjectLocallyCommon should log the specific error @@ -1278,7 +1278,7 @@ internal bool NonAuthorityLocalSpawn(in NetworkObject.SerializedObject serialize /// /// boolean indicating whether the spawn succeeded. // Internal dev note: THIS IS A CATCH FOR OURSELVES. DON'T PULL OUT - internal bool SpawnNetworkObjectLocallyCommon(NetworkObject networkObject, ulong networkId, bool sceneObject, bool playerObject, ulong ownerClientId, bool destroyWithScene) + internal bool SpawnNetworkObjectLocallyCommon(NetworkObject networkObject, ulong networkId, bool playerObject, ulong ownerClientId, bool destroyWithScene) { // TODO: Replace the following checks with internal Netcode asserts // We want our tests to double check this without impacting users. @@ -1300,12 +1300,6 @@ internal bool SpawnNetworkObjectLocallyCommon(NetworkObject networkObject, ulong return false; } -#pragma warning disable CS0618 // Type or member is obsolete - // Obsolete with warning means we need the underlying behaviour to keep existing - // TODO: remove in the 3.x branch - networkObject.SetSceneObjectStatus(sceneObject); -#pragma warning restore CS0618 // Type or member is obsolete - networkObject.SetupOnSpawn(networkId, playerObject, ownerClientId, destroyWithScene); SpawnedObjects.Add(networkObject.NetworkObjectId, networkObject); @@ -1661,7 +1655,7 @@ internal void ServerSpawnSceneObjectsOnStartSweep() ownerId = NetworkManager.LocalClientId; } - if (AuthorityLocalSpawn(networkObject, GetNetworkObjectId(), true, false, ownerId, true)) + if (AuthorityLocalSpawn(networkObject, GetNetworkObjectId(), false, ownerId, true)) { networkObjectsToSpawn.Add(networkObject); } diff --git a/com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs b/com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs index f8ce9d815c..b951353bdb 100644 --- a/com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs +++ b/com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs @@ -61,7 +61,7 @@ public enum ProtocolType /// /// The default maximum send queue size /// - [Obsolete("MaxSendQueueSize is now determined dynamically (can still be set programmatically using the MaxSendQueueSize property). This initial value is not used anymore.", false)] + [Obsolete("MaxSendQueueSize is now determined dynamically (can still be set programmatically using the MaxSendQueueSize property). This initial value is not used anymore.", true)] public const int InitialMaxSendQueueSize = 16 * InitialMaxPayloadSize; // Maximum reliable throughput, assuming the full reliable window can be sent on every @@ -266,7 +266,7 @@ internal static NetworkEndpoint ParseNetworkEndpoint(string ip, ushort port) /// is still handled correctly by NGO, but for this reason usage of this property is /// discouraged. /// - [Obsolete("Use NetworkEndpoint.Parse on the Address field instead.")] + [Obsolete("Use NetworkEndpoint.Parse on the Address field instead.", true)] public NetworkEndpoint ServerEndPoint => ParseNetworkEndpoint(Address, Port); /// @@ -313,6 +313,7 @@ public NetworkEndpoint ListenEndPoint /// /// Parameters for the Network Simulator /// + [Obsolete("SimulatorParameters are no longer used and have no effect. Use Network Simulator from the Multiplayer Tools package.", false)] [Serializable] public struct SimulatorParameters { @@ -345,7 +346,7 @@ public struct SimulatorParameters /// - packet drop rate (packet loss) /// - [Obsolete("DebugSimulator is no longer supported and has no effect. Use Network Simulator from the Multiplayer Tools package.", false)] + [Obsolete("DebugSimulator is no longer supported and has no effect. Use Network Simulator from the Multiplayer Tools package.", true)] [HideInInspector] public SimulatorParameters DebugSimulator = new SimulatorParameters { @@ -966,7 +967,7 @@ public void SetConnectionData(NetworkEndpoint endPoint, NetworkEndpoint listenEn /// Packet delay in milliseconds. /// Packet jitter in milliseconds. /// Packet drop percentage. - [Obsolete("SetDebugSimulatorParameters is no longer supported and has no effect. Use Network Simulator from the Multiplayer Tools package.", false)] + [Obsolete("SetDebugSimulatorParameters is no longer supported and has no effect. Use Network Simulator from the Multiplayer Tools package.", true)] public void SetDebugSimulatorParameters(int packetDelay, int packetJitter, int dropRate) { if (m_Driver.IsCreated) diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/DocumentationCodeSamples/Configuration/CommandLineOptionsDocsTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/DocumentationCodeSamples/Configuration/CommandLineOptionsDocsTests.cs new file mode 100644 index 0000000000..bd24f2ad23 --- /dev/null +++ b/com.unity.netcode.gameobjects/Tests/Runtime/DocumentationCodeSamples/Configuration/CommandLineOptionsDocsTests.cs @@ -0,0 +1,46 @@ +using NUnit.Framework; +using Unity.Netcode; + +namespace DocumentationCodeSamples +{ + internal class CommandLineOptionsDocsTests + { + #region DefineAndRead + private const string k_OverrideArg = "-argName"; + + private bool ParseCommandLineOptions(out string command) + { + if (CommandLineOptions.TryGetArg(k_OverrideArg, out var argValue)) + { + command = argValue; + return true; + } + command = default; + return false; + } + #endregion + + private string CommandLineUsage() + { + #region Usage + if (ParseCommandLineOptions(out var command)) + { + // Your logic here + } + #endregion + + return command; + } + + [Test] + public void TestCommandLineUsage() + { + // This is a compile test. + var succeeded = ParseCommandLineOptions(out var command); + Assert.NotNull(succeeded); + + var output = CommandLineUsage(); + Assert.AreEqual(command, output); + } + } +} diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/DocumentationCodeSamples/Configuration/CommandLineOptionsDocsTests.cs.meta b/com.unity.netcode.gameobjects/Tests/Runtime/DocumentationCodeSamples/Configuration/CommandLineOptionsDocsTests.cs.meta new file mode 100644 index 0000000000..c2cee69fd8 --- /dev/null +++ b/com.unity.netcode.gameobjects/Tests/Runtime/DocumentationCodeSamples/Configuration/CommandLineOptionsDocsTests.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: fe24c7026b40477c9941e9f7eca90a12 +timeCreated: 1788274882 \ No newline at end of file diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/Rpc/RpcInvocationTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/Rpc/RpcInvocationTests.cs index 83cdb828bf..1f36ae9837 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/Rpc/RpcInvocationTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/Rpc/RpcInvocationTests.cs @@ -98,13 +98,11 @@ public IEnumerator RpcInvokePermissionSendingTests() foreach (var (manager, instance) in m_InvokeInstances) { instance.ExpectedCallCounts[nameof(InvokePermissionBehaviour.OwnerInvokePermissionRpc)] = 1; - instance.ExpectedCallCounts[nameof(InvokePermissionBehaviour.OwnerRequireOwnershipRpc)] = 1; var threwException = false; try { instance.OwnerInvokePermissionRpc(); - instance.OwnerRequireOwnershipRpc(); } catch (RpcException) { @@ -178,10 +176,8 @@ public IEnumerator RpcInvokePermissionReceivingTests() foreach (var (manager, instance) in m_InvokeInstances) { instance.ExpectedCallCounts[nameof(InvokePermissionBehaviour.OwnerInvokePermissionRpc)] = 1; - instance.ExpectedCallCounts[nameof(InvokePermissionBehaviour.OwnerRequireOwnershipRpc)] = 1; SendUncheckedMessage(manager, instance, nameof(InvokePermissionBehaviour.OwnerInvokePermissionRpc)); - SendUncheckedMessage(manager, instance, nameof(InvokePermissionBehaviour.OwnerRequireOwnershipRpc)); } yield return WaitForConditionOrTimeOut(AllExpectedCallsReceived); @@ -464,15 +460,6 @@ public void ServerInvokePermissionRpc() TrackRpcCalled(GetCaller()); } - -#pragma warning disable CS0618 // Type or member is obsolete - [Rpc(SendTo.Everyone, RequireOwnership = true)] -#pragma warning restore CS0618 // Type or member is obsolete - public void OwnerRequireOwnershipRpc() - { - TrackRpcCalled(GetCaller()); - } - [Rpc(SendTo.Everyone, InvokePermission = RpcInvokePermission.Owner)] public void OwnerInvokePermissionRpc() { diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/TestHelpers/NetcodeIntegrationTestHelpers.cs b/com.unity.netcode.gameobjects/Tests/Runtime/TestHelpers/NetcodeIntegrationTestHelpers.cs index 792db8d478..4be45b5927 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/TestHelpers/NetcodeIntegrationTestHelpers.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/TestHelpers/NetcodeIntegrationTestHelpers.cs @@ -811,7 +811,7 @@ public static GameObject CreateNetworkObjectPrefab(string baseName, NetworkManag /// /// /// An array of s - [Obsolete("This method is no longer valid or used.", false)] + [Obsolete("This method is no longer valid or used.", true)] public static void MarkAsSceneObjectRoot(GameObject networkObjectRoot, NetworkManager server, NetworkManager[] clients) { } @@ -1173,7 +1173,7 @@ private static IEnumerator ExecuteWaitForHook(MessageHandleCheckWithResult check /// This method is no longer used. /// /// - [Obsolete("This method is deprecated and no longer used", false)] + [Obsolete("This method is deprecated and no longer used", true)] public static void SetRefreshAllPrefabsCallback(Action scenesProcessed) { NetworkObjectRefreshTool.AllScenesProcessed = scenesProcessed; @@ -1184,7 +1184,7 @@ public static void SetRefreshAllPrefabsCallback(Action scenesProcessed) /// /// /// - [Obsolete("This method is deprecated and no longer used", false)] + [Obsolete("This method is deprecated and no longer used", true)] public static void RefreshAllPrefabInstances(NetworkObject networkObject, Action scenesProcessed) { NetworkObjectRefreshTool.AllScenesProcessed = scenesProcessed;