Projet-IA-Madelaine/Scripts/MainMenuUI/GameUI.cs

82 lines
2.1 KiB
C#
Raw Normal View History

2024-06-12 21:03:42 +02:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
public class GameUI : MonoBehaviour
{
#region PROPERTIES
#endregion
#region VARIABLES
private UIDocument _document;
private Button _pauseButton;
private Button _playButton;
private Button _exitButton;
#endregion
#region EVENTS
private void OnPauseButton(ClickEvent e)
{
GameHandler.Instance.PauseGame();
}
private void OnPlayButton(ClickEvent e)
{
GameHandler.Instance.ResumeGame();
}
private void OnExitButton(ClickEvent e)
{
GameController.Instance.ExitToMenu("Retour au menu principal");
}
private void React_OnGamePaused(object sender, EventArgs e)
{
ChangeButtonsVisibility(true);
}
private void React_OnGameResumed(object sender, EventArgs e)
{
ChangeButtonsVisibility(false);
}
#endregion
#region METHODS
private void ChangeButtonsVisibility(bool isPaused)
{
if (isPaused)
{
_pauseButton.style.display = DisplayStyle.None;
_playButton.style.display = DisplayStyle.Flex;
_exitButton.style.display = DisplayStyle.Flex;
}
else
{
_playButton.style.display = DisplayStyle.None;
_exitButton.style.display = DisplayStyle.None;
_pauseButton.style.display = DisplayStyle.Flex;
}
}
#endregion
#region LIFECYCLE
private void Awake()
{
_document=GetComponent<UIDocument>();
_pauseButton = _document.rootVisualElement.Q("PauseButton") as Button;
_pauseButton.RegisterCallback<ClickEvent>(OnPauseButton);
_playButton = _document.rootVisualElement.Q("PlayButton") as Button;
_playButton.RegisterCallback<ClickEvent>(OnPlayButton);
_exitButton = _document.rootVisualElement.Q("ExitButton") as Button;
_exitButton.RegisterCallback<ClickEvent>(OnExitButton);
ChangeButtonsVisibility(false);
GameHandler.Instance.OnGamePaused += React_OnGamePaused;
GameHandler.Instance.OnGameResumed += React_OnGameResumed;
}
#endregion
}