Files
aibis-dream/Assets/Scripts/Test/OptionTest.cs
T
2024-10-24 14:34:42 +08:00

42 lines
1.3 KiB
C#

using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace AibisDream.Test
{
public class OptionTest : MonoBehaviour
{
private GameObject panel;
private GameObject prefab;
private GameObject[] buttonGroup;
private YarnOption[] _options;
void Start()
{
// 初始化时注册Command
// 第一个参数为[command name=xxx]的参数
// 第二个参数是注册的函数,在Yarn走到选择项时触发
DialogController.Instance.RegisterPauseCommand("show_buttons", ShowButtons);
// 不重要
panel = transform.GetChild(0).gameObject;
prefab = Resources.Load<GameObject>("Prefabs/UI/Choice Button");
}
public void ShowButtons(YarnContinueStep step)
{
var option = step;
var instance = Instantiate(prefab, panel.transform, true);
var textMesh = instance.GetComponentInChildren<TextMeshProUGUI>();
textMesh.text = "继续对话";
instance.GetComponent<Button>().onClick.AddListener(() => {
// 执行SelectOption(), 对话就会从对应的选项往下继续执行
option.ContinueTalk();
instance.SetActive(false);
});
}
}
}