This commit is contained in:
2026-04-28 10:11:28 +07:00
parent 252489f48a
commit 6d5a9a4e5b
8 changed files with 137 additions and 742 deletions

View File

@@ -320,103 +320,6 @@ MonoBehaviour:
m_ShadowLayerMask: 1
m_RenderingLayers: 1
m_ShadowRenderingLayers: 1
--- !u!1 &1157680018
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1157680020}
- component: {fileID: 1157680019}
m_Layer: 0
m_Name: Basic Spawner
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1157680019
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1157680018}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ca752d01bdc2c5e42938776307031da3, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::_BasicSpawner
LobbyManager: {fileID: 1588175187}
_playerPrefab:
RawGuidValue: 761bdf2e5c0cff4488527355acb975e5
--- !u!4 &1157680020
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1157680018}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 10.55016, y: -0, z: 12.31339}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1588175186
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1588175188}
- component: {fileID: 1588175187}
m_Layer: 0
m_Name: Lobby manager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1588175187
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1588175186}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 258164a5e282e34489a3c62c443c22f0, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::_LobbyManager
lobbyPanel: {fileID: 0}
spawner: {fileID: 0}
playerNameInput: {fileID: 0}
roomListParent: {fileID: 0}
roomListItemPrefab: {fileID: 0}
roomNameInput: {fileID: 0}
--- !u!4 &1588175188
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1588175186}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 10.55016, y: -0, z: 12.31339}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1848374378
GameObject:
m_ObjectHideFlags: 0
@@ -560,6 +463,4 @@ SceneRoots:
m_Roots:
- {fileID: 1848374381}
- {fileID: 626355270}
- {fileID: 1588175188}
- {fileID: 1157680020}
- {fileID: 458228301}

View File

