This commit is contained in:
2026-04-30 15:45:37 +07:00
parent c2b0e96570
commit 0542f5656f
4 changed files with 33 additions and 34 deletions

View File

@@ -6,11 +6,9 @@
<component name="ChangeListManager">
<list default="true" id="f9183c68-daf0-43b8-be4c-fad79983f91b" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/.idea.HALLUCINATE/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.HALLUCINATE/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scove/UIScaleTest.unity" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scove/UIScaleTest.unity" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Network/BasicSpawner.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Network/BasicSpawner.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Network/PlayerDataManager.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Network/PlayerDataManager.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/UI/LobbyController.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/UI/LobbyController.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/UI/Lobby.uxml" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/UI/Lobby.uxml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/UI/MainPanelSettings.asset" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/UI/MainPanelSettings.asset" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -150,7 +148,7 @@
<workItem from="1777376778745" duration="10727000" />
<workItem from="1777392719306" duration="13382000" />
<workItem from="1777443280908" duration="5223000" />
<workItem from="1777484328779" duration="14811000" />
<workItem from="1777484328779" duration="17223000" />
</task>
<servers />
</component>

View File

@@ -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<string, SessionProperty>();
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) { }
}
}

View File

@@ -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))

View File

@@ -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}