Update
This commit is contained in:
@@ -4,7 +4,7 @@ using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using PrimeTween;
|
||||
using OnlyScove.Scripts; // Namespace của InputReader
|
||||
using OnlyScove.Scripts;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
@@ -40,12 +40,14 @@ namespace Hallucinate.UI
|
||||
[SerializeField] private Color rippleColor = new Color(1, 1, 1, 0.4f);
|
||||
|
||||
[Header("UI Templates")]
|
||||
[SerializeField] private VisualTreeAsset loginTemplate; // Template mới
|
||||
[SerializeField] private VisualTreeAsset mainMenuTemplate;
|
||||
[SerializeField] private VisualTreeAsset lobbyTemplate;
|
||||
[SerializeField] private VisualTreeAsset profileTemplate;
|
||||
[SerializeField] private VisualTreeAsset settingsTemplate;
|
||||
[SerializeField] private VisualTreeAsset hudTemplate;
|
||||
|
||||
private LoginController _loginController;
|
||||
private MainMenuController _mainMenuController;
|
||||
private SettingsController _settingsController;
|
||||
private List<VisualElement> _trailSegments = new List<VisualElement>();
|
||||
@@ -79,7 +81,6 @@ namespace Hallucinate.UI
|
||||
|
||||
_rootElement.RegisterCallback<PointerDownEvent>(OnGlobalClick, TrickleDown.TrickleDown);
|
||||
|
||||
// Đăng ký sự kiện từ InputReader (Chuẩn New Input System)
|
||||
if (inputReader != null)
|
||||
{
|
||||
inputReader.OnToggleSettingsEvent += ToggleSettings;
|
||||
@@ -94,6 +95,29 @@ namespace Hallucinate.UI
|
||||
}
|
||||
#endif
|
||||
InitializeControllers();
|
||||
|
||||
// KIỂM TRA LOGIN
|
||||
CheckLoginStatus();
|
||||
}
|
||||
|
||||
private void CheckLoginStatus()
|
||||
{
|
||||
string savedName = PlayerPrefs.GetString("Username", "");
|
||||
if (string.IsNullOrEmpty(savedName))
|
||||
{
|
||||
_ = Push<LoginController>();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"[UIManager] Welcome back, {savedName}!");
|
||||
_ = Push<MainMenuController>();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnLoginSuccess()
|
||||
{
|
||||
// Sau khi login xong thì hiện MainMenu
|
||||
_ = Push<MainMenuController>();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
@@ -117,6 +141,7 @@ namespace Hallucinate.UI
|
||||
if (!_isSettingsOpen)
|
||||
{
|
||||
_isSettingsOpen = true;
|
||||
_settingsController.Root.BringToFront();
|
||||
_cursorLayer.BringToFront();
|
||||
await _settingsController.PlayTransitionIn();
|
||||
}
|
||||
@@ -261,6 +286,7 @@ namespace Hallucinate.UI
|
||||
|
||||
private void InitializeControllers()
|
||||
{
|
||||
_loginController = RegisterController<LoginController>(loginTemplate);
|
||||
_mainMenuController = RegisterController<MainMenuController>(mainMenuTemplate);
|
||||
if (_mainMenuController != null && gameIcon != null) _mainMenuController.SetGameIcon(gameIcon);
|
||||
|
||||
@@ -268,8 +294,6 @@ namespace Hallucinate.UI
|
||||
RegisterController<ProfileController>(profileTemplate);
|
||||
_settingsController = RegisterController<SettingsController>(settingsTemplate);
|
||||
RegisterController<HUDController>(hudTemplate);
|
||||
|
||||
_ = Push<MainMenuController>();
|
||||
}
|
||||
|
||||
private T RegisterController<T>(VisualTreeAsset template) where T : BaseUIController, new()
|
||||
|
||||
Reference in New Issue
Block a user