51 lines
1.2 KiB
C#
51 lines
1.2 KiB
C#
using GeometryTD.CustomEvent;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
namespace GeometryTD.UI
|
|
{
|
|
public class EventOptionItem : MonoBehaviour
|
|
{
|
|
[SerializeField] private TMP_Text _optionText;
|
|
|
|
private int _optionIndex;
|
|
|
|
public void OnInit(EventOptionItemContext context)
|
|
{
|
|
if (context == null)
|
|
{
|
|
OnReset();
|
|
gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
|
|
_optionIndex = context.OptionIndex;
|
|
if (_optionText != null)
|
|
{
|
|
_optionText.text = context.OptionText ?? string.Empty;
|
|
}
|
|
|
|
gameObject.SetActive(!string.IsNullOrEmpty(context.OptionText));
|
|
}
|
|
|
|
public void OnReset()
|
|
{
|
|
_optionIndex = -1;
|
|
if (_optionText != null)
|
|
{
|
|
_optionText.text = string.Empty;
|
|
}
|
|
}
|
|
|
|
public void OnClick()
|
|
{
|
|
if (_optionIndex < 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
GameEntry.Event.Fire(this, EventOptionItemSelectedEventArgs.Create(_optionIndex));
|
|
}
|
|
}
|
|
}
|