对话系统第一次修改
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user