74 lines
1.6 KiB
C#
74 lines
1.6 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Minesweeper.Presentation.Views
|
|
{
|
|
public sealed class MainMenuView : MonoBehaviour, IMainMenuView
|
|
{
|
|
[SerializeField] private GameObject root;
|
|
[SerializeField] private Button startButton;
|
|
|
|
public event Action StartClicked;
|
|
|
|
private void Awake()
|
|
{
|
|
if (root == null)
|
|
{
|
|
root = gameObject;
|
|
}
|
|
|
|
AutoBind();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (startButton != null)
|
|
{
|
|
startButton.onClick.AddListener(OnStartClicked);
|
|
}
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
if (startButton != null)
|
|
{
|
|
startButton.onClick.RemoveListener(OnStartClicked);
|
|
}
|
|
}
|
|
|
|
public void Show()
|
|
{
|
|
root.SetActive(true);
|
|
}
|
|
|
|
public void Hide()
|
|
{
|
|
root.SetActive(false);
|
|
}
|
|
|
|
private void OnStartClicked()
|
|
{
|
|
StartClicked?.Invoke();
|
|
}
|
|
|
|
public void Bind(GameObject root, Button startButton)
|
|
{
|
|
this.root = root != null ? root : gameObject;
|
|
this.startButton = startButton;
|
|
}
|
|
|
|
private void AutoBind()
|
|
{
|
|
if (startButton == null)
|
|
{
|
|
var startButtonTransform = transform.Find("StartButton");
|
|
if (startButtonTransform != null)
|
|
{
|
|
startButton = startButtonTransform.GetComponent<Button>();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|