63 lines
2.0 KiB
C#
63 lines
2.0 KiB
C#
using System;
|
|
using TemplateUnity.Core;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace TemplateUnity.MainMenu
|
|
{
|
|
public class UIMainSection : UICore
|
|
{
|
|
public static UIMainSection Instance { get; private set; }
|
|
|
|
public event EventHandler onNewGameTrigger;
|
|
public event EventHandler onContinueTrigger;
|
|
public event EventHandler onOptionsTrigger;
|
|
public event EventHandler onQuitTrigger;
|
|
|
|
[Header("Buttons")]
|
|
[SerializeField] private Button newGameButton;
|
|
[SerializeField] private Button continueButton;
|
|
[SerializeField] private Button optionsButton;
|
|
[SerializeField] private Button quitButton;
|
|
|
|
private Button _lastSelectedButton;
|
|
|
|
private void Awake()
|
|
{
|
|
if (Instance)
|
|
{
|
|
Debug.LogWarning($"{typeof(UIMainSection)} already instantiated! {transform}");
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
|
|
Instance = this;
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
if(_lastSelectedButton)
|
|
_lastSelectedButton.Select();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
newGameButton.onClick.AddListener(() => onNewGameTrigger?.Invoke(this, EventArgs.Empty));
|
|
continueButton.onClick.AddListener(() => onContinueTrigger?.Invoke(this, EventArgs.Empty));
|
|
optionsButton.onClick.AddListener(() =>
|
|
{
|
|
_lastSelectedButton = optionsButton;
|
|
onOptionsTrigger?.Invoke(this, EventArgs.Empty);
|
|
});
|
|
quitButton.onClick.AddListener(() => onQuitTrigger?.Invoke(this, EventArgs.Empty));
|
|
|
|
MainMenuManager.Instance.onMainSectionReveal += (_, _) => Show();
|
|
MainMenuManager.Instance.onSaveSectionReveal += (_, _) => Hide();
|
|
MainMenuManager.Instance.onOptionsSectionReveal += (_, _) => Hide();
|
|
|
|
_lastSelectedButton = newGameButton;
|
|
_lastSelectedButton.Select();
|
|
}
|
|
}
|
|
}
|