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). ## [2.0.0-pre.4] - 2024-08-21 ### Added - Added `NetworkVariable.CheckDirtyState` that is to be used in tandem with collections in order to detect whether the collection or an item within the collection has changed. (#3004) ### Fixed - Fixed issue where nested `NetworkTransform` components were not getting updated. (#3016) - Fixed issue by adding null checks in `NetworkVariableBase.CanClientRead` and `NetworkVariableBase.CanClientWrite` methods to ensure safe access to `NetworkBehaviour`. (#3012) - Fixed issue where `FixedStringSerializer<T>` was using `NetworkVariableSerialization<byte>.AreEqual` to determine if two bytes were equal causes an exception to be thrown due to no byte serializer having been defined. (#3009) - Fixed Issue where a state with dual triggers, inbound and outbound, could cause a false layer to layer state transition message to be sent to non-authority `NetworkAnimator` instances and cause a warning message to be logged. (#3008) - Fixed issue using collections within `NetworkVariable` where the collection would not detect changes to items or nested items. (#3004) - Fixed issue where `List`, `Dictionary`, and `HashSet` collections would not uniquely duplicate nested collections. (#3004) - Fixed issue where `NotAuthorityTarget` would include the service observer in the list of targets to send the RPC to as opposed to excluding the service observer as it should. (#3000) - Fixed issue where `ProxyRpcTargetGroup` could attempt to send a message if there were no targets to send to. (#3000) ### Changed - Changed `NetworkAnimator` to automatically switch to owner authoritative mode when using a distributed authority network topology. (#3021) - Changed permissions exception thrown in `NetworkList` to exiting early with a logged error that is now a unified permissions message within `NetworkVariableBase`. (#3004) - Changed permissions exception thrown in `NetworkVariable.Value` to exiting early with a logged error that is now a unified permissions message within `NetworkVariableBase`. (#3004)
106 lines
3.6 KiB
C#
106 lines
3.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Unity.Collections;
|
|
|
|
namespace Unity.Netcode
|
|
{
|
|
internal class ProxyRpcTargetGroup : BaseRpcTarget, IDisposable, IGroupRpcTarget
|
|
{
|
|
public BaseRpcTarget Target => this;
|
|
|
|
private ServerRpcTarget m_ServerRpcTarget;
|
|
private LocalSendRpcTarget m_LocalSendRpcTarget;
|
|
|
|
private bool m_Disposed;
|
|
public NativeList<ulong> TargetClientIds;
|
|
internal HashSet<ulong> Ids = new HashSet<ulong>();
|
|
|
|
internal override void Send(NetworkBehaviour behaviour, ref RpcMessage message, NetworkDelivery delivery, RpcParams rpcParams)
|
|
{
|
|
// If there are no targets then don't attempt to send anything.
|
|
if (TargetClientIds.Length == 0 && Ids.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
var proxyMessage = new ProxyMessage { Delivery = delivery, TargetClientIds = TargetClientIds.AsArray(), WrappedMessage = message };
|
|
#if DEVELOPMENT_BUILD || UNITY_EDITOR || UNITY_MP_TOOLS_NET_STATS_MONITOR_ENABLED_IN_RELEASE
|
|
var size =
|
|
#endif
|
|
behaviour.NetworkManager.MessageManager.SendMessage(ref proxyMessage, delivery, NetworkManager.ServerClientId);
|
|
|
|
#if DEVELOPMENT_BUILD || UNITY_EDITOR || UNITY_MP_TOOLS_NET_STATS_MONITOR_ENABLED_IN_RELEASE
|
|
if (NetworkBehaviour.__rpc_name_table[behaviour.GetType()].TryGetValue(message.Metadata.NetworkRpcMethodId, out var rpcMethodName))
|
|
{
|
|
foreach (var clientId in TargetClientIds)
|
|
{
|
|
behaviour.NetworkManager.NetworkMetrics.TrackRpcSent(
|
|
clientId,
|
|
behaviour.NetworkObject,
|
|
rpcMethodName,
|
|
behaviour.__getTypeName(),
|
|
size);
|
|
}
|
|
}
|
|
#endif
|
|
if (Ids.Contains(NetworkManager.ServerClientId))
|
|
{
|
|
m_ServerRpcTarget.Send(behaviour, ref message, delivery, rpcParams);
|
|
}
|
|
if (Ids.Contains(m_NetworkManager.LocalClientId))
|
|
{
|
|
m_LocalSendRpcTarget.Send(behaviour, ref message, delivery, rpcParams);
|
|
}
|
|
}
|
|
|
|
internal ProxyRpcTargetGroup(NetworkManager manager) : base(manager)
|
|
{
|
|
TargetClientIds = new NativeList<ulong>(Allocator.Persistent);
|
|
m_ServerRpcTarget = new ServerRpcTarget(manager);
|
|
m_LocalSendRpcTarget = new LocalSendRpcTarget(manager);
|
|
}
|
|
|
|
public override void Dispose()
|
|
{
|
|
CheckLockBeforeDispose();
|
|
if (!m_Disposed)
|
|
{
|
|
TargetClientIds.Dispose();
|
|
m_Disposed = true;
|
|
m_ServerRpcTarget.Dispose();
|
|
m_LocalSendRpcTarget.Dispose();
|
|
}
|
|
}
|
|
|
|
public void Add(ulong clientId)
|
|
{
|
|
if (!Ids.Contains(clientId))
|
|
{
|
|
Ids.Add(clientId);
|
|
if (clientId != NetworkManager.ServerClientId && clientId != m_NetworkManager.LocalClientId)
|
|
{
|
|
TargetClientIds.Add(clientId);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Remove(ulong clientId)
|
|
{
|
|
Ids.Remove(clientId);
|
|
for (var i = 0; i < TargetClientIds.Length; ++i)
|
|
{
|
|
if (TargetClientIds[i] == clientId)
|
|
{
|
|
TargetClientIds.RemoveAt(i);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
Ids.Clear();
|
|
TargetClientIds.Clear();
|
|
}
|
|
}
|
|
}
|