80 lines
3.2 KiB
C#
80 lines
3.2 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
|
|
namespace UI
|
|
{
|
|
public class MainMenuController : MonoBehaviour
|
|
{
|
|
private VisualElement _logoContainer;
|
|
private VisualElement _logo;
|
|
private VisualElement _ribbon;
|
|
private bool _isActive = false;
|
|
|
|
[Header("Animation Settings")]
|
|
public float pulseSpeed = 2f;
|
|
public float pulseAmount = 0.1f;
|
|
public float transitionDuration = 0.5f;
|
|
|
|
private void OnEnable()
|
|
{
|
|
var root = GetComponent<UIDocument>().rootVisualElement;
|
|
|
|
_logoContainer = root.Q<VisualElement>("beat-logo-container");
|
|
_logo = root.Q<VisualElement>("beat-logo");
|
|
_ribbon = root.Q<VisualElement>("menu-ribbon");
|
|
|
|
// Register logo click
|
|
_logoContainer.RegisterCallback<ClickEvent>(OnLogoClicked);
|
|
|
|
// Register button events
|
|
root.Q<Button>("btn-create")?.RegisterCallback<ClickEvent>(ev => UIManager.Instance.ShowScreen("Lobby"));
|
|
root.Q<Button>("btn-join")?.RegisterCallback<ClickEvent>(ev => UIManager.Instance.ShowScreen("Lobby"));
|
|
root.Q<Button>("btn-settings")?.RegisterCallback<ClickEvent>(ev => UIManager.Instance.ToggleSettings());
|
|
root.Q<Button>("btn-profile")?.RegisterCallback<ClickEvent>(ev => UIManager.Instance.ShowScreen("Profile"));
|
|
root.Q<Button>("btn-exit")?.RegisterCallback<ClickEvent>(ev => Application.Quit());
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!_isActive)
|
|
{
|
|
// Pulse Animation
|
|
float scale = 1f + Mathf.Sin(Time.time * pulseSpeed) * pulseAmount;
|
|
_logo.style.scale = new Scale(new Vector3(scale, scale, 1f));
|
|
}
|
|
}
|
|
|
|
private void OnLogoClicked(ClickEvent evt)
|
|
{
|
|
if (_isActive) return;
|
|
StartCoroutine(TransitionToActive());
|
|
}
|
|
|
|
private IEnumerator TransitionToActive()
|
|
{
|
|
_isActive = true;
|
|
|
|
// 1. Shrink and move logo
|
|
_logoContainer.style.transitionProperty = new List<StylePropertyName> { "scale", "translate" };
|
|
_logoContainer.style.transitionDuration = new List<TimeValue> { new TimeValue(transitionDuration, TimeUnit.Second) };
|
|
|
|
_logoContainer.style.scale = new Scale(new Vector3(0.4f, 0.4f, 1f));
|
|
// Translate is tricky in UI Toolkit relative to center, but we can use absolute positioning or a placeholder
|
|
// For now, let's just fade in the ribbon and hide the central logo
|
|
|
|
yield return new WaitForSeconds(transitionDuration * 0.5f);
|
|
|
|
_ribbon.style.display = DisplayStyle.Flex;
|
|
_ribbon.style.opacity = 0;
|
|
_ribbon.style.transitionProperty = new List<StylePropertyName> { "opacity" };
|
|
_ribbon.style.transitionDuration = new List<TimeValue> { new TimeValue(transitionDuration, TimeUnit.Second) };
|
|
|
|
yield return null;
|
|
_ribbon.style.opacity = 1;
|
|
_logoContainer.style.display = DisplayStyle.None;
|
|
}
|
|
}
|
|
}
|