online fix
This commit is contained in:
@@ -69,7 +69,6 @@ namespace MegaKoop.Game.Enemy
|
|||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
EnsureIdentity();
|
|
||||||
spawnPosition = transform.position;
|
spawnPosition = transform.position;
|
||||||
baseMoveSpeed = moveSpeed;
|
baseMoveSpeed = moveSpeed;
|
||||||
|
|
||||||
@@ -134,14 +133,22 @@ namespace MegaKoop.Game.Enemy
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (identity.NetworkId == 0)
|
if (identity.NetworkId != 0)
|
||||||
{
|
{
|
||||||
identity.SetNetworkId(nextEnemyNetworkId++);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ShouldAssignLocalNetworkId())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
identity.SetNetworkId(nextEnemyNetworkId++);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnEnable()
|
private void OnEnable()
|
||||||
{
|
{
|
||||||
|
EnsureIdentity();
|
||||||
networkManager = SteamCoopNetworkManager.Instance;
|
networkManager = SteamCoopNetworkManager.Instance;
|
||||||
pooledInstance ??= GetComponent<PooledInstance>();
|
pooledInstance ??= GetComponent<PooledInstance>();
|
||||||
pendingDespawn = false;
|
pendingDespawn = false;
|
||||||
@@ -232,6 +239,22 @@ namespace MegaKoop.Game.Enemy
|
|||||||
return networkManager.IsHost;
|
return networkManager.IsHost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool ShouldAssignLocalNetworkId()
|
||||||
|
{
|
||||||
|
var manager = SteamCoopNetworkManager.Instance;
|
||||||
|
if (manager == null)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!manager.IsConnected)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return manager.IsHost;
|
||||||
|
}
|
||||||
|
|
||||||
private void SyncNavMeshAgentState(bool simulate)
|
private void SyncNavMeshAgentState(bool simulate)
|
||||||
{
|
{
|
||||||
if (navMeshAgent == null)
|
if (navMeshAgent == null)
|
||||||
|
|||||||
@@ -14,14 +14,11 @@ namespace MegaKoop.Game.Networking
|
|||||||
{
|
{
|
||||||
// Note: Auto-increment removed in favor of deterministic ID generation
|
// Note: Auto-increment removed in favor of deterministic ID generation
|
||||||
// IDs should be assigned via SetNetworkId() before or during Awake
|
// IDs should be assigned via SetNetworkId() before or during Awake
|
||||||
if (assignOnAwake && networkId == 0)
|
if (networkId != 0)
|
||||||
{
|
{
|
||||||
Debug.LogWarning($"[NetworkIdentity] {name} has assignOnAwake=true but no ID assigned. " +
|
|
||||||
"Use DeterministicIdGenerator or manually call SetNetworkId().");
|
|
||||||
}
|
|
||||||
|
|
||||||
Register();
|
Register();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void OnDestroy()
|
private void OnDestroy()
|
||||||
{
|
{
|
||||||
@@ -32,7 +29,6 @@ namespace MegaKoop.Game.Networking
|
|||||||
{
|
{
|
||||||
if (networkId == 0)
|
if (networkId == 0)
|
||||||
{
|
{
|
||||||
Debug.LogWarning($"[NetworkIdentity] {name} has no network id and won't be tracked.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user