diff --git a/.idea/.idea.HALLUCINATE/.idea/workspace.xml b/.idea/.idea.HALLUCINATE/.idea/workspace.xml
index 1fc4bacf..01194da0 100644
--- a/.idea/.idea.HALLUCINATE/.idea/workspace.xml
+++ b/.idea/.idea.HALLUCINATE/.idea/workspace.xml
@@ -6,22 +6,8 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
@@ -161,7 +147,7 @@
-
+
diff --git a/Assets/Scripts/Network/BasicSpawner.cs b/Assets/Scripts/Network/BasicSpawner.cs
index c65d53b6..fe0c658b 100644
--- a/Assets/Scripts/Network/BasicSpawner.cs
+++ b/Assets/Scripts/Network/BasicSpawner.cs
@@ -38,19 +38,23 @@ namespace Hallucinate.UI
private async Task EnsureRunnerExists()
{
- if (_runner != null)
+ if (_runner == null)
{
- // Nếu runner cũ vẫn đang chạy hoặc lỗi, dọn dẹp nó
- await _runner.Shutdown();
- if (_runner != null && _runner.gameObject != null)
- {
- Destroy(_runner);
- }
- _runner = null;
+ _runner = GetComponent();
+ }
+
+ if (_runner != null && _runner.IsRunning)
+ {
+ await _runner.Shutdown();
+ }
+
+ if (_runner == null)
+ {
+ _runner = gameObject.AddComponent();
}
- _runner = gameObject.AddComponent();
_runner.ProvideInput = true;
+ _runner.RemoveCallbacks(this);
_runner.AddCallbacks(this);
}
@@ -186,12 +190,17 @@ namespace Hallucinate.UI
{
runner.Despawn(networkObject);
_spawnedCharacters.Remove(player);
- if (runner.IsServer) runner.Shutdown();
+ // Chỉ Shutdown nếu người thoát chính là Server (Host)
+ if (runner.IsServer && player == runner.LocalPlayer)
+ {
+ runner.Shutdown();
+ }
}
}
public void OnShutdown(NetworkRunner runner, ShutdownReason shutdownReason)
{
+ Debug.LogWarning($"[Fusion] Shutdown occurred. Reason: {shutdownReason}");
OnShutdownEvent?.Invoke(shutdownReason.ToString());
}
diff --git a/Assets/Scripts/UI/LobbyController.cs b/Assets/Scripts/UI/LobbyController.cs
index 323d75b3..666c536a 100644
--- a/Assets/Scripts/UI/LobbyController.cs
+++ b/Assets/Scripts/UI/LobbyController.cs
@@ -89,14 +89,14 @@ namespace Hallucinate.UI
});
}
- // Đăng ký sự kiện từ Spawner (Sử dụng Instance)
+ // Đăng ký sự kiện từ Spawner
if (BasicSpawner.Instance != null)
{
RegisterSpawnerEvents();
+ _ = BasicSpawner.Instance.StartLobby();
}
else
{
- // Nếu chưa có, thử tìm sau một chút
Invoke(nameof(RegisterSpawnerEvents), 0.1f);
}
}
@@ -107,6 +107,7 @@ namespace Hallucinate.UI
BasicSpawner.Instance.OnSessionListUpdatedEvent += UpdateRoomList;
BasicSpawner.Instance.OnJoinFailedEvent += () => { if(_joinPassError != null) _joinPassError.style.display = DisplayStyle.Flex; };
BasicSpawner.Instance.OnJoinStartedEvent += () => { /* Show loading if needed */ };
+ _ = BasicSpawner.Instance.StartLobby();
}
public void SetRoomTemplate(VisualTreeAsset template) => _roomItemTemplate = template;
@@ -122,7 +123,7 @@ namespace Hallucinate.UI
if (_joinContainer != null) _joinContainer.style.display = DisplayStyle.Flex;
if (_createContainer != null) _createContainer.style.display = DisplayStyle.None;
if (_loungeContainer != null) _loungeContainer.style.display = DisplayStyle.None;
- BasicSpawner.Instance?.StartLobby();
+ _ = BasicSpawner.Instance?.StartLobby();
}
public void ShowCreate()
@@ -144,11 +145,7 @@ namespace Hallucinate.UI
private async void OnCreateRoomClicked()
{
var spawner = BasicSpawner.Instance;
- if (spawner == null)
- {
- Debug.LogError("[LobbyController] BasicSpawner.Instance is missing!");
- return;
- }
+ if (spawner == null) return;
string id = _roomIDInput != null && !string.IsNullOrEmpty(_roomIDInput.value)
? _roomIDInput.value.Trim()
@@ -165,14 +162,7 @@ namespace Hallucinate.UI
: null;
bool success = await spawner.StartHost(id, pass);
- if (success)
- {
- ShowLounge(name);
- }
- else
- {
- Debug.LogWarning("[LobbyController] Failed to create room. Please check AppID/Region.");
- }
+ if (success) ShowLounge(name);
}
private void UpdateRoomList(List sessions)