@@ -12,12 +12,13 @@ namespace Hallucinate.UI
private VisualElement _logo;
private VisualElement _ribbon;
private VisualElement _virtualCursor;
private VisualElement _logoSpace;
private float _lastInteractionTime;
private const float IDLE_TIMEOUT = 5.0f;
private Tween _pulseTween;
private Tween _rotationTween;
public override void Initialize(VisualElement uxmlRoot, UIManager manager)
{
@@ -25,89 +26,117 @@ namespace Hallucinate.UI
_logo = root.Q<VisualElement>("Logo");
_ribbon = root.Q<VisualElement>("Ribbon");
_virtualCursor = root.Q<VisualElement>("VirtualCursor");
_logoSpace = root.Q<VisualElement>("LogoSpace");
if (_logo == null)
{
Debug.LogError($"[MainMenuController] Element 'Logo' not found in UXML! Root children: {root.childCount}");
Debug.LogError($"[MainMenuController] Element 'Logo' not found in UXML!");
return;
}
_logo.RegisterCallback<PointerDownEvent>(OnLogoClicked);
ResetLogoPosition();
_logo.RegisterCallback<ClickEvent>(OnLogoClicked);
// Bind Buttons with null checks
var settingsBtn = root.Q<Button>("SettingsBtn");
if (settingsBtn != null) settingsBtn.clicked += () => uiManager.Push<SettingsController>();
var joinBtn = root.Q<Button>("JoinBtn");
if (joinBtn != null) joinBtn.clicked += () => uiManager.Push<LobbyController>();
var createBtn = root.Q<Button>("CreateBtn");
if (createBtn != null) createBtn.clicked += () => uiManager.Push<LobbyController>();
var profileBtn = root.Q<Button>("ProfileBtn");
if (profileBtn != null) profileBtn.clicked += () => uiManager.Push<ProfileController>();
var exitBtn = root.Q<Button>("ExitBtn");
if (exitBtn != null) exitBtn.clicked += () => Application.Quit();
// Bind Buttons
root.Q<Button>("SettingsBtn").clicked += () => uiManager.Push<SettingsController>();
root.Q<Button>("JoinBtn").clicked += () => uiManager.Push<LobbyController>();
root.Q<Button>("CreateBtn").clicked += () => uiManager.Push<LobbyController>();
root.Q<Button>("ProfileBtn").clicked += () => uiManager.Push<ProfileController>();
root.Q<Button>("ExitBtn").clicked += () => Application.Quit();
StartPulse();
_lastInteractionTime = Time.time;
}
private void ResetLogoPosition()
{
_logo.style.left = (Screen.width / 2f) - 100;
_logo.style.top = (Screen.height / 2f) - 100;
_logo.style.width = 200;
_logo.style.height = 200;
}
public void SetGameIcon(Texture2D icon)
{
if (icon == null || _logo == null) return;
_logo.style.backgroundImage = icon;
var radius = new StyleLength(new Length(50, LengthUnit.Percent));
_logo.style.borderTopLeftRadius = radius;
_logo.style.borderTopRightRadius = radius;
_logo.style.borderBottomLeftRadius = radius;
_logo.style.borderBottomRightRadius = radius;
_logo.style.overflow = Overflow.Hidden;
var label = _logo.Q<Label>();
if (label != null) label.style.display = DisplayStyle.None;
if (_rotationTween.isAlive) _rotationTween.Stop();
_rotationTween = Tween.Custom(0f, 360f, duration: 4f, cycles: -1, ease: Ease.Linear,
onValueChange: val => _logo.style.rotate = new StyleRotate(new Rotate(Angle.Degrees(val))));
}
public override async Task PlayTransitionIn()
{
await base.PlayTransitionIn();
UnityEngine.Cursor.visible = false;
Show();
// Đảm bảo chuột hệ thống luôn hiện
UnityEngine.Cursor.visible = true;
await Task.CompletedTask;
}
public override async Task PlayTransitionOut()
{
UnityEngine.Cursor.visible = true;
if (_rotationTween.isAlive) _rotationTween.Stop();
await base.PlayTransitionOut();
}
private void StartPulse()
{
// Use Vector3.one * 1.1f for target scale
_pulseTween = Tween.Scale(_logo.transform, Vector3.one * 1.1f, duration: 0.8f, cycles: -1, cycleMode: CycleMode.Yoyo, ease: Ease.InOutSine);
}
private void OnLogoClicked(PointerDownEvent evt)
private void OnLogoClicked(ClickEvent evt)
{
_lastInteractionTime = Time.time;
if (_currentState == MenuState.Idle)
{
TransitionToRibbon();
}
else
{
_ = uiManager.Push<LobbyController>();
}
if (_currentState == MenuState.Idle) TransitionToRibbon();
else _ = uiManager.Push<LobbyController>();
}
private void TransitionToRibbon()
private async void TransitionToRibbon()
{
_currentState = MenuState.Ribbon;
// Transition Logo using Custom tween for offset
Tween.Custom(0f, -300f, duration: 0.5f, ease: Ease.OutQuad,
onValueChange: val => _logo.style.left = val);
_ribbon.style.display = DisplayStyle.Flex;
_ribbon.style.opacity = 0;
Tween.Custom(0f, 1f, duration: 0.3f, onValueChange: val => _ribbon.style.opacity = val);
await Task.Yield();
Rect targetBounds = _logoSpace.worldBound;
// Fade in Ribbon
Tween.Custom(0f, 1f, duration: 0.5f, onValueChange: val => _ribbon.style.opacity = val);
Tween.Custom(_logo.style.left.value.value, targetBounds.x, duration: 0.5f, ease: Ease.OutQuad,
onValueChange: val => _logo.style.left = val);
Tween.Custom(_logo.style.top.value.value, targetBounds.y - 35, duration: 0.5f, ease: Ease.OutQuad,
onValueChange: val => _logo.style.top = val);
Tween.Custom(_logo.style.width.value.value, 120f, duration: 0.5f, ease: Ease.OutQuad,
onValueChange: val => _logo.style.width = val);
Tween.Custom(_logo.style.height.value.value, 120f, duration: 0.5f, ease: Ease.OutQuad,
onValueChange: val => _logo.style.height = val);
}
private void TransitionToIdle()
{
_currentState = MenuState.Idle;
Tween.Custom(-300f, 0f, duration: 0.5f, ease: Ease.OutQuad,
float targetX = (Screen.width / 2f) - 100;
float targetY = (Screen.height / 2f) - 100;
Tween.Custom(_logo.style.left.value.value, targetX, duration: 0.5f, ease: Ease.OutQuad,
onValueChange: val => _logo.style.left = val);
Tween.Custom(_logo.style.top.value.value, targetY, duration: 0.5f, ease: Ease.OutQuad,
onValueChange: val => _logo.style.top = val);
Tween.Custom(_logo.style.width.value.value, 200f, duration: 0.5f, ease: Ease.OutQuad,
onValueChange: val => _logo.style.width = val);
Tween.Custom(_logo.style.height.value.value, 200f, duration: 0.5f, ease: Ease.OutQuad,
onValueChange: val => _logo.style.height = val);
Tween.Custom(1f, 0f, duration: 0.5f, onValueChange: val => _ribbon.style.opacity = val)
.OnComplete(() => _ribbon.style.display = DisplayStyle.None);
@@ -115,32 +144,15 @@ namespace Hallucinate.UI
public void Update()
{
UpdateVirtualCursor();
if (_currentState == MenuState.Ribbon)
if (_currentState == MenuState.Ribbon && Time.time - _lastInteractionTime > IDLE_TIMEOUT)
{
if (Time.time - _lastInteractionTime > IDLE_TIMEOUT)
{
TransitionToIdle();
}
TransitionToIdle();
}
}
private void UpdateVirtualCursor()
private void StartPulse()
{
if (_virtualCursor == null) return;
Vector2 mousePos = Input.mousePosition;
float x = mousePos.x;
float y = Screen.height - mousePos.y;
if (_currentState == MenuState.Ribbon)
{
y = Screen.height / 2f + 50;
}
_virtualCursor.style.left = x - _virtualCursor.layout.width / 2;
_virtualCursor.style.top = y - _virtualCursor.layout.height / 2;
_pulseTween = Tween.Scale(_logo.transform, Vector3.one * 1.1f, duration: 0.8f, cycles: -1, cycleMode: CycleMode.Yoyo, ease: Ease.InOutSine);
}
}
}

