using NodeCanvas.DialogueTrees; using System; using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; namespace Ether { [UIElement(FrameTier.Top)] public class DialogueFrame : DialogueFrameBase { List choiceBtnList = new List(); private SubtitlesRequestInfo curSubTitleInfo; public override void OnOpenFrame() { _GoTempChoiceBtn.SetActive(false); _BtnExBgNext.OnClick.AddListener(() => { curSubTitleInfo.Continue(); }); } public override void OnSubscribe() { EventCenter.AddListener("OnSubtitlesRequest", OnSubtitlesRequest); EventCenter.AddListener("OnMultipleChoiceRequest", OnMultipleChoiceRequest); } private void OnSubtitlesRequest(SubtitlesRequestInfo info) { curSubTitleInfo = info; foreach (ButtonEx btnEx in choiceBtnList) { btnEx.OnClick.RemoveAllListeners(); btnEx.gameObject.SetActive(false); } _TextActorName.text = info.actor.name; _TextContent.text = info.statement.text; //Debug.LogError($"说话人:{info.actor.name},内容:{info.statement.text},声音:{info.statement.audio}"); } private void OnMultipleChoiceRequest(MultipleChoiceRequestInfo info) { int index = 0; foreach (var pair in info.options) { ButtonEx choiceBtn; if (index < choiceBtnList.Count) { choiceBtn = choiceBtnList[index]; } else { choiceBtn = GameObject.Instantiate(_GoTempChoiceBtn, _TransChoiceBtnList).GetComponent(); choiceBtnList.Add(choiceBtn); } choiceBtn.gameObject.SetActive(true); TextMeshProUGUI name = choiceBtn.transform.Find("Name").GetComponent(); name.text = pair.Key.text; choiceBtn.OnClick.AddListener(() => { info.SelectOption(pair.Value); }); index++; } } public override void OnUnSubscribe() { EventCenter.RemoveListener("OnSubtitlesRequest", OnSubtitlesRequest); EventCenter.RemoveListener("OnMultipleChoiceRequest", OnMultipleChoiceRequest); } } }