rabidus-test/Assets/UIMonumentButton.cs

59 lines
1.2 KiB
C#
Raw Normal View History

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(Button))]
public class UIMonumentButton : MonoBehaviour
{
[SerializeField]
private GameObject _lockPanel;
[SerializeField]
private TMPro.TextMeshProUGUI _name;
private Button _button;
private MonumentInfo _info;
private MonumentResultController _controller;
public void Init(MonumentInfo info)
{
_info = info;
_name.SetText(_info.Name);
}
private void Awake()
{
_button = GetComponent<Button>();
_controller = FindObjectOfType<MonumentResultController>();
}
private void OnEnable()
{
_button.onClick.AddListener(SelectMonument);
}
private void OnDisable()
{
_button.onClick.RemoveListener(SelectMonument);
}
public void Lock()
{
_button.interactable = false;
_lockPanel.SetActive(true);
}
public void Unlock()
{
_button.interactable = true;
_lockPanel.SetActive(false);
}
public void SelectMonument()
{
_controller.SelectMonument(_info);
}
}