Update
This commit is contained in:
@@ -236,7 +236,13 @@ namespace Hallucinate.UI
|
||||
: null;
|
||||
|
||||
bool success = await spawner.StartHost(id, name, pass);
|
||||
if (success) ShowLounge(name);
|
||||
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>();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateRoomList(List<SessionInfo> sessions)
|
||||
@@ -319,12 +325,12 @@ namespace Hallucinate.UI
|
||||
BasicSpawner.Instance?.StartGame();
|
||||
}
|
||||
|
||||
private void OnLeaveLoungeClicked()
|
||||
private async void OnLeaveLoungeClicked()
|
||||
{
|
||||
var runner = Object.FindFirstObjectByType<NetworkRunner>();
|
||||
if (runner != null)
|
||||
{
|
||||
runner.Shutdown();
|
||||
await runner.Shutdown();
|
||||
}
|
||||
if (_playerDataManager != null)
|
||||
{
|
||||
@@ -355,7 +361,7 @@ namespace Hallucinate.UI
|
||||
}
|
||||
}
|
||||
|
||||
if (_playerDataManager == null || !_playerDataManager.Object.IsValid) return;
|
||||
if (_playerDataManager == null || _playerDataManager.Object == null || !_playerDataManager.Object.IsValid) return;
|
||||
|
||||
PlayerRef hostRef = PlayerRef.None;
|
||||
PlayerRef guestRef = PlayerRef.None;
|
||||
|
||||
@@ -63,6 +63,9 @@ namespace Hallucinate.UI
|
||||
|
||||
private const string UI_SCALE_KEY = "UIScale";
|
||||
|
||||
[Header("Development Settings")]
|
||||
[SerializeField] private bool allowMultipleInstances = true;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance != null && Instance != this)
|
||||
@@ -73,6 +76,19 @@ namespace Hallucinate.UI
|
||||
Instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
// Single instance guard
|
||||
if (!Application.isEditor && !allowMultipleInstances)
|
||||
{
|
||||
var currentProcess = System.Diagnostics.Process.GetCurrentProcess();
|
||||
var processes = System.Diagnostics.Process.GetProcessesByName(currentProcess.ProcessName);
|
||||
if (processes.Length > 1)
|
||||
{
|
||||
Debug.LogError("[UIManager] Another instance is already running. Quitting to prevent save conflict.");
|
||||
Application.Quit();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_uiDocument = GetComponent<UIDocument>();
|
||||
UnityEngine.Cursor.visible = false;
|
||||
|
||||
@@ -92,10 +108,10 @@ namespace Hallucinate.UI
|
||||
public void SetUIScale(float scale)
|
||||
{
|
||||
if (_uiDocument == null || _uiDocument.panelSettings == null) return;
|
||||
|
||||
|
||||
// Unity UI Toolkit dùng panelSettings để điều khiển tỉ lệ
|
||||
// Chúng ta thay đổi scale multiplier
|
||||
_uiDocument.panelSettings.scale = scale;
|
||||
// Chúng ta thay đổi scale multiplier. Mặc định 1.0 sẽ tương ứng với visual scale là 1.3
|
||||
_uiDocument.panelSettings.scale = scale * 1.3f;
|
||||
PlayerPrefs.SetFloat(UI_SCALE_KEY, scale);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
@@ -105,7 +121,6 @@ namespace Hallucinate.UI
|
||||
float savedScale = PlayerPrefs.GetFloat(UI_SCALE_KEY, 1.0f);
|
||||
SetUIScale(savedScale);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (_uiDocument == null) _uiDocument = GetComponent<UIDocument>();
|
||||
|
||||
Reference in New Issue
Block a user