View File

@@ -3,6 +3,9 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UIElements;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace Hallucinate.UI
{
@@ -17,6 +20,9 @@ namespace Hallucinate.UI
private readonly Dictionary<Type, BaseUIController> _controllers = new Dictionary<Type, BaseUIController>();
private readonly Stack<BaseUIController> _history = new Stack<BaseUIController>();
[Header("Game Metadata")]
[SerializeField] private Texture2D gameIcon;
[Header("UI Templates")]
[SerializeField] private VisualTreeAsset mainMenuTemplate;
[SerializeField] private VisualTreeAsset lobbyTemplate;
@@ -48,6 +54,14 @@ namespace Hallucinate.UI
_uiDocument = GetComponent<UIDocument>();
_rootElement = _uiDocument.rootVisualElement;
#if UNITY_EDITOR
if (gameIcon == null)
{
var icons = PlayerSettings.GetIconsForTargetGroup(BuildTargetGroup.Unknown);
if (icons != null && icons.Length > 0) gameIcon = icons[0];
}
#endif
InitializeControllers();
}
@@ -55,6 +69,11 @@ namespace Hallucinate.UI
private void InitializeControllers()
{
_mainMenuController = RegisterController<MainMenuController>(mainMenuTemplate);
if (_mainMenuController != null && gameIcon != null)
{
_mainMenuController.SetGameIcon(gameIcon);
}
_lobbyController = RegisterController<LobbyController>(lobbyTemplate);
_profileController = RegisterController<ProfileController>(profileTemplate);
_settingsController = RegisterController<SettingsController>(settingsTemplate);
@@ -120,7 +139,5 @@ namespace Hallucinate.UI
var previousScreen = _history.Peek();
await previousScreen.PlayTransitionIn();
}
// Custom Inspector features can be added here with [ContextMenu] or CustomEditor
}
}

View File

@@ -21,7 +21,7 @@ TextureImporter:
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
isReadable: 1
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
@@ -54,7 +54,7 @@ TextureImporter:
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureType: 7
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1

View File

@@ -21,7 +21,7 @@ TextureImporter:
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
isReadable: 1
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
@@ -54,7 +54,7 @@ TextureImporter:
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureType: 7
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1

View File

@@ -1,26 +1,23 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False"> <Style src="project:/Assets/UI/Global.uss" />
<ui:VisualElement name="HUD_Root" class="screen-root" style="picking-mode: ignore;">
<!-- Top Left: Stats -->
<ui:VisualElement name="TopLeft" style="position: absolute; top: 20px; left: 20px; width: 300px; picking-mode: ignore;">
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
<Style src="project:/Assets/UI/Global.uss" />
<ui:VisualElement name="HUD_Root" class="screen-root" picking-mode="Ignore">
<ui:VisualElement name="TopLeft" picking-mode="Ignore" style="position: absolute; top: 20px; left: 20px; width: 300px;">
<ui:ProgressBar name="HealthBar" title="HEALTH" value="100" style="margin-bottom: 5px;" />
<ui:ProgressBar name="StaminaBar" title="STAMINA" value="100" />
</ui:VisualElement>
<!-- Top Right: Minimap -->
<ui:VisualElement name="TopRight" style="position: absolute; top: 20px; right: 20px; width: 200px; height: 200px; background-color: rgba(0, 0, 0, 0.5); border-radius: 10px; border-width: 2px; border-color: white; picking-mode: ignore;">
<ui:VisualElement name="TopRight" picking-mode="Ignore" style="position: absolute; top: 20px; right: 20px; width: 200px; height: 200px; background-color: rgba(0, 0, 0, 0.5); border-radius: 10px; border-width: 2px; border-color: white;">
<ui:Label text="MINIMAP" style="align-self: center; margin-top: 80px;" />
</ui:VisualElement>
<!-- Bottom Left: Inventory -->
<ui:VisualElement name="BottomLeft" style="position: absolute; bottom: 20px; left: 20px; flex-direction: row; align-items: flex-end; picking-mode: ignore;">
<ui:VisualElement name="BottomLeft" picking-mode="Ignore" style="position: absolute; bottom: 20px; left: 20px; flex-direction: row; align-items: flex-end;">
<ui:VisualElement name="MainSlot" style="width: 80px; height: 80px; background-color: rgba(255, 255, 255, 0.1); border-width: 2px; border-color: white; margin-right: 10px;" />
<ui:VisualElement name="QuickSlot1" style="width: 50px; height: 50px; background-color: rgba(255, 255, 255, 0.1); border-width: 1px; border-color: gray; margin-right: 5px;" />
<ui:VisualElement name="QuickSlot2" style="width: 50px; height: 50px; background-color: rgba(255, 255, 255, 0.1); border-width: 1px; border-color: gray; margin-right: 5px;" />
<ui:VisualElement name="QuickSlot3" style="width: 50px; height: 50px; background-color: rgba(255, 255, 255, 0.1); border-width: 1px; border-color: gray;" />
</ui:VisualElement>
<!-- Bottom Center: Stats -->
<ui:VisualElement name="BottomCenter" style="position: absolute; bottom: 10px; width: 100%; align-items: center; picking-mode: ignore;">
<ui:VisualElement name="BottomCenter" picking-mode="Ignore" style="position: absolute; bottom: 10px; width: 100%; align-items: center;">
<ui:VisualElement style="flex-direction: row; background-color: rgba(0, 0, 0, 0.3); padding: 2px 10px; border-radius: 5px;">
<ui:Label name="PingLabel" text="PING: 25ms" style="font-size: 12px; margin-right: 15px;" />
<ui:Label name="FPSLabel" text="FPS: 144" style="font-size: 12px;" />

