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(); _pauseButton = _document.rootVisualElement.Q("PauseButton") as Button; _pauseButton.RegisterCallback(OnPauseButton); _playButton = _document.rootVisualElement.Q("PlayButton") as Button; _playButton.RegisterCallback(OnPlayButton); _exitButton = _document.rootVisualElement.Q("ExitButton") as Button; _exitButton.RegisterCallback(OnExitButton); ChangeButtonsVisibility(false); GameHandler.Instance.OnGamePaused += React_OnGamePaused; GameHandler.Instance.OnGameResumed += React_OnGameResumed; } #endregion }