45 lines
1.5 KiB
C#
45 lines
1.5 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using BaseGames.Localization;
|
|
|
|
namespace BaseGames.UI.MainMenu
|
|
{
|
|
/// <summary>
|
|
/// 主菜单按钮视图(显式序列化绑定,对照 <see cref="BaseGames.UI.Inventory.ItemSlotView"/> 风格)。
|
|
/// 由 <see cref="DataDrivenMainMenuController"/> 据配置实例化并 <see cref="Bind"/>。
|
|
/// 标签走 <see cref="LocalizedText"/>,随语言切换自动刷新。
|
|
/// </summary>
|
|
[DisallowMultipleComponent]
|
|
public class MainMenuButtonView : MonoBehaviour
|
|
{
|
|
[SerializeField] private Button _button;
|
|
[SerializeField] private LocalizedText _label;
|
|
[Tooltip("按钮图标(可空)。")]
|
|
[SerializeField] private Image _icon;
|
|
|
|
public Button Button => _button;
|
|
|
|
/// <summary>绑定标签 Key、图标与点击回调。</summary>
|
|
public void Bind(string labelKey, Sprite icon, Action onClick)
|
|
{
|
|
if (_label != null) _label.SetKey(labelKey);
|
|
if (_icon != null)
|
|
{
|
|
_icon.sprite = icon;
|
|
_icon.enabled = icon != null;
|
|
}
|
|
if (_button != null)
|
|
{
|
|
_button.onClick.RemoveAllListeners();
|
|
if (onClick != null) _button.onClick.AddListener(() => onClick());
|
|
}
|
|
}
|
|
|
|
public void SetInteractable(bool value)
|
|
{
|
|
if (_button != null) _button.interactable = value;
|
|
}
|
|
}
|
|
}
|