diff --git a/.idea/.idea.HALLUCINATE/.idea/workspace.xml b/.idea/.idea.HALLUCINATE/.idea/workspace.xml index a7d42365..dfcda12b 100644 --- a/.idea/.idea.HALLUCINATE/.idea/workspace.xml +++ b/.idea/.idea.HALLUCINATE/.idea/workspace.xml @@ -6,11 +6,9 @@ - - - + diff --git a/Assets/Scripts/Network/BasicSpawner.cs b/Assets/Scripts/Network/BasicSpawner.cs index ac2f1d21..f770a265 100644 --- a/Assets/Scripts/Network/BasicSpawner.cs +++ b/Assets/Scripts/Network/BasicSpawner.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -19,7 +19,7 @@ namespace Hallucinate.UI public event Action OnJoinStartedEvent; public event Action OnJoinFailedEvent; - [Header(""Prefabs"")] + [Header("Prefabs")] [SerializeField] private NetworkPrefabRef _playerPrefab; [SerializeField] private NetworkPrefabRef _playerDataManagerPrefab; @@ -71,7 +71,7 @@ namespace Hallucinate.UI var result = await _runner.JoinSessionLobby(SessionLobby.ClientServer); if (!result.Ok) { - Debug.LogWarning($""Join lobby result: {result.ShutdownReason}. This is often normal on first run if already connecting.""); + Debug.LogWarning($"Join lobby result: {result.ShutdownReason}. This is often normal on first run if already connecting."); } } @@ -82,7 +82,7 @@ namespace Hallucinate.UI bool sceneExists = false; for (int i = 0; i < UnityEngine.SceneManagement.SceneManager.sceneCountInBuildSettings; i++) { - if (UnityEngine.SceneManagement.SceneUtility.GetScenePathByBuildIndex(i).Contains(""Main Scene"")) + if (UnityEngine.SceneManagement.SceneUtility.GetScenePathByBuildIndex(i).Contains("Main Scene")) { sceneExists = true; break; @@ -91,7 +91,7 @@ namespace Hallucinate.UI if (!sceneExists) { - Debug.LogError(""CRITICAL: 'Main Scene' is NOT in Build Settings!""); + Debug.LogError("CRITICAL: 'Main Scene' is NOT in Build Settings!"); return false; } @@ -100,9 +100,9 @@ namespace Hallucinate.UI var customProps = new Dictionary(); if (!string.IsNullOrEmpty(password)) { - customProps.Add(""pw"", password); + customProps.Add("pw", password); } - customProps.Add(""rn"", displayName); + customProps.Add("rn", displayName); var result = await _runner.StartGame(new StartGameArgs() { @@ -126,7 +126,7 @@ namespace Hallucinate.UI } else { - Debug.LogError($""Fusion StartHost Failed: {result.ShutdownReason}.""); + Debug.LogError($"Fusion StartHost Failed: {result.ShutdownReason}."); OnJoinFailedEvent?.Invoke(); return false; } @@ -150,7 +150,7 @@ namespace Hallucinate.UI } else { - Debug.LogError($""Fusion StartClient Failed: {result.ShutdownReason}""); + Debug.LogError($"Fusion StartClient Failed: {result.ShutdownReason}"); OnJoinFailedEvent?.Invoke(); return false; } @@ -180,10 +180,10 @@ namespace Hallucinate.UI if (pdm != null) { - string playerName = LocalPlayerProfile != null ? LocalPlayerProfile.Name : ""Player "" + player.PlayerId; + string playerName = LocalPlayerProfile != null ? LocalPlayerProfile.Name : "Player " + player.PlayerId; // Thêm hậu tố (HOST) nếu là server để dễ phân biệt - if (_runner.IsServer) playerName += "" (HOST)""; + if (_runner.IsServer) playerName += " (HOST)"; _Role playerRole = _Role.Seeker; @@ -197,7 +197,7 @@ namespace Hallucinate.UI } else { - Debug.LogError(""[BasicSpawner] Could not find PlayerDataManager after retries. Data will not sync.""); + Debug.LogError("[BasicSpawner] Could not find PlayerDataManager after retries. Data will not sync."); } } @@ -205,7 +205,7 @@ namespace Hallucinate.UI { if (_runner != null && _runner.IsServer) { - _runner.LoadScene(""Main Scene""); + _runner.LoadScene("Main Scene"); } } @@ -225,7 +225,7 @@ namespace Hallucinate.UI public void OnShutdown(NetworkRunner runner, ShutdownReason shutdownReason) { - Debug.LogWarning($""[Fusion] Shutdown occurred. Reason: {shutdownReason}""); + Debug.LogWarning($"[Fusion] Shutdown occurred. Reason: {shutdownReason}"); OnShutdownEvent?.Invoke(shutdownReason.ToString()); if (UIManager.Instance != null) @@ -268,7 +268,7 @@ namespace Hallucinate.UI public void OnSceneLoadDone(NetworkRunner runner) { string currentSceneName = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name; - if (runner.IsServer && currentSceneName == ""Main Scene"") + if (runner.IsServer && currentSceneName == "Main Scene") { foreach (var player in runner.ActivePlayers) { @@ -277,12 +277,20 @@ namespace Hallucinate.UI _spawnedCharacters.Add(player, networkPlayerObject); } } - if (currentSceneName == ""Main Scene"") + // Removed incorrect UI transition for Lobby/Menu scenes to allow LobbyController to manage its state. + // The original logic incorrectly called UIManager.OnBackToMenu() when entering the Lobby scene, + // causing the redirect to the Main Menu after creating a room. + // This block ensures that only the Main Scene triggers a specific UI transition (OnGameStarted). + // If other scenes like "Lobby" or "Menu" are loaded, no automatic transition is forced from here, + // letting scene-specific controllers (like LobbyController) manage their UI. + if (currentSceneName == "Main Scene") + { UIManager.Instance?.OnGameStarted(); - else if (currentSceneName == ""Lobby"" || currentSceneName == ""Menu"") - UIManager.Instance?.OnBackToMenu(); + } + // Removed the problematic else-if block that would incorrectly call OnBackToMenu for "Lobby" or "Menu" scenes. } + public void OnSceneLoadStart(NetworkRunner runner) { } } } diff --git a/Assets/Scripts/UI/LobbyController.cs b/Assets/Scripts/UI/LobbyController.cs index d16027e0..4a0d10e8 100644 --- a/Assets/Scripts/UI/LobbyController.cs +++ b/Assets/Scripts/UI/LobbyController.cs @@ -360,17 +360,10 @@ namespace Hallucinate.UI PlayerRef hostRef = PlayerRef.None; PlayerRef guestRef = PlayerRef.None; - foreach (var p in runner.ActivePlayers) - { - if (runner.IsPlayerServer(p)) - { - hostRef = p; - } - else - { - guestRef = p; - } - } + // Trong Host Mode, chủ phòng luôn là người có PlayerId = 1 + var sortedPlayers = runner.ActivePlayers.OrderBy(p => p.PlayerId).ToList(); + if (sortedPlayers.Count > 0) hostRef = sortedPlayers[0]; + if (sortedPlayers.Count > 1) guestRef = sortedPlayers[1]; // Update Room Name for Guest if (runner.SessionInfo != null && runner.SessionInfo.Properties.TryGetValue("rn", out var rnProp)) diff --git a/Assets/UI/MainPanelSettings.asset b/Assets/UI/MainPanelSettings.asset index dd92aeaa..36254a2c 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.3 m_ReferenceDpi: 96 m_FallbackDpi: 96 m_ReferenceResolution: {x: 1200, y: 800}