This commit is contained in:
2026-05-01 21:58:20 +07:00
parent 07fb48353c
commit 709ed4069d
26 changed files with 599 additions and 1008 deletions

View File

@@ -72,8 +72,13 @@ namespace Hallucinate.UI
await _runner.Shutdown();
}
Debug.Log("[BasicSpawner] Destroying existing runner component.");
Destroy(_runner);
// Check if it still exists (Unity pseudo-null check)
if (_runner != null)
{
// Only log if it's actually a valid object to destroy
// If it's already marked for destruction, Unity == null will be true soon
Destroy(_runner);
}
_runner = null;
await Task.Yield();
@@ -84,6 +89,8 @@ namespace Hallucinate.UI
}
}
if (this == null) return; // BasicSpawner itself might be destroyed
Debug.Log("[BasicSpawner] Creating new NetworkRunner component.");
_runner = gameObject.AddComponent<NetworkRunner>();
_runner.ProvideInput = true;
@@ -118,7 +125,12 @@ namespace Hallucinate.UI
public async Task<bool> StartHost(string sessionName, string displayName, string password = null)
{
if (_isStarting) return false;
// Wait for any existing startup process (like StartLobby) to finish
while (_isStarting)
{
await Task.Yield();
}
_isStarting = true;
try

View File

@@ -24,15 +24,22 @@ public class PlayerDataManager : NetworkBehaviour
Instance = this;
}
public override void Despawned(NetworkRunner runner, bool hasState)
{
if (Instance == this) Instance = null;
}
[Rpc(RpcSources.All, RpcTargets.StateAuthority)]
public void RPC_UpdatePlayerMetaData(PlayerRef playerRef, _PlayerMetaData metaData)
{
if (Object == null || !Object.IsValid) return;
Players.Set(playerRef, metaData);
}
[Rpc(RpcSources.All, RpcTargets.StateAuthority)]
public void RPC_SetReady(PlayerRef playerRef, bool ready)
{
if (Object == null || !Object.IsValid) return;
if (Players.TryGet(playerRef, out var data))
{
data.IsReady = ready;
@@ -48,6 +55,10 @@ public class PlayerDataManager : NetworkBehaviour
public bool TryGetPlayerMetaData(PlayerRef playerRef, out _PlayerMetaData metaData)
{
metaData = default;
// Kiểm tra xem object đã được Spawned chưa trước khi truy cập networked property
if (Object == null || !Object.IsValid) return false;
return Players.TryGet(playerRef, out metaData);
}
}