存档重构,游戏内容解锁机制;教程完善(未完成)
This commit is contained in:
40
Assets/Scripts/UI/Elements/SelectionBoxButton.cs
Normal file
40
Assets/Scripts/UI/Elements/SelectionBoxButton.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Ichni.Menu.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// SelectionBox 动态生成的单个选项按钮。
|
||||
/// 预制体只需提供 Button 和 TMP 文本;运行时由 <see cref="SelectionBox"/> 写入显示文字与点击回调。
|
||||
/// </summary>
|
||||
public class SelectionBoxButton : MonoBehaviour
|
||||
{
|
||||
public Button button;
|
||||
public TMP_Text labelText;
|
||||
|
||||
/// <summary>
|
||||
/// 重新绑定按钮文字与本次 SelectionBox 的选择回调。
|
||||
/// 每次生成时都会清空旧监听,防止对象复用或预制体事件造成重复触发。
|
||||
/// </summary>
|
||||
public void SetUp(string label, UnityAction onSelected)
|
||||
{
|
||||
button ??= GetComponent<Button>();
|
||||
labelText ??= GetComponentInChildren<TMP_Text>(true);
|
||||
|
||||
if (labelText != null)
|
||||
labelText.text = label ?? string.Empty;
|
||||
|
||||
if (button == null)
|
||||
{
|
||||
Debug.LogWarning("[SelectionBoxButton] 选项预制体缺少 Button 组件。");
|
||||
return;
|
||||
}
|
||||
|
||||
button.onClick.RemoveAllListeners();
|
||||
button.onClick.AddListener(() => onSelected?.Invoke());
|
||||
button.interactable = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user