This commit is contained in:
2026-05-01 18:10:32 +07:00
parent b0fab4bb6a
commit 3226eab649
4 changed files with 61 additions and 52 deletions

View File

@@ -5,28 +5,9 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="f9183c68-daf0-43b8-be4c-fad79983f91b" name="Changes" comment=""> <list default="true" id="f9183c68-daf0-43b8-be4c-fad79983f91b" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.gemini-workspace-history/active-context.md" beforeDir="false" afterPath="$PROJECT_DIR$/.gemini-workspace-history/active-context.md" afterDir="false" />
<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$/.idea/.idea.HALLUCINATE/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.HALLUCINATE/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Resources/Localization/en.json" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Resources/Localization/en.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Resources/Localization/vi.json" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Resources/Localization/vi.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scenes/Lobby.unity" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scenes/Lobby.unity.meta" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scove/UIScaleTest.unity" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scove/UIScaleTest.unity.meta" beforeDir="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/BasicSpawner.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Network/BasicSpawner.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerDashState.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerDashState.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/UI/HUDController.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/UI/HUDController.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/Scripts/UI/LobbyController.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/UI/LobbyController.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/UI/LocalizationManager.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/UI/LocalizationManager.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/UI/LoginController.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/UI/LoginController.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/UI/MainMenuController.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/UI/MainMenuController.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/UI/PerformanceOverlay.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/UI/PerformanceOverlay.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/UI/ProfileController.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/UI/ProfileController.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/UI/SettingsController.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/UI/SettingsController.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/UI/UIManager.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/UI/UIManager.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/UI/Global.uss" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/UI/Global.uss" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/UI/Settings.uxml" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/UI/Settings.uxml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ProjectSettings/EditorBuildSettings.asset" beforeDir="false" afterPath="$PROJECT_DIR$/ProjectSettings/EditorBuildSettings.asset" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -171,7 +152,7 @@
<workItem from="1777568077522" duration="8613000" /> <workItem from="1777568077522" duration="8613000" />
<workItem from="1777604072510" duration="12724000" /> <workItem from="1777604072510" duration="12724000" />
<workItem from="1777629255838" duration="2209000" /> <workItem from="1777629255838" duration="2209000" />
<workItem from="1777631506531" duration="1317000" /> <workItem from="1777631506531" duration="2045000" />
</task> </task>
<servers /> <servers />
</component> </component>

View File

@@ -16,6 +16,7 @@ namespace Hallucinate.UI
public NetworkRunner Runner => _runner; public NetworkRunner Runner => _runner;
private bool _isStarting = false; private bool _isStarting = false;
private bool _isInternalShutdown = false;
public event Action<List<SessionInfo>> OnSessionListUpdatedEvent; public event Action<List<SessionInfo>> OnSessionListUpdatedEvent;
public event Action<string> OnShutdownEvent; public event Action<string> OnShutdownEvent;
@@ -46,6 +47,9 @@ namespace Hallucinate.UI
private async Task EnsureRunnerExists() private async Task EnsureRunnerExists()
{ {
if (_runner != null) if (_runner != null)
{
_isInternalShutdown = true;
try
{ {
if (_runner.IsRunning) if (_runner.IsRunning)
{ {
@@ -57,9 +61,13 @@ namespace Hallucinate.UI
Destroy(_runner); Destroy(_runner);
_runner = null; _runner = null;
// Đợi 1 frame để đảm bảo component đã bị hủy thực sự
await Task.Yield(); await Task.Yield();
} }
finally
{
_isInternalShutdown = false;
}
}
Debug.Log("[BasicSpawner] Creating new NetworkRunner component."); Debug.Log("[BasicSpawner] Creating new NetworkRunner component.");
_runner = gameObject.AddComponent<NetworkRunner>(); _runner = gameObject.AddComponent<NetworkRunner>();
@@ -168,6 +176,11 @@ namespace Hallucinate.UI
} }
public async Task<bool> StartClient(string sessionName, string password = null) public async Task<bool> StartClient(string sessionName, string password = null)
{
if (_isStarting) return false;
_isStarting = true;
try
{ {
OnJoinStartedEvent?.Invoke(); OnJoinStartedEvent?.Invoke();
await EnsureRunnerExists(); await EnsureRunnerExists();
@@ -182,18 +195,23 @@ namespace Hallucinate.UI
SceneManager = sceneManager SceneManager = sceneManager
}); });
if (result.Ok) if (result.Ok)
{ {
return true; return true;
} }
else else
{ {
Debug.LogError($"Fusion StartClient Failed: {result.ShutdownReason}"); Debug.LogError($"[BasicSpawner] Fusion StartClient Failed: {result.ShutdownReason}");
OnJoinFailedEvent?.Invoke(); OnJoinFailedEvent?.Invoke();
return false; return false;
} }
} }
finally
{
_isStarting = false;
}
}
private Dictionary<PlayerRef, NetworkObject> _spawnedCharacters = new Dictionary<PlayerRef, NetworkObject>(); private Dictionary<PlayerRef, NetworkObject> _spawnedCharacters = new Dictionary<PlayerRef, NetworkObject>();
@@ -267,6 +285,13 @@ namespace Hallucinate.UI
Debug.LogWarning($"[Fusion] Shutdown occurred. Reason: {shutdownReason}"); Debug.LogWarning($"[Fusion] Shutdown occurred. Reason: {shutdownReason}");
OnShutdownEvent?.Invoke(shutdownReason.ToString()); 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) if (UIManager.Instance != null)
{ {
UIManager.Instance.OnBackToMenu(); UIManager.Instance.OnBackToMenu();

View File

@@ -287,8 +287,14 @@ namespace Hallucinate.UI
if (_joinContainer != null) _joinContainer.style.display = DisplayStyle.Flex; if (_joinContainer != null) _joinContainer.style.display = DisplayStyle.Flex;
if (_createContainer != null) _createContainer.style.display = DisplayStyle.None; if (_createContainer != null) _createContainer.style.display = DisplayStyle.None;
if (_loungeContainer != null) _loungeContainer.style.display = DisplayStyle.None; if (_loungeContainer != null) _loungeContainer.style.display = DisplayStyle.None;
// 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(); _ = BasicSpawner.Instance?.StartLobby();
} }
}
public void ShowCreate() public void ShowCreate()
{ {
@@ -338,9 +344,6 @@ namespace Hallucinate.UI
if (success) if (success)
{ {
ShowLounge(name); 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<LobbyController>();
} }
} }

View File

@@ -21,7 +21,7 @@ MonoBehaviour:
m_ScaleMode: 1 m_ScaleMode: 1
m_ReferenceSpritePixelsPerUnit: 100 m_ReferenceSpritePixelsPerUnit: 100
m_PixelsPerUnit: 100 m_PixelsPerUnit: 100
m_Scale: 1 m_Scale: 1.8199999
m_ReferenceDpi: 96 m_ReferenceDpi: 96
m_FallbackDpi: 96 m_FallbackDpi: 96
m_ReferenceResolution: {x: 1200, y: 800} m_ReferenceResolution: {x: 1200, y: 800}