42 lines
1.1 KiB
C#
42 lines
1.1 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace AibisDream
|
|
{
|
|
public class CenterOptions : MonoBehaviour
|
|
{
|
|
public GameObject choiceButtonPrefab;
|
|
|
|
public void ShowOptions(DialogOption[] dialogOptions)
|
|
{
|
|
gameObject.SetActive(true);
|
|
|
|
// 销毁原来的按钮
|
|
foreach (Transform child in transform)
|
|
{
|
|
Destroy(child.gameObject);
|
|
}
|
|
|
|
// 生成新按钮
|
|
foreach (var option in dialogOptions)
|
|
{
|
|
if (!option.IsAvailable) continue;
|
|
|
|
var choiceInstance = Instantiate(choiceButtonPrefab, transform);
|
|
var optionText = choiceInstance.GetComponentInChildren<TextMeshProUGUI>();
|
|
optionText.text = option.Line;
|
|
choiceInstance.GetComponent<Button>().onClick.AddListener(() =>
|
|
{
|
|
HideOptions();
|
|
option.Select();
|
|
});
|
|
}
|
|
}
|
|
|
|
public void HideOptions()
|
|
{
|
|
gameObject.SetActive(false);
|
|
}
|
|
}
|
|
} |