com.unity.netcode.gameobjects@1.0.0-pre.3
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.3] - 2021-10-22 ### Added - ResetTrigger function to NetworkAnimator (#1327) ### Fixed - Overflow exception when syncing Animator state. (#1327) - Added `try`/`catch` around RPC calls, preventing exception from causing further RPC calls to fail (#1329) - Fixed an issue where ServerClientId and LocalClientId could have the same value, causing potential confusion, and also fixed an issue with the UNet where the server could be identified with two different values, one of which might be the same as LocalClientId, and the other of which would not.(#1368) - IL2CPP would not properly compile (#1359)
This commit is contained in:
@@ -149,14 +149,9 @@ namespace Unity.Netcode
|
||||
|
||||
public void Send(ulong clientId, NetworkDelivery delivery, FastBufferWriter batchData)
|
||||
{
|
||||
var sendBuffer = batchData.ToTempByteArray();
|
||||
|
||||
var length = batchData.Length;
|
||||
//TODO: Transport needs to have a way to send it data without copying and allocating here.
|
||||
var bytes = batchData.ToArray();
|
||||
var sendBuffer = new ArraySegment<byte>(bytes, 0, length);
|
||||
|
||||
m_NetworkManager.NetworkConfig.NetworkTransport.Send(clientId, sendBuffer, delivery);
|
||||
|
||||
m_NetworkManager.NetworkConfig.NetworkTransport.Send(m_NetworkManager.ClientIdToTransportId(clientId), sendBuffer, delivery);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,10 +223,12 @@ namespace Unity.Netcode
|
||||
|
||||
public NetworkSceneManager SceneManager { get; private set; }
|
||||
|
||||
public readonly ulong ServerClientId = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the networkId of the server
|
||||
/// </summary>
|
||||
public ulong ServerClientId => NetworkConfig.NetworkTransport?.ServerClientId ??
|
||||
private ulong m_ServerTransportId => NetworkConfig.NetworkTransport?.ServerClientId ??
|
||||
throw new NullReferenceException(
|
||||
$"The transport in the active {nameof(NetworkConfig)} is null");
|
||||
|
||||
@@ -248,6 +245,10 @@ namespace Unity.Netcode
|
||||
|
||||
private Dictionary<ulong, NetworkClient> m_ConnectedClients = new Dictionary<ulong, NetworkClient>();
|
||||
|
||||
private ulong m_NextClientId = 1;
|
||||
private Dictionary<ulong, ulong> m_ClientIdToTransportIdMap = new Dictionary<ulong, ulong>();
|
||||
private Dictionary<ulong, ulong> m_TransportIdToClientIdMap = new Dictionary<ulong, ulong>();
|
||||
|
||||
private List<NetworkClient> m_ConnectedClientsList = new List<NetworkClient>();
|
||||
|
||||
private List<ulong> m_ConnectedClientIds = new List<ulong>();
|
||||
@@ -985,6 +986,12 @@ namespace Unity.Netcode
|
||||
}
|
||||
}
|
||||
|
||||
private void DisconnectRemoteClient(ulong clientId)
|
||||
{
|
||||
var transportId = ClientIdToTransportId(clientId);
|
||||
NetworkConfig.NetworkTransport.DisconnectRemoteClient(transportId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Globally shuts down the library.
|
||||
/// Disconnects clients if connected and stops server if running.
|
||||
@@ -1019,7 +1026,7 @@ namespace Unity.Netcode
|
||||
continue;
|
||||
}
|
||||
|
||||
NetworkConfig.NetworkTransport.DisconnectRemoteClient(pair.Key);
|
||||
DisconnectRemoteClient(pair.Key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1033,7 +1040,7 @@ namespace Unity.Netcode
|
||||
continue;
|
||||
}
|
||||
|
||||
NetworkConfig.NetworkTransport.DisconnectRemoteClient(pair.Key);
|
||||
DisconnectRemoteClient(pair.Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1103,6 +1110,9 @@ namespace Unity.Netcode
|
||||
NetworkConfig?.NetworkTransport?.Shutdown();
|
||||
}
|
||||
|
||||
m_ClientIdToTransportIdMap.Clear();
|
||||
m_TransportIdToClientIdMap.Clear();
|
||||
|
||||
IsListening = false;
|
||||
}
|
||||
|
||||
@@ -1229,14 +1239,30 @@ namespace Unity.Netcode
|
||||
}
|
||||
}
|
||||
|
||||
private ulong TransportIdToClientId(ulong transportId)
|
||||
{
|
||||
return transportId == m_ServerTransportId ? ServerClientId : m_TransportIdToClientIdMap[transportId];
|
||||
}
|
||||
|
||||
private ulong ClientIdToTransportId(ulong clientId)
|
||||
{
|
||||
return clientId == ServerClientId ? m_ServerTransportId : m_ClientIdToTransportIdMap[clientId];
|
||||
}
|
||||
|
||||
private void HandleRawTransportPoll(NetworkEvent networkEvent, ulong clientId, ArraySegment<byte> payload, float receiveTime)
|
||||
{
|
||||
var transportId = clientId;
|
||||
switch (networkEvent)
|
||||
{
|
||||
case NetworkEvent.Connect:
|
||||
#if DEVELOPMENT_BUILD || UNITY_EDITOR
|
||||
s_TransportConnect.Begin();
|
||||
#endif
|
||||
|
||||
clientId = m_NextClientId++;
|
||||
m_ClientIdToTransportIdMap[clientId] = transportId;
|
||||
m_TransportIdToClientIdMap[transportId] = clientId;
|
||||
|
||||
MessagingSystem.ClientConnected(clientId);
|
||||
if (IsServer)
|
||||
{
|
||||
@@ -1275,6 +1301,8 @@ namespace Unity.Netcode
|
||||
NetworkLog.LogInfo($"Incoming Data From {clientId}: {payload.Count} bytes");
|
||||
}
|
||||
|
||||
clientId = TransportIdToClientId(clientId);
|
||||
|
||||
HandleIncomingData(clientId, payload, receiveTime);
|
||||
break;
|
||||
}
|
||||
@@ -1282,6 +1310,10 @@ namespace Unity.Netcode
|
||||
#if DEVELOPMENT_BUILD || UNITY_EDITOR
|
||||
s_TransportDisconnect.Begin();
|
||||
#endif
|
||||
clientId = TransportIdToClientId(clientId);
|
||||
|
||||
m_TransportIdToClientIdMap.Remove(transportId);
|
||||
m_ClientIdToTransportIdMap.Remove(clientId);
|
||||
|
||||
if (NetworkLog.CurrentLogLevel <= LogLevel.Developer)
|
||||
{
|
||||
@@ -1405,8 +1437,7 @@ namespace Unity.Netcode
|
||||
}
|
||||
|
||||
OnClientDisconnectFromServer(clientId);
|
||||
|
||||
NetworkConfig.NetworkTransport.DisconnectRemoteClient(clientId);
|
||||
DisconnectRemoteClient(clientId);
|
||||
}
|
||||
|
||||
private void OnClientDisconnectFromServer(ulong clientId)
|
||||
@@ -1580,7 +1611,7 @@ namespace Unity.Netcode
|
||||
else
|
||||
{
|
||||
PendingClients.Remove(ownerClientId);
|
||||
NetworkConfig.NetworkTransport.DisconnectRemoteClient(ownerClientId);
|
||||
DisconnectRemoteClient(ownerClientId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace Unity.Netcode
|
||||
((UnnamedMessageDelegate)handler).Invoke(clientId, reader);
|
||||
}
|
||||
}
|
||||
m_NetworkManager.NetworkMetrics.TrackUnnamedMessageReceived(clientId, reader.Length);
|
||||
m_NetworkManager.NetworkMetrics.TrackUnnamedMessageReceived(clientId, reader.Length + FastBufferWriter.GetWriteSize<MessageHeader>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -53,7 +53,6 @@ namespace Unity.Netcode
|
||||
SendUnnamedMessage(m_NetworkManager.ConnectedClientsIds, messageBuffer, networkDelivery);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Sends unnamed message to a list of clients
|
||||
/// </summary>
|
||||
@@ -118,7 +117,7 @@ namespace Unity.Netcode
|
||||
|
||||
internal void InvokeNamedMessage(ulong hash, ulong sender, FastBufferReader reader)
|
||||
{
|
||||
var bytesCount = reader.Length;
|
||||
var bytesCount = reader.Length + FastBufferWriter.GetWriteSize<MessageHeader>();
|
||||
|
||||
if (m_NetworkManager == null)
|
||||
{
|
||||
|
||||
@@ -226,7 +226,7 @@ namespace Unity.Netcode
|
||||
|
||||
for (var hookIdx = 0; hookIdx < m_Hooks.Count; ++hookIdx)
|
||||
{
|
||||
m_Hooks[hookIdx].OnBeforeReceiveMessage(senderId, type, reader.Length);
|
||||
m_Hooks[hookIdx].OnBeforeReceiveMessage(senderId, type, reader.Length + FastBufferWriter.GetWriteSize<MessageHeader>());
|
||||
}
|
||||
var handler = m_MessageHandlers[header.MessageType];
|
||||
using (reader)
|
||||
@@ -247,7 +247,7 @@ namespace Unity.Netcode
|
||||
}
|
||||
for (var hookIdx = 0; hookIdx < m_Hooks.Count; ++hookIdx)
|
||||
{
|
||||
m_Hooks[hookIdx].OnAfterReceiveMessage(senderId, type, reader.Length);
|
||||
m_Hooks[hookIdx].OnAfterReceiveMessage(senderId, type, reader.Length + FastBufferWriter.GetWriteSize<MessageHeader>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,8 +310,13 @@ namespace Unity.Netcode
|
||||
where TMessageType : INetworkMessage
|
||||
where TClientIdListType : IReadOnlyList<ulong>
|
||||
{
|
||||
if (clientIds.Count == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
var maxSize = delivery == NetworkDelivery.ReliableFragmentedSequenced ? FRAGMENTED_MESSAGE_MAX_SIZE : NON_FRAGMENTED_MESSAGE_MAX_SIZE;
|
||||
var tmpSerializer = new FastBufferWriter(NON_FRAGMENTED_MESSAGE_MAX_SIZE - sizeof(MessageHeader), Allocator.Temp, maxSize - sizeof(MessageHeader));
|
||||
var tmpSerializer = new FastBufferWriter(NON_FRAGMENTED_MESSAGE_MAX_SIZE - FastBufferWriter.GetWriteSize<MessageHeader>(), Allocator.Temp, maxSize - FastBufferWriter.GetWriteSize<MessageHeader>());
|
||||
using (tmpSerializer)
|
||||
{
|
||||
message.Serialize(tmpSerializer);
|
||||
@@ -342,7 +347,7 @@ namespace Unity.Netcode
|
||||
ref var lastQueueItem = ref sendQueueItem.GetUnsafeList()->ElementAt(sendQueueItem.Length - 1);
|
||||
if (lastQueueItem.NetworkDelivery != delivery ||
|
||||
lastQueueItem.Writer.MaxCapacity - lastQueueItem.Writer.Position
|
||||
< tmpSerializer.Length + sizeof(MessageHeader))
|
||||
< tmpSerializer.Length + FastBufferWriter.GetWriteSize<MessageHeader>())
|
||||
{
|
||||
sendQueueItem.Add(new SendQueueItem(delivery, NON_FRAGMENTED_MESSAGE_MAX_SIZE, Allocator.TempJob,
|
||||
maxSize));
|
||||
@@ -351,7 +356,7 @@ namespace Unity.Netcode
|
||||
}
|
||||
|
||||
ref var writeQueueItem = ref sendQueueItem.GetUnsafeList()->ElementAt(sendQueueItem.Length - 1);
|
||||
writeQueueItem.Writer.TryBeginWrite(sizeof(MessageHeader) + tmpSerializer.Length);
|
||||
writeQueueItem.Writer.TryBeginWrite(tmpSerializer.Length + FastBufferWriter.GetWriteSize<MessageHeader>());
|
||||
var header = new MessageHeader
|
||||
{
|
||||
MessageSize = (ushort)tmpSerializer.Length,
|
||||
@@ -363,11 +368,11 @@ namespace Unity.Netcode
|
||||
writeQueueItem.BatchHeader.BatchSize++;
|
||||
for (var hookIdx = 0; hookIdx < m_Hooks.Count; ++hookIdx)
|
||||
{
|
||||
m_Hooks[hookIdx].OnAfterSendMessage(clientId, typeof(TMessageType), delivery, tmpSerializer.Length + sizeof(MessageHeader));
|
||||
m_Hooks[hookIdx].OnAfterSendMessage(clientId, typeof(TMessageType), delivery, tmpSerializer.Length + FastBufferWriter.GetWriteSize<MessageHeader>());
|
||||
}
|
||||
}
|
||||
|
||||
return tmpSerializer.Length;
|
||||
return tmpSerializer.Length + FastBufferWriter.GetWriteSize<MessageHeader>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,17 +8,22 @@ using UnityEngine.SceneManagement;
|
||||
namespace Unity.Netcode
|
||||
{
|
||||
/// <summary>
|
||||
/// Used for local notifications of various scene events.
|
||||
/// The <see cref="NetworkSceneManager.OnSceneEvent"/> of delegate type <see cref="NetworkSceneManager.SceneEventDelegate"/> uses this class to provide
|
||||
/// scene event status/state.
|
||||
/// Used for local notifications of various scene events. The <see cref="NetworkSceneManager.OnSceneEvent"/> of
|
||||
/// delegate type <see cref="NetworkSceneManager.SceneEventDelegate"/> uses this class to provide
|
||||
/// scene event status.<br/>
|
||||
/// <em>Note: This is only when <see cref="NetworkConfig.EnableSceneManagement"/> is enabled.</em><br/>
|
||||
/// See also: <br/>
|
||||
/// <seealso cref="SceneEventType"/>
|
||||
/// </summary>
|
||||
public class SceneEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="UnityEngine.AsyncOperation"/> returned by <see cref="SceneManager"/>
|
||||
/// The <see cref="UnityEngine.AsyncOperation"/> returned by <see cref="SceneManager"/><BR/>
|
||||
/// This is set for the following <see cref="Netcode.SceneEventType"/>s:
|
||||
/// <see cref="SceneEventType.Load"/>
|
||||
/// <see cref="SceneEventType.Unload"/>
|
||||
/// <list type="bullet">
|
||||
/// <item><term><see cref="SceneEventType.Load"/></term></item>
|
||||
/// <item><term><see cref="SceneEventType.Unload"/></term></item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public AsyncOperation AsyncOperation;
|
||||
|
||||
@@ -28,71 +33,92 @@ namespace Unity.Netcode
|
||||
public SceneEventType SceneEventType;
|
||||
|
||||
/// <summary>
|
||||
/// If applicable, this reflects the type of scene loading or unloading that is occurring.
|
||||
/// If applicable, this reflects the type of scene loading or unloading that is occurring.<BR/>
|
||||
/// This is set for the following <see cref="Netcode.SceneEventType"/>s:
|
||||
/// <see cref="SceneEventType.Load"/>
|
||||
/// <see cref="SceneEventType.Unload"/>
|
||||
/// <see cref="SceneEventType.LoadComplete"/>
|
||||
/// <see cref="SceneEventType.UnloadComplete"/>
|
||||
/// <see cref="SceneEventType.LoadEventCompleted"/>
|
||||
/// <see cref="SceneEventType.UnloadEventCompleted"/>
|
||||
/// <list type="bullet">
|
||||
/// <item><term><see cref="SceneEventType.Load"/></term></item>
|
||||
/// <item><term><see cref="SceneEventType.Unload"/></term></item>
|
||||
/// <item><term><see cref="SceneEventType.LoadComplete"/></term></item>
|
||||
/// <item><term><see cref="SceneEventType.UnloadComplete"/></term></item>
|
||||
/// <item><term><see cref="SceneEventType.LoadEventCompleted"/></term></item>
|
||||
/// <item><term><see cref="SceneEventType.UnloadEventCompleted"/></term></item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public LoadSceneMode LoadSceneMode;
|
||||
|
||||
/// <summary>
|
||||
/// This will be set to the scene name that the event pertains to.
|
||||
/// This will be set to the scene name that the event pertains to.<BR/>
|
||||
/// This is set for the following <see cref="Netcode.SceneEventType"/>s:
|
||||
/// <see cref="SceneEventType.Load"/>
|
||||
/// <see cref="SceneEventType.Unload"/>
|
||||
/// <see cref="SceneEventType.LoadComplete"/>
|
||||
/// <see cref="SceneEventType.UnloadComplete"/>
|
||||
/// <see cref="SceneEventType.LoadEventCompleted"/>
|
||||
/// <see cref="SceneEventType.UnloadEventCompleted"/>
|
||||
/// <list type="bullet">
|
||||
/// <item><term><see cref="SceneEventType.Load"/></term></item>
|
||||
/// <item><term><see cref="SceneEventType.Unload"/></term></item>
|
||||
/// <item><term><see cref="SceneEventType.LoadComplete"/></term></item>
|
||||
/// <item><term><see cref="SceneEventType.UnloadComplete"/></term></item>
|
||||
/// <item><term><see cref="SceneEventType.LoadEventCompleted"/></term></item>
|
||||
/// <item><term><see cref="SceneEventType.UnloadEventCompleted"/></term></item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public string SceneName;
|
||||
|
||||
/// <summary>
|
||||
/// When a scene is loaded, the Scene structure is returned.
|
||||
/// When a scene is loaded, the Scene structure is returned.<BR/>
|
||||
/// This is set for the following <see cref="Netcode.SceneEventType"/>s:
|
||||
/// <see cref="SceneEventType.LoadComplete"/>
|
||||
/// <list type="bullet">
|
||||
/// <item><term><see cref="SceneEventType.LoadComplete"/></term></item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Scene Scene;
|
||||
|
||||
/// <summary>
|
||||
/// Events that always set the <see cref="ClientId"/> to the local client identifier,
|
||||
/// are initiated (and processed locally) by the server-host, and sent to all clients
|
||||
/// to be processed:
|
||||
/// <see cref="SceneEventType.Load"/>
|
||||
/// <see cref="SceneEventType.Unload"/>
|
||||
/// <see cref="SceneEventType.Synchronize"/>
|
||||
/// <see cref="SceneEventType.ReSynchronize"/>
|
||||
///
|
||||
/// Events that always set the <see cref="ClientId"/> to the local client identifier,
|
||||
/// The client identifier can vary depending upon the following conditions: <br/>
|
||||
/// <list type="number">
|
||||
/// <item><term><see cref="Netcode.SceneEventType"/>s that always set the <see cref="ClientId"/>
|
||||
/// to the local client identifier, are initiated (and processed locally) by the
|
||||
/// server-host, and sent to all clients to be processed.<br/>
|
||||
/// <list type="bullet">
|
||||
/// <item><term><see cref="SceneEventType.Load"/></term></item>
|
||||
/// <item><term><see cref="SceneEventType.Unload"/></term></item>
|
||||
/// <item><term><see cref="SceneEventType.Synchronize"/></term></item>
|
||||
/// <item><term><see cref="SceneEventType.ReSynchronize"/></term></item>
|
||||
/// </list>
|
||||
/// </term></item>
|
||||
/// <item><term>Events that always set the <see cref="ClientId"/> to the local client identifier,
|
||||
/// are initiated (and processed locally) by a client or server-host, and if initiated
|
||||
/// by a client will always be sent to and processed on the server-host:
|
||||
/// <see cref="SceneEventType.LoadComplete"/>
|
||||
/// <see cref="SceneEventType.UnloadComplete"/>
|
||||
/// <see cref="SceneEventType.SynchronizeComplete"/>
|
||||
///
|
||||
/// <list type="bullet">
|
||||
/// <item><term><see cref="SceneEventType.LoadComplete"/></term></item>
|
||||
/// <item><term><see cref="SceneEventType.UnloadComplete"/></term></item>
|
||||
/// <item><term><see cref="SceneEventType.SynchronizeComplete"/></term></item>
|
||||
/// </list>
|
||||
/// </term></item>
|
||||
/// <item><term>
|
||||
/// Events that always set the <see cref="ClientId"/> to the ServerId:
|
||||
/// <see cref="SceneEventType.LoadEventCompleted"/>
|
||||
/// <see cref="SceneEventType.UnloadEventCompleted"/>
|
||||
/// <list type="bullet">
|
||||
/// <item><term><see cref="SceneEventType.LoadEventCompleted"/></term></item>
|
||||
/// <item><term><see cref="SceneEventType.UnloadEventCompleted"/></term></item>
|
||||
/// </list>
|
||||
/// </term></item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public ulong ClientId;
|
||||
|
||||
/// <summary>
|
||||
/// List of clients that completed a loading or unloading event
|
||||
/// List of clients that completed a loading or unloading event.<br/>
|
||||
/// This is set for the following <see cref="Netcode.SceneEventType"/>s:
|
||||
/// <see cref="SceneEventType.LoadEventCompleted"/>
|
||||
/// <see cref="SceneEventType.UnloadEventCompleted"/>
|
||||
/// <list type="bullet">
|
||||
/// <item><term><see cref="SceneEventType.LoadEventCompleted"/></term></item>
|
||||
/// <item><term><see cref="SceneEventType.UnloadEventCompleted"/></term></item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public List<ulong> ClientsThatCompleted;
|
||||
|
||||
/// <summary>
|
||||
/// List of clients that timed out during a loading or unloading event
|
||||
/// List of clients that timed out during a loading or unloading event.<br/>
|
||||
/// This is set for the following <see cref="Netcode.SceneEventType"/>s:
|
||||
/// <see cref="SceneEventType.LoadEventCompleted"/>
|
||||
/// <see cref="SceneEventType.UnloadEventCompleted"/>
|
||||
/// <list type="bullet">
|
||||
/// <item><term><see cref="SceneEventType.LoadEventCompleted"/></term></item>
|
||||
/// <item><term><see cref="SceneEventType.UnloadEventCompleted"/></term></item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public List<ulong> ClientsThatTimedOut;
|
||||
}
|
||||
@@ -122,34 +148,37 @@ namespace Unity.Netcode
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// The delegate callback definition for scene event notifications
|
||||
/// For more details review over <see cref="SceneEvent"/> and <see cref="SceneEventData"/>
|
||||
/// The delegate callback definition for scene event notifications.<br/>
|
||||
/// See also: <br/>
|
||||
/// <seealso cref="SceneEvent"/><br/>
|
||||
/// <seealso cref="SceneEventData"/>
|
||||
/// </summary>
|
||||
/// <param name="sceneEvent"></param>
|
||||
public delegate void SceneEventDelegate(SceneEvent sceneEvent);
|
||||
|
||||
/// <summary>
|
||||
/// Event that will notify the local client or server of all scene events that take place
|
||||
/// For more details review over <see cref="SceneEvent"/>, <see cref="SceneEventData"/>, and <see cref="SceneEventType"/>
|
||||
/// Subscribe to this event to receive all <see cref="SceneEventType"/> notifications
|
||||
///
|
||||
/// Alternate Single Event Type Notification Registration Options
|
||||
/// Subscribe to this event to receive all <see cref="SceneEventType"/> notifications.<br/>
|
||||
/// For more details review over <see cref="SceneEvent"/> and <see cref="SceneEventType"/>.<br/>
|
||||
/// <b>Alternate Single Event Type Notification Registration Options</b><br/>
|
||||
/// To receive only a specific event type notification or a limited set of notifications you can alternately subscribe to
|
||||
/// each notification type individually via the following events:
|
||||
/// -- <see cref="OnLoad"/> Invoked only when a <see cref="SceneEventType.Load"/> event is being processed
|
||||
/// -- <see cref="OnUnload"/> Invoked only when an <see cref="SceneEventType.Unload"/> event is being processed
|
||||
/// -- <see cref="OnSynchronize"/> Invoked only when a <see cref="SceneEventType.Synchronize"/> event is being processed
|
||||
/// -- <see cref="OnLoadEventCompleted"/> Invoked only when a <see cref="SceneEventType.LoadEventCompleted"/> event is being processed
|
||||
/// -- <see cref="OnUnloadEventCompleted"/> Invoked only when an <see cref="SceneEventType.UnloadEventCompleted"/> event is being processed
|
||||
/// -- <see cref="OnLoadComplete"/> Invoked only when a <see cref="SceneEventType.LoadComplete"/> event is being processed
|
||||
/// -- <see cref="OnUnloadComplete"/> Invoked only when an <see cref="SceneEventType.UnloadComplete"/> event is being processed
|
||||
/// -- <see cref="OnSynchronizeComplete"/> Invoked only when a <see cref="SceneEventType.SynchronizeComplete"/> event is being processed
|
||||
/// each notification type individually via the following events:<br/>
|
||||
/// <list type="bullet">
|
||||
/// <item><term><see cref="OnLoad"/> Invoked only when a <see cref="SceneEventType.Load"/> event is being processed</term></item>
|
||||
/// <item><term><see cref="OnUnload"/> Invoked only when an <see cref="SceneEventType.Unload"/> event is being processed</term></item>
|
||||
/// <item><term><see cref="OnSynchronize"/> Invoked only when a <see cref="SceneEventType.Synchronize"/> event is being processed</term></item>
|
||||
/// <item><term><see cref="OnLoadEventCompleted"/> Invoked only when a <see cref="SceneEventType.LoadEventCompleted"/> event is being processed</term></item>
|
||||
/// <item><term><see cref="OnUnloadEventCompleted"/> Invoked only when an <see cref="SceneEventType.UnloadEventCompleted"/> event is being processed</term></item>
|
||||
/// <item><term><see cref="OnLoadComplete"/> Invoked only when a <see cref="SceneEventType.LoadComplete"/> event is being processed</term></item>
|
||||
/// <item><term><see cref="OnUnloadComplete"/> Invoked only when an <see cref="SceneEventType.UnloadComplete"/> event is being processed</term></item>
|
||||
/// <item><term><see cref="OnSynchronizeComplete"/> Invoked only when a <see cref="SceneEventType.SynchronizeComplete"/> event is being processed</term></item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public event SceneEventDelegate OnSceneEvent;
|
||||
|
||||
/// <summary>
|
||||
/// Delegate declaration for the OnLoad event
|
||||
/// View <see cref="SceneEventType.Load"/> for more information
|
||||
/// Delegate declaration for the OnLoad event.<br/>
|
||||
/// See also: <br/>
|
||||
/// <seealso cref="SceneEventType.Load"/>for more information
|
||||
/// </summary>
|
||||
/// <param name="clientId">the client that is processing this event (the server will receive all of these events for every client and itself)</param>
|
||||
/// <param name="sceneName">name of the scene being processed</param>
|
||||
@@ -158,8 +187,9 @@ namespace Unity.Netcode
|
||||
public delegate void OnLoadDelegateHandler(ulong clientId, string sceneName, LoadSceneMode loadSceneMode, AsyncOperation asyncOperation);
|
||||
|
||||
/// <summary>
|
||||
/// Delegate declaration for the OnUnload event
|
||||
/// View <see cref="SceneEventType.Unload"/> for more information
|
||||
/// Delegate declaration for the OnUnload event.<br/>
|
||||
/// See also: <br/>
|
||||
/// <seealso cref="SceneEventType.Unload"/> for more information
|
||||
/// </summary>
|
||||
/// <param name="clientId">the client that is processing this event (the server will receive all of these events for every client and itself)</param>
|
||||
/// <param name="sceneName">name of the scene being processed</param>
|
||||
@@ -167,16 +197,18 @@ namespace Unity.Netcode
|
||||
public delegate void OnUnloadDelegateHandler(ulong clientId, string sceneName, AsyncOperation asyncOperation);
|
||||
|
||||
/// <summary>
|
||||
/// Delegate declaration for the OnSynchronize event
|
||||
/// View <see cref="SceneEventType.Synchronize"/> for more information
|
||||
/// Delegate declaration for the OnSynchronize event.<br/>
|
||||
/// See also: <br/>
|
||||
/// <seealso cref="SceneEventType.Synchronize"/> for more information
|
||||
/// </summary>
|
||||
/// <param name="clientId">the client that is processing this event (the server will receive all of these events for every client and itself)</param>
|
||||
public delegate void OnSynchronizeDelegateHandler(ulong clientId);
|
||||
|
||||
/// <summary>
|
||||
/// Delegate declaration for the OnLoadEventCompleted and OnUnloadEventCompleted events
|
||||
/// View <see cref="SceneEventType.LoadEventCompleted"/> for more information
|
||||
/// View <see cref="SceneEventType.UnloadEventCompleted"/> for more information
|
||||
/// Delegate declaration for the OnLoadEventCompleted and OnUnloadEventCompleted events.<br/>
|
||||
/// See also:<br/>
|
||||
/// <seealso cref="SceneEventType.LoadEventCompleted"/><br/>
|
||||
/// <seealso cref="SceneEventType.UnloadEventCompleted"/>
|
||||
/// </summary>
|
||||
/// <param name="sceneName">scene pertaining to this event</param>
|
||||
/// <param name="loadSceneMode"><see cref="LoadSceneMode"/> of the associated event completed</param>
|
||||
@@ -185,8 +217,9 @@ namespace Unity.Netcode
|
||||
public delegate void OnEventCompletedDelegateHandler(string sceneName, LoadSceneMode loadSceneMode, List<ulong> clientsCompleted, List<ulong> clientsTimedOut);
|
||||
|
||||
/// <summary>
|
||||
/// Delegate declaration for the OnLoadComplete event
|
||||
/// View <see cref="SceneEventType.LoadComplete"/> for more information
|
||||
/// Delegate declaration for the OnLoadComplete event.<br/>
|
||||
/// See also:<br/>
|
||||
/// <seealso cref="SceneEventType.LoadComplete"/> for more information
|
||||
/// </summary>
|
||||
/// <param name="clientId">the client that is processing this event (the server will receive all of these events for every client and itself)</param>
|
||||
/// <param name="sceneName">the scene name pertaining to this event</param>
|
||||
@@ -194,38 +227,40 @@ namespace Unity.Netcode
|
||||
public delegate void OnLoadCompleteDelegateHandler(ulong clientId, string sceneName, LoadSceneMode loadSceneMode);
|
||||
|
||||
/// <summary>
|
||||
/// Delegate declaration for the OnUnloadComplete event
|
||||
/// View <see cref="SceneEventType.UnloadComplete"/> for more information
|
||||
/// Delegate declaration for the OnUnloadComplete event.<br/>
|
||||
/// See also:<br/>
|
||||
/// <seealso cref="SceneEventType.UnloadComplete"/> for more information
|
||||
/// </summary>
|
||||
/// <param name="clientId">the client that is processing this event (the server will receive all of these events for every client and itself)</param>
|
||||
/// <param name="sceneName">the scene name pertaining to this event</param>
|
||||
public delegate void OnUnloadCompleteDelegateHandler(ulong clientId, string sceneName);
|
||||
|
||||
/// <summary>
|
||||
/// Delegate declaration for the OnSynchronizeComplete event
|
||||
/// View <see cref="SceneEventType.SynchronizeComplete"/> for more information
|
||||
/// Delegate declaration for the OnSynchronizeComplete event.<br/>
|
||||
/// See also:<br/>
|
||||
/// <seealso cref="SceneEventType.SynchronizeComplete"/> for more information
|
||||
/// </summary>
|
||||
/// <param name="clientId">the client that completed this event</param>
|
||||
public delegate void OnSynchronizeCompleteDelegateHandler(ulong clientId);
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a <see cref="SceneEventType.Load"/> event is started by the server
|
||||
/// The server and client(s) will receive this notification
|
||||
/// Invoked when a <see cref="SceneEventType.Load"/> event is started by the server.<br/>
|
||||
/// <em>Note: The server and connected client(s) will always receive this notification.</em>
|
||||
/// </summary>
|
||||
public event OnLoadDelegateHandler OnLoad;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a <see cref="SceneEventType.Unload"/> event is started by the server
|
||||
/// The server and client(s) will receive this notification
|
||||
/// Invoked when a <see cref="SceneEventType.Unload"/> event is started by the server.<br/>
|
||||
/// <em>Note: The server and connected client(s) will always receive this notification.</em>
|
||||
/// </summary>
|
||||
public event OnUnloadDelegateHandler OnUnload;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a <see cref="SceneEventType.Synchronize"/> event is started by the server
|
||||
/// after a client is approved for connection in order to synchronize the client with the currently loaded
|
||||
/// scenes and NetworkObjects. This event signifies the beginning of the synchronization event.
|
||||
/// The server and client will receive this notification
|
||||
/// Note: this event is generated on a per newly connected and approved client basis
|
||||
/// scenes and NetworkObjects. This event signifies the beginning of the synchronization event.<br/>
|
||||
/// <em>Note: The server and connected client(s) will always receive this notification.
|
||||
/// This event is generated on a per newly connected and approved client basis.</em>
|
||||
/// </summary>
|
||||
public event OnSynchronizeDelegateHandler OnSynchronize;
|
||||
|
||||
@@ -233,8 +268,8 @@ namespace Unity.Netcode
|
||||
/// Invoked when a <see cref="SceneEventType.LoadEventCompleted"/> event is generated by the server.
|
||||
/// This event signifies the end of an existing <see cref="SceneEventType.Load"/> event as it pertains
|
||||
/// to all clients connected when the event was started. This event signifies that all clients (and server) have
|
||||
/// finished the <see cref="SceneEventType.Load"/> event.
|
||||
/// Note: this is useful to know when all clients have loaded the same scene (single or additive mode)
|
||||
/// finished the <see cref="SceneEventType.Load"/> event.<br/>
|
||||
/// <em>Note: this is useful to know when all clients have loaded the same scene (single or additive mode)</em>
|
||||
/// </summary>
|
||||
public event OnEventCompletedDelegateHandler OnLoadEventCompleted;
|
||||
|
||||
@@ -242,32 +277,31 @@ namespace Unity.Netcode
|
||||
/// Invoked when a <see cref="SceneEventType.UnloadEventCompleted"/> event is generated by the server.
|
||||
/// This event signifies the end of an existing <see cref="SceneEventType.Unload"/> event as it pertains
|
||||
/// to all clients connected when the event was started. This event signifies that all clients (and server) have
|
||||
/// finished the <see cref="SceneEventType.Unload"/> event.
|
||||
/// Note: this is useful to know when all clients have unloaded a specific scene. The <see cref="LoadSceneMode"/> will
|
||||
/// always be <see cref="LoadSceneMode.Additive"/> for this event
|
||||
/// finished the <see cref="SceneEventType.Unload"/> event.<br/>
|
||||
/// <em>Note: this is useful to know when all clients have unloaded a specific scene. The <see cref="LoadSceneMode"/> will
|
||||
/// always be <see cref="LoadSceneMode.Additive"/> for this event.</em>
|
||||
/// </summary>
|
||||
public event OnEventCompletedDelegateHandler OnUnloadEventCompleted;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a <see cref="SceneEventType.LoadComplete"/> event is generated by a client or server.
|
||||
/// The server receives this message from all clients (including itself).
|
||||
/// Each client receives their own notification sent to the server.
|
||||
/// Invoked when a <see cref="SceneEventType.LoadComplete"/> event is generated by a client or server.<br/>
|
||||
/// <em>Note: The server receives this message from all clients (including itself).
|
||||
/// Each client receives their own notification sent to the server.</em>
|
||||
/// </summary>
|
||||
public event OnLoadCompleteDelegateHandler OnLoadComplete;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a <see cref="SceneEventType.UnloadComplete"/> event is generated by a client or server.
|
||||
/// The server receives this message from all clients (including itself).
|
||||
/// Each client receives their own notification sent to the server.
|
||||
/// Invoked when a <see cref="SceneEventType.UnloadComplete"/> event is generated by a client or server.<br/>
|
||||
/// <em>Note: The server receives this message from all clients (including itself).
|
||||
/// Each client receives their own notification sent to the server.</em>
|
||||
/// </summary>
|
||||
public event OnUnloadCompleteDelegateHandler OnUnloadComplete;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a <see cref="SceneEventType.SynchronizeComplete"/> event is generated by a client.
|
||||
/// The server receives this message from the client, but will never generate this event for itself.
|
||||
/// Each client receives their own notification sent to the server.
|
||||
/// Note: This is useful to know that a client has completed the entire connection sequence, loaded all scenes, and
|
||||
/// synchronized all NetworkObjects.
|
||||
/// Invoked when a <see cref="SceneEventType.SynchronizeComplete"/> event is generated by a client. <br/>
|
||||
/// <em> Note: The server receives this message from the client, but will never generate this event for itself.
|
||||
/// Each client receives their own notification sent to the server. This is useful to know that a client has
|
||||
/// completed the entire connection sequence, loaded all scenes, and synchronized all NetworkObjects.</em>
|
||||
/// </summary>
|
||||
public event OnSynchronizeCompleteDelegateHandler OnSynchronizeComplete;
|
||||
|
||||
@@ -284,9 +318,9 @@ namespace Unity.Netcode
|
||||
|
||||
/// <summary>
|
||||
/// Delegate handler defined by <see cref="VerifySceneBeforeLoadingDelegateHandler"/> that is invoked before the
|
||||
/// server or client loads a scene during an active netcode game session.
|
||||
/// Client Side: In order for clients to be notified of this condition you must assign the <see cref="VerifySceneBeforeLoading"/> delegate handler.
|
||||
/// Server Side: <see cref="LoadScene(string, LoadSceneMode)"/> will return <see cref="SceneEventProgressStatus.SceneFailedVerification"/>.
|
||||
/// server or client loads a scene during an active netcode game session.<br/>
|
||||
/// <b>Client Side:</b> In order for clients to be notified of this condition you must assign the <see cref="VerifySceneBeforeLoading"/> delegate handler.<br/>
|
||||
/// <b>Server Side:</b> <see cref="LoadScene(string, LoadSceneMode)"/> will return <see cref="SceneEventProgressStatus"/>.
|
||||
/// </summary>
|
||||
public VerifySceneBeforeLoadingDelegateHandler VerifySceneBeforeLoading;
|
||||
|
||||
@@ -353,11 +387,10 @@ namespace Unity.Netcode
|
||||
internal Scene DontDestroyOnLoadScene;
|
||||
|
||||
/// <summary>
|
||||
/// LoadSceneMode.Single: All currently loaded scenes on the client will be unloaded and
|
||||
/// <b>LoadSceneMode.Single:</b> All currently loaded scenes on the client will be unloaded and
|
||||
/// the server's currently active scene will be loaded in single mode on the client
|
||||
/// unless it was already loaded.
|
||||
///
|
||||
/// LoadSceneMode.Additive: All currently loaded scenes are left as they are and any newly loaded
|
||||
/// unless it was already loaded.<br/>
|
||||
/// <b>LoadSceneMode.Additive:</b> All currently loaded scenes are left as they are and any newly loaded
|
||||
/// scenes will be loaded additively. Users need to determine which scenes are valid to load via the
|
||||
/// <see cref="VerifySceneBeforeLoading"/> method.
|
||||
/// </summary>
|
||||
@@ -506,12 +539,11 @@ namespace Unity.Netcode
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This will change how clients are initially synchronized.
|
||||
/// LoadSceneMode.Single: All currently loaded scenes on the client will be unloaded and
|
||||
/// This will change how clients are initially synchronized.<br/>
|
||||
/// <b>LoadSceneMode.Single:</b> All currently loaded scenes on the client will be unloaded and
|
||||
/// the server's currently active scene will be loaded in single mode on the client
|
||||
/// unless it was already loaded.
|
||||
///
|
||||
/// LoadSceneMode.Additive: All currently loaded scenes are left as they are and any newly loaded
|
||||
/// unless it was already loaded. <br/>
|
||||
/// <b>LoadSceneMode.Additive:</b> All currently loaded scenes are left as they are and any newly loaded
|
||||
/// scenes will be loaded additively. Users need to determine which scenes are valid to load via the
|
||||
/// <see cref="VerifySceneBeforeLoading"/> method.
|
||||
/// </summary>
|
||||
@@ -858,7 +890,7 @@ namespace Unity.Netcode
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Server Side:
|
||||
/// <b>Server Side:</b>
|
||||
/// Unloads an additively loaded scene. If you want to unload a <see cref="LoadSceneMode.Single"/> mode loaded scene load another <see cref="LoadSceneMode.Single"/> scene.
|
||||
/// When applicable, the <see cref="AsyncOperation"/> is delivered within the <see cref="SceneEvent"/> via the <see cref="OnSceneEvent"/>
|
||||
/// </summary>
|
||||
@@ -918,7 +950,7 @@ namespace Unity.Netcode
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Client Side:
|
||||
/// <b>Client Side:</b>
|
||||
/// Handles <see cref="SceneEventType.Unload"/> scene events.
|
||||
/// </summary>
|
||||
private void OnClientUnloadScene(uint sceneEventId)
|
||||
@@ -1056,7 +1088,7 @@ namespace Unity.Netcode
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Server side:
|
||||
/// <b>Server side:</b>
|
||||
/// Loads the scene name in either additive or single loading mode.
|
||||
/// When applicable, the <see cref="AsyncOperation"/> is delivered within the <see cref="SceneEvent"/> via <see cref="OnSceneEvent"/>
|
||||
/// </summary>
|
||||
|
||||
@@ -8,84 +8,86 @@ using UnityEngine.SceneManagement;
|
||||
namespace Unity.Netcode
|
||||
{
|
||||
/// <summary>
|
||||
/// The different types of scene events communicated between a server and client.
|
||||
/// Used by <see cref="NetworkSceneManager"/> for <see cref="SceneEventMessage"/> messages
|
||||
/// Note: This is only when <see cref="NetworkConfig.EnableSceneManagement"/> is enabled
|
||||
/// See also: <see cref="SceneEvent"/>
|
||||
/// The different types of scene events communicated between a server and client. <br/>
|
||||
/// Used by <see cref="NetworkSceneManager"/> for <see cref="SceneEventMessage"/> messages.<br/>
|
||||
/// <em>Note: This is only when <see cref="NetworkConfig.EnableSceneManagement"/> is enabled.</em><br/>
|
||||
/// See also: <br/>
|
||||
/// <seealso cref="SceneEvent"/>
|
||||
/// </summary>
|
||||
public enum SceneEventType : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// Load a scene
|
||||
/// Invocation: Server Side
|
||||
/// Message Flow: Server to client
|
||||
/// Event Notification: Both server and client are notified a load scene event started
|
||||
/// Load a scene<br/>
|
||||
/// <b>Invocation:</b> Server Side<br/>
|
||||
/// <b>Message Flow:</b> Server to client<br/>
|
||||
/// <b>Event Notification:</b> Both server and client are notified a load scene event started
|
||||
/// </summary>
|
||||
Load,
|
||||
/// <summary>
|
||||
/// Unload a scene
|
||||
/// Invocation: Server Side
|
||||
/// Message Flow: Server to client
|
||||
/// Event Notification: Both server and client are notified an unload scene event started
|
||||
/// Unload a scene<br/>
|
||||
/// <b>Invocation:</b> Server Side<br/>
|
||||
/// <b>Message Flow:</b> Server to client<br/>
|
||||
/// <b>Event Notification:</b> Both server and client are notified an unload scene event started.
|
||||
/// </summary>
|
||||
Unload,
|
||||
/// <summary>
|
||||
/// Synchronize current game session state for approved clients
|
||||
/// Invocation: Server Side
|
||||
/// Message Flow: Server to client
|
||||
/// Event Notification: Server and Client receives a local notification (server receives the ClientId being synchronized)
|
||||
/// Synchronizes current game session state for newly approved clients<br/>
|
||||
/// <b>Invocation:</b> Server Side<br/>
|
||||
/// <b>Message Flow:</b> Server to client<br/>
|
||||
/// <b>Event Notification:</b> Server and Client receives a local notification (<em>server receives the ClientId being synchronized</em>).
|
||||
/// </summary>
|
||||
Synchronize,
|
||||
/// <summary>
|
||||
/// Game session re-synchronization of NetworkObjects that were destroyed during a <see cref="Synchronize"/> event
|
||||
/// Invocation: Server Side
|
||||
/// Message Flow: Server to client
|
||||
/// Event Notification: Both server and client receive a local notification
|
||||
/// Note: This will be removed once snapshot and buffered messages are finalized as it will no longer be needed at that point
|
||||
/// Game session re-synchronization of NetworkObjects that were destroyed during a <see cref="Synchronize"/> event<br/>
|
||||
/// <b>Invocation:</b> Server Side<br/>
|
||||
/// <b>Message Flow:</b> Server to client<br/>
|
||||
/// <b>Event Notification:</b> Both server and client receive a local notification<br/>
|
||||
/// <em>Note: This will be removed once snapshot and buffered messages are finalized as it will no longer be needed at that point.</em>
|
||||
/// </summary>
|
||||
ReSynchronize,
|
||||
/// <summary>
|
||||
/// All clients have finished loading a scene
|
||||
/// Invocation: Server Side
|
||||
/// Message Flow: Server to Client
|
||||
/// Event Notification: Both server and client receive a local notification containing the clients that finished
|
||||
/// as well as the clients that timed out (if any).
|
||||
/// All clients have finished loading a scene<br/>
|
||||
/// <b>Invocation:</b> Server Side<br/>
|
||||
/// <b>Message Flow:</b> Server to Client<br/>
|
||||
/// <b>Event Notification:</b> Both server and client receive a local notification containing the clients that finished
|
||||
/// as well as the clients that timed out(<em>if any</em>).
|
||||
/// </summary>
|
||||
LoadEventCompleted,
|
||||
/// <summary>
|
||||
/// All clients have unloaded a scene
|
||||
/// Invocation: Server Side
|
||||
/// Message Flow: Server to Client
|
||||
/// Event Notification: Both server and client receive a local notification containing the clients that finished
|
||||
/// as well as the clients that timed out (if any).
|
||||
/// All clients have unloaded a scene<br/>
|
||||
/// <b>Invocation:</b> Server Side<br/>
|
||||
/// <b>Message Flow:</b> Server to Client<br/>
|
||||
/// <b>Event Notification:</b> Both server and client receive a local notification containing the clients that finished
|
||||
/// as well as the clients that timed out(<em>if any</em>).
|
||||
/// </summary>
|
||||
UnloadEventCompleted,
|
||||
/// <summary>
|
||||
/// A client has finished loading a scene
|
||||
/// Invocation: Client Side
|
||||
/// Message Flow: Client to Server
|
||||
/// Event Notification: Both server and client receive a local notification
|
||||
/// A client has finished loading a scene<br/>
|
||||
/// <b>Invocation:</b> Client Side<br/>
|
||||
/// <b>Message Flow:</b> Client to Server<br/>
|
||||
/// <b>Event Notification:</b> Both server and client receive a local notification.
|
||||
/// </summary>
|
||||
LoadComplete,
|
||||
/// <summary>
|
||||
/// A client has finished unloading a scene
|
||||
/// Invocation: Client Side
|
||||
/// Message Flow: Client to Server
|
||||
/// Event Notification: Both server and client receive a local notification
|
||||
/// A client has finished unloading a scene<br/>
|
||||
/// <b>Invocation:</b> Client Side<br/>
|
||||
/// <b>Message Flow:</b> Client to Server<br/>
|
||||
/// <b>Event Notification:</b> Both server and client receive a local notification.
|
||||
/// </summary>
|
||||
UnloadComplete,
|
||||
/// <summary>
|
||||
/// A client has finished synchronizing from a <see cref="Synchronize"/> event
|
||||
/// Invocation: Client Side
|
||||
/// Message Flow: Client to Server
|
||||
/// Event Notification: Both server and client receive a local notification
|
||||
/// A client has finished synchronizing from a <see cref="Synchronize"/> event<br/>
|
||||
/// <b>Invocation:</b> Client Side<br/>
|
||||
/// <b>Message Flow:</b> Client to Server<br/>
|
||||
/// <b>Event Notification:</b> Both server and client receive a local notification.
|
||||
/// </summary>
|
||||
SynchronizeComplete,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used by <see cref="NetworkSceneManager"/> for <see cref="SceneEventMessage"/> messages
|
||||
/// Note: This is only when <see cref="NetworkConfig.EnableSceneManagement"/> is enabled
|
||||
/// <em>Note: This is only when <see cref="NetworkConfig.EnableSceneManagement"/> is enabled.</em><br/>
|
||||
/// See also: <seealso cref="SceneEvent"/>
|
||||
/// </summary>
|
||||
internal class SceneEventData : IDisposable
|
||||
{
|
||||
|
||||
@@ -9,10 +9,10 @@ namespace Unity.Netcode
|
||||
{
|
||||
/// <summary>
|
||||
/// Used by <see cref="NetworkSceneManager"/> to determine if a server invoked scene event has started.
|
||||
/// The returned status is stored in the <see cref="SceneEventProgress.Status"/> property.
|
||||
/// Note: This was formally known as SwitchSceneProgress which contained the <see cref="AsyncOperation"/>.
|
||||
/// The returned status is stored in the <see cref="SceneEventProgress.Status"/> property.<br/>
|
||||
/// <em>Note: This was formally known as SwitchSceneProgress which contained the <see cref="AsyncOperation"/>.
|
||||
/// All <see cref="AsyncOperation"/>s are now delivered by the <see cref="NetworkSceneManager.OnSceneEvent"/> event handler
|
||||
/// via the <see cref="SceneEvent"/> parameter.
|
||||
/// via the <see cref="SceneEvent"/> parameter.</em>
|
||||
/// </summary>
|
||||
public enum SceneEventProgressStatus
|
||||
{
|
||||
@@ -21,31 +21,30 @@ namespace Unity.Netcode
|
||||
/// </summary>
|
||||
None,
|
||||
/// <summary>
|
||||
/// The scene event was successfully started
|
||||
/// The scene event was successfully started.
|
||||
/// </summary>
|
||||
Started,
|
||||
/// <summary>
|
||||
/// Returned if you try to unload a scene that was not yet loaded
|
||||
/// Returned if you try to unload a scene that was not yet loaded.
|
||||
/// </summary>
|
||||
SceneNotLoaded,
|
||||
/// <summary>
|
||||
/// Returned if you try to start a new scene event before a previous one is finished
|
||||
/// Returned if you try to start a new scene event before a previous one is finished.
|
||||
/// </summary>
|
||||
SceneEventInProgress,
|
||||
/// <summary>
|
||||
/// Returned if the scene name used with <see cref="NetworkSceneManager.LoadScene(string, LoadSceneMode)"/>
|
||||
/// or <see cref="NetworkSceneManager.UnloadScene(Scene)"/>is invalid
|
||||
/// or <see cref="NetworkSceneManager.UnloadScene(Scene)"/>is invalid.
|
||||
/// </summary>
|
||||
InvalidSceneName,
|
||||
/// <summary>
|
||||
/// Server side: Returned if the <see cref="NetworkSceneManager.VerifySceneBeforeLoading"/> delegate handler returns false
|
||||
/// (i.e. scene is considered not valid/safe to load)
|
||||
/// (<em>i.e. scene is considered not valid/safe to load</em>).
|
||||
/// </summary>
|
||||
SceneFailedVerification,
|
||||
/// <summary>
|
||||
/// This is used for internal error notifications.
|
||||
/// If you receive this event then it is most likely due to a bug.
|
||||
/// If you receive this event repeatedly, then please open a GitHub issue with steps to replicate
|
||||
/// This is used for internal error notifications.<br/>
|
||||
/// If you receive this event then it is most likely due to a bug (<em>please open a GitHub issue with steps to replicate</em>).<br/>
|
||||
/// </summary>
|
||||
InternalNetcodeError,
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ namespace Unity.Netcode
|
||||
|
||||
internal readonly unsafe WriterHandle* Handle;
|
||||
|
||||
private static byte[] s_ByteArrayCache = new byte[65535];
|
||||
|
||||
/// <summary>
|
||||
/// The current write position
|
||||
/// </summary>
|
||||
@@ -78,6 +80,10 @@ namespace Unity.Netcode
|
||||
/// <param name="maxSize">Maximum size the buffer can grow to. If less than size, buffer cannot grow.</param>
|
||||
public unsafe FastBufferWriter(int size, Allocator allocator, int maxSize = -1)
|
||||
{
|
||||
// Allocating both the Handle struct and the buffer in a single allocation - sizeof(WriterHandle) + size
|
||||
// The buffer for the initial allocation is the next block of memory after the handle itself.
|
||||
// If the buffer grows, a new buffer will be allocated and the handle pointer pointed at the new location...
|
||||
// The original buffer won't be deallocated until the writer is destroyed since it's part of the handle allocation.
|
||||
Handle = (WriterHandle*)UnsafeUtility.Malloc(sizeof(WriterHandle) + size, UnsafeUtility.AlignOf<WriterHandle>(), allocator);
|
||||
#if DEVELOPMENT_BUILD || UNITY_EDITOR
|
||||
UnsafeUtility.MemSet(Handle, 0, sizeof(WriterHandle) + size);
|
||||
@@ -349,6 +355,29 @@ namespace Unity.Netcode
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uses a static cached array to create an array segment with no allocations.
|
||||
/// This array can only be used until the next time ToTempByteArray() is called on ANY FastBufferWriter,
|
||||
/// as the cached buffer is shared by all of them and will be overwritten.
|
||||
/// As such, this should be used with care.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal unsafe ArraySegment<byte> ToTempByteArray()
|
||||
{
|
||||
var length = Length;
|
||||
if (length > s_ByteArrayCache.Length)
|
||||
{
|
||||
return new ArraySegment<byte>(ToArray(), 0, length);
|
||||
}
|
||||
|
||||
fixed (byte* b = s_ByteArrayCache)
|
||||
{
|
||||
UnsafeUtility.MemCpy(b, Handle->BufferPointer, length);
|
||||
}
|
||||
|
||||
return new ArraySegment<byte>(s_ByteArrayCache, 0, length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a direct pointer to the underlying buffer
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user