feat(dialog): 添加梦境选项提示语支持
标记 #option_prompt 的台词不再进入普通台词流程,由 OptionView 暂存并在下一组 Dream Options 出现时显示在选项上方,同时通过 新增 LineHistoryAppend 事件加入对话历史。OnelineOptions 支持 提示语文本与独立选项根节点,并改为按实例追踪销毁按钮。
This commit is contained in:
@@ -23,6 +23,7 @@ namespace AibisDream
|
||||
}
|
||||
|
||||
EnumEventSystem.Global.Register<DialogEventEnum, LineInfo>(DialogEventEnum.LineStart, AddDialogueLine);
|
||||
EnumEventSystem.Global.Register<DialogEventEnum, LineInfo>(DialogEventEnum.LineHistoryAppend, AddDialogueLine);
|
||||
EnumEventSystem.Global.Register<DialogEventEnum, LineInfo>(DialogEventEnum.OptionSelected, AddDialogueLine);
|
||||
EnumEventSystem.Global.Register(EventEnum.NextYarn, CleanDialogHistory);
|
||||
EnumEventSystem.Global.Register(GameLifecycleEvent.SessionEnded, CleanDialogHistory);
|
||||
@@ -33,6 +34,7 @@ namespace AibisDream
|
||||
public override void OnSingletonDestroy()
|
||||
{
|
||||
EnumEventSystem.Global.UnRegister<DialogEventEnum, LineInfo>(DialogEventEnum.LineStart, AddDialogueLine);
|
||||
EnumEventSystem.Global.UnRegister<DialogEventEnum, LineInfo>(DialogEventEnum.LineHistoryAppend, AddDialogueLine);
|
||||
EnumEventSystem.Global.UnRegister<DialogEventEnum, LineInfo>(DialogEventEnum.OptionSelected, AddDialogueLine);
|
||||
EnumEventSystem.Global.UnRegister(EventEnum.NextYarn, CleanDialogHistory);
|
||||
EnumEventSystem.Global.UnRegister(GameLifecycleEvent.SessionEnded, CleanDialogHistory);
|
||||
|
||||
@@ -1,16 +1,39 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using AibisDream.Framework;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class OnelineOptions : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameObject choiceButtonPrefab;
|
||||
[SerializeField] private Transform optionsRoot;
|
||||
[SerializeField] private bool showDisabledOptions;
|
||||
[SerializeField] private GameObject optionPromptRoot;
|
||||
[SerializeField] private TMP_Text optionPrompt;
|
||||
|
||||
public void ShowOptions(DialogOption[] dialogOptions)
|
||||
private readonly List<GameObject> _choiceInstances = new();
|
||||
|
||||
private Transform OptionsRoot => optionsRoot != null ? optionsRoot : transform;
|
||||
|
||||
private GameObject OptionPromptRoot
|
||||
{
|
||||
get
|
||||
{
|
||||
if (optionPromptRoot != null)
|
||||
return optionPromptRoot;
|
||||
if (optionPrompt != null && optionPrompt.transform.parent != null)
|
||||
return optionPrompt.transform.parent.gameObject;
|
||||
return optionPrompt != null ? optionPrompt.gameObject : null;
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowOptions(DialogOption[] dialogOptions, string optionPromptText = null)
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
ClearOptionButtons();
|
||||
ShowOptionPrompt(optionPromptText);
|
||||
|
||||
// 生成新按钮
|
||||
foreach (var option in dialogOptions)
|
||||
@@ -19,7 +42,8 @@ namespace AibisDream
|
||||
if (!option.IsAvailable && !showDisabledOptions) continue;
|
||||
|
||||
// 生成按钮
|
||||
var choiceInstance = Instantiate(choiceButtonPrefab, transform);
|
||||
var choiceInstance = Instantiate(choiceButtonPrefab, OptionsRoot);
|
||||
_choiceInstances.Add(choiceInstance);
|
||||
var choiceButton = choiceInstance.GetComponent<OnelineOption>();
|
||||
|
||||
choiceButton.Init();
|
||||
@@ -29,17 +53,60 @@ namespace AibisDream
|
||||
|
||||
public void HideOptions()
|
||||
{
|
||||
// 销毁所有按钮
|
||||
foreach (Transform child in transform)
|
||||
ClearOptionButtons();
|
||||
SetOptionPromptVisible(false);
|
||||
}
|
||||
|
||||
private void ShowOptionPrompt(string optionPromptText)
|
||||
{
|
||||
var shouldShowPrompt = !string.IsNullOrWhiteSpace(optionPromptText);
|
||||
if (shouldShowPrompt && optionPrompt != null)
|
||||
{
|
||||
Destroy(child.gameObject);
|
||||
optionPrompt.text = optionPromptText;
|
||||
}
|
||||
|
||||
SetOptionPromptVisible(shouldShowPrompt);
|
||||
}
|
||||
|
||||
private void SetOptionPromptVisible(bool visible)
|
||||
{
|
||||
var root = OptionPromptRoot;
|
||||
if (root != null)
|
||||
{
|
||||
root.SetActive(visible);
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearOptionButtons()
|
||||
{
|
||||
foreach (var choiceInstance in _choiceInstances)
|
||||
{
|
||||
if (choiceInstance != null)
|
||||
{
|
||||
Destroy(choiceInstance);
|
||||
}
|
||||
}
|
||||
|
||||
_choiceInstances.Clear();
|
||||
}
|
||||
|
||||
private void OnOptionSelected(LineInfo _)
|
||||
{
|
||||
HideOptions();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
EnumEventSystem.Global.Register<DialogEventEnum, LineInfo>(DialogEventEnum.OptionSelected,
|
||||
_ => HideOptions());
|
||||
EnumEventSystem.Global.Register<DialogEventEnum, LineInfo>(
|
||||
DialogEventEnum.OptionSelected,
|
||||
OnOptionSelected);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
EnumEventSystem.Global.UnRegister<DialogEventEnum, LineInfo>(
|
||||
DialogEventEnum.OptionSelected,
|
||||
OnOptionSelected);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user