diff --git a/.idea/.idea.HALLUCINATE/.idea/workspace.xml b/.idea/.idea.HALLUCINATE/.idea/workspace.xml index 95db50a4..020b6fe8 100644 --- a/.idea/.idea.HALLUCINATE/.idea/workspace.xml +++ b/.idea/.idea.HALLUCINATE/.idea/workspace.xml @@ -5,28 +5,9 @@ - - - - - - - - - - - - - - - - - - - diff --git a/Assets/Scripts/Network/BasicSpawner.cs b/Assets/Scripts/Network/BasicSpawner.cs index 6e6e015c..2867eb33 100644 --- a/Assets/Scripts/Network/BasicSpawner.cs +++ b/Assets/Scripts/Network/BasicSpawner.cs @@ -16,6 +16,7 @@ namespace Hallucinate.UI public NetworkRunner Runner => _runner; private bool _isStarting = false; + private bool _isInternalShutdown = false; public event Action> OnSessionListUpdatedEvent; public event Action OnShutdownEvent; @@ -47,18 +48,25 @@ namespace Hallucinate.UI { if (_runner != null) { - if (_runner.IsRunning) + _isInternalShutdown = true; + try { - Debug.Log("[BasicSpawner] Shutting down existing runner before recreation."); - await _runner.Shutdown(); + if (_runner.IsRunning) + { + Debug.Log("[BasicSpawner] Shutting down existing runner before recreation."); + await _runner.Shutdown(); + } + + Debug.Log("[BasicSpawner] Destroying existing runner component."); + Destroy(_runner); + _runner = null; + + await Task.Yield(); + } + finally + { + _isInternalShutdown = false; } - - Debug.Log("[BasicSpawner] Destroying existing runner component."); - Destroy(_runner); - _runner = null; - - // Đợi 1 frame để đảm bảo component đã bị hủy thực sự - await Task.Yield(); } Debug.Log("[BasicSpawner] Creating new NetworkRunner component."); @@ -169,32 +177,42 @@ namespace Hallucinate.UI public async Task StartClient(string sessionName, string password = null) { - OnJoinStartedEvent?.Invoke(); - await EnsureRunnerExists(); + if (_isStarting) return false; + _isStarting = true; - var sceneManager = gameObject.GetComponent(); - if (sceneManager == null) sceneManager = gameObject.AddComponent(); - - var result = await _runner.StartGame(new StartGameArgs() + try { - GameMode = GameMode.Client, - SessionName = sessionName, - SceneManager = sceneManager - }); + OnJoinStartedEvent?.Invoke(); + await EnsureRunnerExists(); + var sceneManager = gameObject.GetComponent(); + if (sceneManager == null) sceneManager = gameObject.AddComponent(); - if (result.Ok) - { - return true; + var result = await _runner.StartGame(new StartGameArgs() + { + GameMode = GameMode.Client, + SessionName = sessionName, + SceneManager = sceneManager + }); + + if (result.Ok) + { + return true; + } + else + { + Debug.LogError($"[BasicSpawner] Fusion StartClient Failed: {result.ShutdownReason}"); + OnJoinFailedEvent?.Invoke(); + return false; + } } - else + finally { - Debug.LogError($"Fusion StartClient Failed: {result.ShutdownReason}"); - OnJoinFailedEvent?.Invoke(); - return false; + _isStarting = false; } } + private Dictionary _spawnedCharacters = new Dictionary(); public void OnPlayerJoined(NetworkRunner runner, PlayerRef player) @@ -267,6 +285,13 @@ namespace Hallucinate.UI Debug.LogWarning($"[Fusion] Shutdown occurred. Reason: {shutdownReason}"); OnShutdownEvent?.Invoke(shutdownReason.ToString()); + // Nếu shutdown là do hệ thống chủ động hủy để tạo runner mới, KHÔNG quay về Menu + if (_isInternalShutdown) + { + Debug.Log("[BasicSpawner] Internal shutdown detected, skipping Menu routing."); + return; + } + if (UIManager.Instance != null) { UIManager.Instance.OnBackToMenu(); diff --git a/Assets/Scripts/UI/LobbyController.cs b/Assets/Scripts/UI/LobbyController.cs index 50059e01..006c5a20 100644 --- a/Assets/Scripts/UI/LobbyController.cs +++ b/Assets/Scripts/UI/LobbyController.cs @@ -287,7 +287,13 @@ 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(); + + // Chỉ bắt đầu Lobby nếu chưa có session nào đang chạy + var runner = BasicSpawner.Instance?.Runner; + if (runner == null || !runner.IsRunning) + { + _ = BasicSpawner.Instance?.StartLobby(); + } } public void ShowCreate() @@ -338,9 +344,6 @@ namespace Hallucinate.UI if (success) { ShowLounge(name); - // Explicitly push the LobbyController to ensure it's the active UI screen. - // This helps prevent unintended navigation away from the lounge. - await uiManager.Push(); } } diff --git a/Assets/UI/MainPanelSettings.asset b/Assets/UI/MainPanelSettings.asset index dd92aeaa..4a844d97 100644 --- a/Assets/UI/MainPanelSettings.asset +++ b/Assets/UI/MainPanelSettings.asset @@ -21,7 +21,7 @@ MonoBehaviour: m_ScaleMode: 1 m_ReferenceSpritePixelsPerUnit: 100 m_PixelsPerUnit: 100 - m_Scale: 1 + m_Scale: 1.8199999 m_ReferenceDpi: 96 m_FallbackDpi: 96 m_ReferenceResolution: {x: 1200, y: 800}