fix: Network Id Zero

This commit is contained in:
Syntriax 2024-07-19 21:39:50 +03:00
parent d011bf9a7a
commit 150deaa618
1 changed files with 18 additions and 2 deletions

View File

@ -124,10 +124,26 @@ public abstract class NetworkBase : BehaviourOverride, INetworkCommunicator
} }
private void OnNetworkEntityCollected(BehaviourCollector<INetworkEntity> sender, INetworkEntity behaviourCollected) private void OnNetworkEntityCollected(BehaviourCollector<INetworkEntity> sender, INetworkEntity behaviourCollected)
=> networkEntities.Add(behaviourCollected.NetworkId, behaviourCollected); {
if (behaviourCollected.NetworkId != 0)
networkEntities.Add(behaviourCollected.NetworkId, behaviourCollected);
behaviourCollected.OnNetworkIdChanged += OnNetworkIdChanged;
}
private void OnNetworkIdChanged(INetworkEntity sender, uint previousId)
{
if (networkEntities.TryGetValue(previousId, out INetworkEntity? networkEntity) && sender == networkEntity)
networkEntities.Remove(previousId);
networkEntities.Add(sender.NetworkId, sender);
}
private void OnNetworkEntityRemoved(BehaviourCollector<INetworkEntity> sender, INetworkEntity behaviourRemoved) private void OnNetworkEntityRemoved(BehaviourCollector<INetworkEntity> sender, INetworkEntity behaviourRemoved)
=> networkEntities.Remove(behaviourRemoved.NetworkId); {
networkEntities.Remove(behaviourRemoved.NetworkId);
behaviourRemoved.OnNetworkIdChanged -= OnNetworkIdChanged;
}
private void NetworkReceiveEvent(NetPeer peer, NetPacketReader reader, byte channel, DeliveryMethod deliveryMethod) private void NetworkReceiveEvent(NetPeer peer, NetPacketReader reader, byte channel, DeliveryMethod deliveryMethod)
{ {