online fix
This commit is contained in:
@@ -22,7 +22,15 @@ namespace MegaKoop.Game.Networking
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
NetworkIdRegistry.Unregister(networkId);
|
||||
if (networkId != 0)
|
||||
{
|
||||
if (NetworkIdAllocator.IsEnemyId(networkId))
|
||||
{
|
||||
NetworkIdAllocator.ReleaseEnemyId(networkId);
|
||||
}
|
||||
NetworkIdRegistry.Unregister(networkId);
|
||||
networkId = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void Register()
|
||||
@@ -32,6 +40,11 @@ namespace MegaKoop.Game.Networking
|
||||
return;
|
||||
}
|
||||
|
||||
if (NetworkIdAllocator.IsEnemyId(networkId))
|
||||
{
|
||||
NetworkIdAllocator.SyncEnemyCursor(networkId);
|
||||
}
|
||||
|
||||
if (!NetworkIdRegistry.TryRegister(this))
|
||||
{
|
||||
Debug.LogError($"[NetworkIdentity] Failed to register {name} with ID {networkId}. " +
|
||||
@@ -68,11 +81,21 @@ namespace MegaKoop.Game.Networking
|
||||
// Unregister old ID if it was registered
|
||||
if (networkId != 0)
|
||||
{
|
||||
if (NetworkIdAllocator.IsEnemyId(networkId))
|
||||
{
|
||||
NetworkIdAllocator.ReleaseEnemyId(networkId);
|
||||
}
|
||||
|
||||
NetworkIdRegistry.Unregister(networkId);
|
||||
}
|
||||
|
||||
networkId = id;
|
||||
|
||||
|
||||
if (NetworkIdAllocator.IsEnemyId(networkId))
|
||||
{
|
||||
NetworkIdAllocator.SyncEnemyCursor(networkId);
|
||||
}
|
||||
|
||||
// Register with new ID
|
||||
if (!NetworkIdRegistry.TryRegister(this))
|
||||
{
|
||||
@@ -85,5 +108,25 @@ namespace MegaKoop.Game.Networking
|
||||
/// Gets the current network ID without triggering registration.
|
||||
/// </summary>
|
||||
public int GetNetworkId() => networkId;
|
||||
|
||||
/// <summary>
|
||||
/// Clears the current network ID and unregisters without emitting duplicate warnings.
|
||||
/// </summary>
|
||||
public void ClearNetworkId()
|
||||
{
|
||||
if (networkId == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int id = networkId;
|
||||
NetworkIdRegistry.Unregister(id);
|
||||
if (NetworkIdAllocator.IsEnemyId(id))
|
||||
{
|
||||
NetworkIdAllocator.ReleaseEnemyId(id);
|
||||
}
|
||||
|
||||
networkId = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user