This commit is contained in:
2026-04-30 01:30:58 +07:00
parent a8d268c42b
commit 68dd336d00
3 changed files with 27 additions and 42 deletions

View File

@@ -6,22 +6,8 @@
<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/Scenes/Menu.unity" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scenes/Menu.unity.meta" beforeDir="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/Duy/PlayerInputData.cs" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Duy/PlayerInputData.cs.meta" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Duy/_BasicSpawner.cs" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Duy/_BasicSpawner.cs.meta" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Duy/_PlayerData.cs" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Duy/_PlayerData.cs.meta" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Duy/_PlayerDataManager.cs" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Duy/_PlayerDataManager.cs.meta" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Duy/_PlayerInfo.cs" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Duy/_PlayerInfo.cs.meta" beforeDir="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/Network/BasicSpawner.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Network/BasicSpawner.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/UI/MainPanelSettings.asset" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/UI/MainPanelSettings.asset" 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" />
@@ -161,7 +147,7 @@
<workItem from="1777376778745" duration="10727000" />
<workItem from="1777392719306" duration="13382000" />
<workItem from="1777443280908" duration="5223000" />
<workItem from="1777484328779" duration="741000" />
<workItem from="1777484328779" duration="2736000" />
</task>
<servers />
</component>

View File

@@ -38,19 +38,23 @@ namespace Hallucinate.UI
private async Task EnsureRunnerExists()
{
if (_runner != null)
if (_runner == null)
{
// Nếu runner cũ vẫn đang chạy hoặc lỗi, dọn dẹp nó
await _runner.Shutdown();
if (_runner != null && _runner.gameObject != null)
{
Destroy(_runner);
}
_runner = null;
_runner = GetComponent<NetworkRunner>();
}
if (_runner != null && _runner.IsRunning)
{
await _runner.Shutdown();
}
if (_runner == null)
{
_runner = gameObject.AddComponent<NetworkRunner>();
}
_runner = gameObject.AddComponent<NetworkRunner>();
_runner.ProvideInput = true;
_runner.RemoveCallbacks(this);
_runner.AddCallbacks(this);
}
@@ -186,12 +190,17 @@ namespace Hallucinate.UI
{
runner.Despawn(networkObject);
_spawnedCharacters.Remove(player);
if (runner.IsServer) runner.Shutdown();
// Chỉ Shutdown nếu người thoát chính là Server (Host)
if (runner.IsServer && player == runner.LocalPlayer)
{
runner.Shutdown();
}
}
}
public void OnShutdown(NetworkRunner runner, ShutdownReason shutdownReason)
{
Debug.LogWarning($"[Fusion] Shutdown occurred. Reason: {shutdownReason}");
OnShutdownEvent?.Invoke(shutdownReason.ToString());
}

View File

@@ -89,14 +89,14 @@ namespace Hallucinate.UI
});
}
// Đăng ký sự kiện từ Spawner (Sử dụng Instance)
// Đăng ký sự kiện từ Spawner
if (BasicSpawner.Instance != null)
{
RegisterSpawnerEvents();
_ = BasicSpawner.Instance.StartLobby();
}
else
{
// Nếu chưa có, thử tìm sau một chút
Invoke(nameof(RegisterSpawnerEvents), 0.1f);
}
}
@@ -107,6 +107,7 @@ namespace Hallucinate.UI
BasicSpawner.Instance.OnSessionListUpdatedEvent += UpdateRoomList;
BasicSpawner.Instance.OnJoinFailedEvent += () => { if(_joinPassError != null) _joinPassError.style.display = DisplayStyle.Flex; };
BasicSpawner.Instance.OnJoinStartedEvent += () => { /* Show loading if needed */ };
_ = BasicSpawner.Instance.StartLobby();
}
public void SetRoomTemplate(VisualTreeAsset template) => _roomItemTemplate = template;
@@ -122,7 +123,7 @@ 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();
_ = BasicSpawner.Instance?.StartLobby();
}
public void ShowCreate()
@@ -144,11 +145,7 @@ namespace Hallucinate.UI
private async void OnCreateRoomClicked()
{
var spawner = BasicSpawner.Instance;
if (spawner == null)
{
Debug.LogError("[LobbyController] BasicSpawner.Instance is missing!");
return;
}
if (spawner == null) return;
string id = _roomIDInput != null && !string.IsNullOrEmpty(_roomIDInput.value)
? _roomIDInput.value.Trim()
@@ -165,14 +162,7 @@ namespace Hallucinate.UI
: null;
bool success = await spawner.StartHost(id, pass);
if (success)
{
ShowLounge(name);
}
else
{
Debug.LogWarning("[LobbyController] Failed to create room. Please check AppID/Region.");
}
if (success) ShowLounge(name);
}
private void UpdateRoomList(List<SessionInfo> sessions)