online game working

This commit is contained in:
2025-10-05 19:24:52 +02:00
parent 7cec95b8a0
commit dd89012919
3 changed files with 77 additions and 11 deletions

View File

@@ -49,5 +49,30 @@ namespace MegaKoop.Game.Networking
}
public static bool TryGet(int id, out NetworkIdentity identity) => registry.TryGetValue(id, out identity);
/// <summary>
/// Allows deterministic assignment so IDs match across clients.
/// </summary>
public void SetNetworkId(int id)
{
if (id == 0)
{
Debug.LogWarning("[NetworkIdentity] Cannot assign network id 0.");
return;
}
if (networkId == id)
{
return;
}
if (registry.TryGetValue(networkId, out NetworkIdentity existing) && existing == this)
{
registry.Remove(networkId);
}
networkId = id;
Register();
}
}
}