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 name="ChangeListManager">
<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$/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/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/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>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -171,7 +152,7 @@
<workItem from="1777568077522" duration="8613000" />
<workItem from="1777604072510" duration="12724000" />
<workItem from="1777629255838" duration="2209000" />
<workItem from="1777631506531" duration="1317000" />
<workItem from="1777631506531" duration="2045000" />
</task>
<servers />
</component>

View File

@@ -16,6 +16,7 @@ namespace Hallucinate.UI
public NetworkRunner Runner => _runner;
private bool _isStarting = false;
private bool _isInternalShutdown = false;
public event Action<List<SessionInfo>> OnSessionListUpdatedEvent;
public event Action<string> 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<bool> StartClient(string sessionName, string password = null)
{
OnJoinStartedEvent?.Invoke();
await EnsureRunnerExists();
if (_isStarting) return false;
_isStarting = true;
var sceneManager = gameObject.GetComponent<NetworkSceneManagerDefault>();
if (sceneManager == null) sceneManager = gameObject.AddComponent<NetworkSceneManagerDefault>();
var result = await _runner.StartGame(new StartGameArgs()
try
{
GameMode = GameMode.Client,
SessionName = sessionName,
SceneManager = sceneManager
});
OnJoinStartedEvent?.Invoke();
await EnsureRunnerExists();
var sceneManager = gameObject.GetComponent<NetworkSceneManagerDefault>();
if (sceneManager == null) sceneManager = gameObject.AddComponent<NetworkSceneManagerDefault>();
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<PlayerRef, NetworkObject> _spawnedCharacters = new Dictionary<PlayerRef, NetworkObject>();
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();

View File

@@ -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<LobbyController>();
}
}

View File

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