Files
FueraDeEscala/Assets/Game/Menus/MainMenu/MainMenuController.cs
Robii Aragon 7d62bba411 Responsive UI for MainMenu & LoadingScreen
Convert MainMenu and LoadingScreen UXML/USS to responsive layouts (percent-based sizing, media queries for wide/tall screens), adjust spacing, fonts and colors, and refine spaceship icon and button styles. Update MainMenu and LoadingScreen controllers to force the root TemplateContainer to occupy the full screen. Add Assets/Resources.meta. Update metadata and LFS object IDs for several Unity assets (ReflectionProbe-0.exr.meta importer fields and AssetOrigin, Komikax font LFS oid, Loading.unity, DefaultVolumeProfile.asset, and project settings hashes) to reflect import/serialization changes.
2026-02-25 04:34:26 -08:00

71 lines
2.0 KiB
C#

using UnityEngine;
using UnityEngine.UIElements;
using UnityEngine.SceneManagement;
public class MainMenuController : MonoBehaviour
{
private UIDocument _doc;
private Button _playButton;
private Button _settingsButton;
private Button _exitButton;
[Header("Sonidos del Menú")]
public AudioClip hoverSound;
public AudioClip clickSound;
private AudioSource _audioSource;
private void Awake()
{
_doc = GetComponent<UIDocument>();
var root = _doc.rootVisualElement;
// Forzar que el TemplateContainer raíz ocupe toda la pantalla
root.style.flexGrow = 1;
root.style.width = new Length(100, LengthUnit.Percent);
root.style.height = new Length(100, LengthUnit.Percent);
_audioSource = gameObject.AddComponent<AudioSource>();
_playButton = root.Q<Button>("BtnPlay");
_settingsButton = root.Q<Button>("BtnSettings");
_exitButton = root.Q<Button>("BtnExit");
_playButton.clicked += OnPlayClicked;
_settingsButton.clicked += OnSettingsClicked;
_exitButton.clicked += OnExitClicked;
_playButton.RegisterCallback<PointerEnterEvent>(OnButtonHover);
_settingsButton.RegisterCallback<PointerEnterEvent>(OnButtonHover);
_exitButton.RegisterCallback<PointerEnterEvent>(OnButtonHover);
}
private void OnButtonHover(PointerEnterEvent evt)
{
if (hoverSound != null) _audioSource.PlayOneShot(hoverSound);
}
private void PlayClickSound()
{
if (clickSound != null) _audioSource.PlayOneShot(clickSound);
}
private void OnPlayClicked()
{
PlayClickSound();
Debug.Log("Cargando SampleScene...");
SceneManager.LoadScene("Loading");
}
private void OnSettingsClicked()
{
PlayClickSound();
Debug.Log("Abriendo ajustes...");
}
private void OnExitClicked()
{
PlayClickSound();
Debug.Log("Saliendo...");
Application.Quit();
}
}