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:
Unity Technologies
2021-10-22 00:00:00 +00:00
parent 22d877d1b2
commit f5664b4cc1
14 changed files with 408 additions and 228 deletions

View File

@@ -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);
}
}