42 lines
1.2 KiB
C#
42 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace AibisDream.Test
|
|
{
|
|
public class OptionTest : MonoBehaviour
|
|
{
|
|
private GameObject panel;
|
|
private GameObject prefab;
|
|
|
|
void Start()
|
|
{
|
|
DialogController.Instance.RegisterOptionCommand("show_buttons", ShowButtons);
|
|
panel = transform.GetChild(0).gameObject;
|
|
prefab = Resources.Load<GameObject>("Perfabs/UI/Choice Button");
|
|
}
|
|
|
|
public void ShowButtons(YarnOption[] options)
|
|
{
|
|
foreach (YarnOption option in options)
|
|
{
|
|
var instance = Instantiate(prefab);
|
|
instance.transform.SetParent(panel.transform);
|
|
instance.GetComponentInChildren<TextMeshProUGUI>().text = option.Text;
|
|
instance.GetComponent<Button>().onClick.AddListener(() => {
|
|
option.SelectOption();
|
|
panel.SetActive(false);
|
|
});
|
|
}
|
|
}
|
|
|
|
public void OnDestroy()
|
|
{
|
|
DialogController.Instance.RemoveOptionCommand("show_buttons");
|
|
}
|
|
}
|
|
}
|
|
|