View File

@@ -1,18 +1,26 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False"> <Style src="project:/Assets/UI/Global.uss" />
<ui:VisualElement name="MainMenuRoot" class="screen-root">
<ui:VisualElement name="MenuContainer" style="flex-grow: 1; justify-content: center; align-items: center;">
<ui:VisualElement name="Logo" class="logo-pulse" style="background-color: white; border-radius: 100px;">
<ui:Label text="LOGO" style="color: black; align-self: center;" />
</ui:VisualElement>
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
<Style src="project:/Assets/UI/Global.uss" />
<ui:VisualElement name="MainMenuRoot" class="screen-root" picking-mode="Position">
<!-- Ribbon Container - Luôn ở giữa màn hình -->
<ui:VisualElement name="MenuContainer" picking-mode="Position" style="flex-grow: 1; justify-content: center; align-items: center;">
<ui:VisualElement name="Ribbon" style="flex-direction: row; display: none; background-color: rgba(0, 0, 0, 0.8); padding: 10px; margin-top: 20px;">
<ui:Button name="SettingsBtn" text="Settings" class="button-spring" />
<ui:Button name="JoinBtn" text="Join" class="button-spring" />
<ui:Button name="CreateBtn" text="Create" class="button-spring" />
<ui:Button name="ProfileBtn" text="Profile" class="button-spring" />
<ui:Button name="ExitBtn" text="Exit" class="button-spring" />
<ui:VisualElement name="Ribbon" picking-mode="Position" style="flex-direction: row; display: none; background-color: rgba(0, 0, 0, 0.8); padding: 5px 20px; border-radius: 10px; align-items: center; justify-content: center;">
<ui:Button name="SettingsBtn" text="Settings" class="button-spring" style="width: 100px; height: 50px;" />
<!-- Placeholder cho Logo -->
<ui:VisualElement name="LogoSpace" style="width: 120px; height: 50px; background-color: transparent; margin: 0 10px;" />
<ui:Button name="JoinBtn" text="Join" class="button-spring" style="width: 100px; height: 50px;" />
<ui:Button name="CreateBtn" text="Create" class="button-spring" style="width: 100px; height: 50px;" />
<ui:Button name="ProfileBtn" text="Profile" class="button-spring" style="width: 100px; height: 50px;" />
<ui:Button name="ExitBtn" text="Exit" class="button-spring" style="width: 100px; height: 50px;" />
</ui:VisualElement>
</ui:VisualElement>
<!-- Logo -->
<ui:VisualElement name="Logo" class="logo-pulse" picking-mode="Position" style="background-color: white; border-radius: 100px; position: absolute; width: 200px; height: 200px;">
<ui:Label text="LOGO" picking-mode="Ignore" style="color: black; align-self: center;" />
</ui:VisualElement>
<ui:VisualElement name="VirtualCursor" style="width: 20px; height: 20px; background-color: cyan; border-radius: 10px; position: absolute; picking-mode: ignore; pointer-events: none;" />
</ui:VisualElement>
</ui:UXML>