46 lines
1.4 KiB
C#
46 lines
1.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using Yarn.Unity;
|
|
|
|
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);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|