com.unity.netcode.gameobjects@1.8.0
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.8.0] - 2023-12-12 ### Added - Added a new RPC attribute, which is simply `Rpc`. (#2762) - This is a generic attribute that can perform the functions of both Server and Client RPCs, as well as enabling client-to-client RPCs. Includes several default targets: `Server`, `NotServer`, `Owner`, `NotOwner`, `Me`, `NotMe`, `ClientsAndHost`, and `Everyone`. Runtime overrides are available for any of these targets, as well as for sending to a specific ID or groups of IDs. - This attribute also includes the ability to defer RPCs that are sent to the local process to the start of the next frame instead of executing them immediately, treating them as if they had gone across the network. The default behavior is to execute immediately. - This attribute effectively replaces `ServerRpc` and `ClientRpc`. `ServerRpc` and `ClientRpc` remain in their existing forms for backward compatibility, but `Rpc` will be the recommended and most supported option. - Added `NetworkManager.OnConnectionEvent` as a unified connection event callback to notify clients and servers of all client connections and disconnections within the session (#2762) - Added `NetworkManager.ServerIsHost` and `NetworkBehaviour.ServerIsHost` to allow a client to tell if it is connected to a host or to a dedicated server (#2762) - Added `SceneEventProgress.SceneManagementNotEnabled` return status to be returned when a `NetworkSceneManager` method is invoked and scene management is not enabled. (#2735) - Added `SceneEventProgress.ServerOnlyAction` return status to be returned when a `NetworkSceneManager` method is invoked by a client. (#2735) - Added `NetworkObject.InstantiateAndSpawn` and `NetworkSpawnManager.InstantiateAndSpawn` methods to simplify prefab spawning by assuring that the prefab is valid and applies any override prior to instantiating the `GameObject` and spawning the `NetworkObject` instance. (#2710) ### Fixed - Fixed issue where a client disconnected by a server-host would not receive a local notification. (#2789) - Fixed issue where a server-host could shutdown during a relay connection but periodically the transport disconnect message sent to any connected clients could be dropped. (#2789) - Fixed issue where a host could disconnect its local client but remain running as a server. (#2789) - Fixed issue where `OnClientDisconnectedCallback` was not being invoked under certain conditions. (#2789) - Fixed issue where `OnClientDisconnectedCallback` was always returning 0 as the client identifier. (#2789) - Fixed issue where if a host or server shutdown while a client owned NetworkObjects (other than the player) it would throw an exception. (#2789) - Fixed issue where setting values on a `NetworkVariable` or `NetworkList` within `OnNetworkDespawn` during a shutdown sequence would throw an exception. (#2789) - Fixed issue where a teleport state could potentially be overridden by a previous unreliable delta state. (#2777) - Fixed issue where `NetworkTransform` was using the `NetworkManager.ServerTime.Tick` as opposed to `NetworkManager.NetworkTickSystem.ServerTime.Tick` during the authoritative side's tick update where it performed a delta state check. (#2777) - Fixed issue where a parented in-scene placed NetworkObject would be destroyed upon a client or server exiting a network session but not unloading the original scene in which the NetworkObject was placed. (#2737) - Fixed issue where during client synchronization and scene loading, when client synchronization or the scene loading mode are set to `LoadSceneMode.Single`, a `CreateObjectMessage` could be received, processed, and the resultant spawned `NetworkObject` could be instantiated in the client's currently active scene that could, towards the end of the client synchronization or loading process, be unloaded and cause the newly created `NetworkObject` to be destroyed (and throw and exception). (#2735) - Fixed issue where a `NetworkTransform` instance with interpolation enabled would result in wide visual motion gaps (stuttering) under above normal latency conditions and a 1-5% or higher packet are drop rate. (#2713) - Fixed issue where you could not have multiple source network prefab overrides targeting the same network prefab as their override. (#2710) ### Changed - Changed the server or host shutdown so it will now perform a "soft shutdown" when `NetworkManager.Shutdown` is invoked. This will send a disconnect notification to all connected clients and the server-host will wait for all connected clients to disconnect or timeout after a 5 second period before completing the shutdown process. (#2789) - Changed `OnClientDisconnectedCallback` will now return the assigned client identifier on the local client side if the client was approved and assigned one prior to being disconnected. (#2789) - Changed `NetworkTransform.SetState` (and related methods) now are cumulative during a fractional tick period and sent on the next pending tick. (#2777) - `NetworkManager.ConnectedClientsIds` is now accessible on the client side and will contain the list of all clients in the session, including the host client if the server is operating in host mode (#2762) - Changed `NetworkSceneManager` to return a `SceneEventProgress` status and not throw exceptions for methods invoked when scene management is disabled and when a client attempts to access a `NetworkSceneManager` method by a client. (#2735) - Changed `NetworkTransform` authoritative instance tick registration so a single `NetworkTransform` specific tick event update will update all authoritative instances to improve perofmance. (#2713) - Changed `NetworkPrefabs.OverrideToNetworkPrefab` dictionary is no longer used/populated due to it ending up being related to a regression bug and not allowing more than one override to be assigned to a network prefab asset. (#2710) - Changed in-scene placed `NetworkObject`s now store their source network prefab asset's `GlobalObjectIdHash` internally that is used, when scene management is disabled, by clients to spawn the correct prefab even if the `NetworkPrefab` entry has an override. This does not impact dynamically spawning the same prefab which will yield the override on both host and client. (#2710) - Changed in-scene placed `NetworkObject`s no longer require a `NetworkPrefab` entry with `GlobalObjectIdHash` override in order for clients to properly synchronize. (#2710) - Changed in-scene placed `NetworkObject`s now set their `IsSceneObject` value when generating their `GlobalObjectIdHash` value. (#2710) - Changed the default `NetworkConfig.SpawnTimeout` value from 1.0s to 10.0s. (#2710)
This commit is contained in:
@@ -6,6 +6,14 @@ using UnityEngine;
|
||||
|
||||
namespace Unity.Netcode
|
||||
{
|
||||
public class RpcException : Exception
|
||||
{
|
||||
public RpcException(string message) : base(message)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The base class to override to write network code. Inherits MonoBehaviour
|
||||
/// </summary>
|
||||
@@ -27,16 +35,22 @@ namespace Unity.Netcode
|
||||
// RuntimeAccessModifiersILPP will make this `protected`
|
||||
internal enum __RpcExecStage
|
||||
{
|
||||
// Technically will overlap with None and Server
|
||||
// but it doesn't matter since we don't use None and Server
|
||||
Send = 0,
|
||||
Execute = 1,
|
||||
|
||||
// Backward compatibility, not used...
|
||||
None = 0,
|
||||
Server = 1,
|
||||
Client = 2
|
||||
Client = 2,
|
||||
}
|
||||
// NetworkBehaviourILPP will override this in derived classes to return the name of the concrete type
|
||||
internal virtual string __getTypeName() => nameof(NetworkBehaviour);
|
||||
|
||||
[NonSerialized]
|
||||
// RuntimeAccessModifiersILPP will make this `protected`
|
||||
internal __RpcExecStage __rpc_exec_stage = __RpcExecStage.None;
|
||||
internal __RpcExecStage __rpc_exec_stage = __RpcExecStage.Send;
|
||||
#pragma warning restore IDE1006 // restore naming rule violation check
|
||||
|
||||
private const int k_RpcMessageDefaultSize = 1024; // 1k
|
||||
@@ -284,6 +298,99 @@ namespace Unity.Netcode
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#pragma warning disable IDE1006 // disable naming rule violation check
|
||||
// RuntimeAccessModifiersILPP will make this `protected`
|
||||
internal FastBufferWriter __beginSendRpc(uint rpcMethodId, RpcParams rpcParams, RpcAttribute.RpcAttributeParams attributeParams, SendTo defaultTarget, RpcDelivery rpcDelivery)
|
||||
#pragma warning restore IDE1006 // restore naming rule violation check
|
||||
{
|
||||
if (attributeParams.RequireOwnership && !IsOwner)
|
||||
{
|
||||
throw new RpcException("This RPC can only be sent by its owner.");
|
||||
}
|
||||
return new FastBufferWriter(k_RpcMessageDefaultSize, Allocator.Temp, k_RpcMessageMaximumSize);
|
||||
}
|
||||
|
||||
#pragma warning disable IDE1006 // disable naming rule violation check
|
||||
// RuntimeAccessModifiersILPP will make this `protected`
|
||||
internal void __endSendRpc(ref FastBufferWriter bufferWriter, uint rpcMethodId, RpcParams rpcParams, RpcAttribute.RpcAttributeParams attributeParams, SendTo defaultTarget, RpcDelivery rpcDelivery)
|
||||
#pragma warning restore IDE1006 // restore naming rule violation check
|
||||
{
|
||||
var rpcMessage = new RpcMessage
|
||||
{
|
||||
Metadata = new RpcMetadata
|
||||
{
|
||||
NetworkObjectId = NetworkObjectId,
|
||||
NetworkBehaviourId = NetworkBehaviourId,
|
||||
NetworkRpcMethodId = rpcMethodId,
|
||||
},
|
||||
SenderClientId = NetworkManager.LocalClientId,
|
||||
WriteBuffer = bufferWriter
|
||||
};
|
||||
|
||||
NetworkDelivery networkDelivery;
|
||||
switch (rpcDelivery)
|
||||
{
|
||||
default:
|
||||
case RpcDelivery.Reliable:
|
||||
networkDelivery = NetworkDelivery.ReliableFragmentedSequenced;
|
||||
break;
|
||||
case RpcDelivery.Unreliable:
|
||||
if (bufferWriter.Length > NetworkManager.MessageManager.NonFragmentedMessageMaxSize)
|
||||
{
|
||||
throw new OverflowException("RPC parameters are too large for unreliable delivery.");
|
||||
}
|
||||
networkDelivery = NetworkDelivery.Unreliable;
|
||||
break;
|
||||
}
|
||||
|
||||
if (rpcParams.Send.Target == null)
|
||||
{
|
||||
switch (defaultTarget)
|
||||
{
|
||||
case SendTo.Everyone:
|
||||
rpcParams.Send.Target = RpcTarget.Everyone;
|
||||
break;
|
||||
case SendTo.Owner:
|
||||
rpcParams.Send.Target = RpcTarget.Owner;
|
||||
break;
|
||||
case SendTo.Server:
|
||||
rpcParams.Send.Target = RpcTarget.Server;
|
||||
break;
|
||||
case SendTo.NotServer:
|
||||
rpcParams.Send.Target = RpcTarget.NotServer;
|
||||
break;
|
||||
case SendTo.NotMe:
|
||||
rpcParams.Send.Target = RpcTarget.NotMe;
|
||||
break;
|
||||
case SendTo.NotOwner:
|
||||
rpcParams.Send.Target = RpcTarget.NotOwner;
|
||||
break;
|
||||
case SendTo.Me:
|
||||
rpcParams.Send.Target = RpcTarget.Me;
|
||||
break;
|
||||
case SendTo.ClientsAndHost:
|
||||
rpcParams.Send.Target = RpcTarget.ClientsAndHost;
|
||||
break;
|
||||
case SendTo.SpecifiedInParams:
|
||||
throw new RpcException("This method requires a runtime-specified send target.");
|
||||
}
|
||||
}
|
||||
else if (defaultTarget != SendTo.SpecifiedInParams && !attributeParams.AllowTargetOverride)
|
||||
{
|
||||
throw new RpcException("Target override is not allowed for this method.");
|
||||
}
|
||||
|
||||
if (rpcParams.Send.LocalDeferMode == LocalDeferMode.Default)
|
||||
{
|
||||
rpcParams.Send.LocalDeferMode = attributeParams.DeferLocal ? LocalDeferMode.Defer : LocalDeferMode.SendImmediate;
|
||||
}
|
||||
|
||||
rpcParams.Send.Target.Send(this, ref rpcMessage, networkDelivery, rpcParams);
|
||||
|
||||
bufferWriter.Dispose();
|
||||
}
|
||||
|
||||
#pragma warning disable IDE1006 // disable naming rule violation check
|
||||
// RuntimeAccessModifiersILPP will make this `protected`
|
||||
internal static NativeList<T> __createNativeList<T>() where T : unmanaged
|
||||
@@ -315,6 +422,24 @@ namespace Unity.Netcode
|
||||
}
|
||||
}
|
||||
|
||||
// This erroneously tries to simplify these method references but the docs do not pick it up correctly
|
||||
// because they try to resolve it on the field rather than the class of the same name.
|
||||
#pragma warning disable IDE0001
|
||||
/// <summary>
|
||||
/// Provides access to the various <see cref="SendTo"/> targets at runtime, as well as
|
||||
/// runtime-bound targets like <see cref="Unity.Netcode.RpcTarget.Single"/>,
|
||||
/// <see cref="Unity.Netcode.RpcTarget.Group(NativeArray{ulong})"/>,
|
||||
/// <see cref="Unity.Netcode.RpcTarget.Group(NativeList{ulong})"/>,
|
||||
/// <see cref="Unity.Netcode.RpcTarget.Group(ulong[])"/>,
|
||||
/// <see cref="Unity.Netcode.RpcTarget.Group{T}(T)"/>, <see cref="Unity.Netcode.RpcTarget.Not(ulong)"/>,
|
||||
/// <see cref="Unity.Netcode.RpcTarget.Not(NativeArray{ulong})"/>,
|
||||
/// <see cref="Unity.Netcode.RpcTarget.Not(NativeList{ulong})"/>,
|
||||
/// <see cref="Unity.Netcode.RpcTarget.Not(ulong[])"/>, and
|
||||
/// <see cref="Unity.Netcode.RpcTarget.Not{T}(T)"/>
|
||||
/// </summary>
|
||||
#pragma warning restore IDE0001
|
||||
public RpcTarget RpcTarget => NetworkManager.RpcTarget;
|
||||
|
||||
/// <summary>
|
||||
/// If a NetworkObject is assigned, it will return whether or not this NetworkObject
|
||||
/// is the local player object. If no NetworkObject is assigned it will always return false.
|
||||
@@ -331,6 +456,11 @@ namespace Unity.Netcode
|
||||
/// </summary>
|
||||
public bool IsServer { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets if the server (local or remote) is a host - i.e., also a client
|
||||
/// </summary>
|
||||
public bool ServerIsHost { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets if we are executing as client
|
||||
/// </summary>
|
||||
@@ -472,12 +602,13 @@ namespace Unity.Netcode
|
||||
IsHost = NetworkManager.IsListening && NetworkManager.IsHost;
|
||||
IsClient = NetworkManager.IsListening && NetworkManager.IsClient;
|
||||
IsServer = NetworkManager.IsListening && NetworkManager.IsServer;
|
||||
ServerIsHost = NetworkManager.IsListening && NetworkManager.ServerIsHost;
|
||||
}
|
||||
}
|
||||
else // Shouldn't happen, but if so then set the properties to their default value;
|
||||
{
|
||||
OwnerClientId = NetworkObjectId = default;
|
||||
IsOwnedByServer = IsOwner = IsHost = IsClient = IsServer = default;
|
||||
IsOwnedByServer = IsOwner = IsHost = IsClient = IsServer = ServerIsHost = default;
|
||||
NetworkBehaviourId = default;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user