75 lines
2.7 KiB
C#
75 lines
2.7 KiB
C#
using UnityEngine;
|
|
using Yarn.Unity;
|
|
using Sirenix.OdinInspector;
|
|
|
|
namespace SLSUtilities.Narrative.UI
|
|
{
|
|
/// <summary>
|
|
/// 高级选项展现层,继承自官方 OptionsPresenter。
|
|
/// </summary>
|
|
public class AdvancedOptionsPresenter : OptionsPresenter
|
|
{
|
|
[TitleGroup("Advanced Settings", Alignment = TitleAlignments.Centered)]
|
|
[BoxGroup("Advanced Settings/Prefabs")]
|
|
[Required("需要指定 AdvancedOptionItem 预制体")]
|
|
[SerializeField] private AdvancedOptionItem advancedOptionViewPrefab;
|
|
|
|
public override YarnTask OnDialogueStartedAsync()
|
|
{
|
|
// 建立关键词缓存,保证 ProcessWithMarkup 能正确查找关键词数据
|
|
// (不依赖 AdvancedLinePresenter 是否已经运行)
|
|
if (StorySystem.Database != null)
|
|
KeywordProcessor.BuildCache(StorySystem.Database.keywords);
|
|
|
|
return base.OnDialogueStartedAsync();
|
|
}
|
|
|
|
public override YarnTask<DialogueOption?> RunOptionsAsync(DialogueOption[] dialogueOptions, LineCancellationToken cancellationToken)
|
|
{
|
|
// 过滤掉不可用且带有 "hide" 或 "#hide" 标签的选项
|
|
var filteredOptions = new System.Collections.Generic.List<DialogueOption>();
|
|
foreach (var option in dialogueOptions)
|
|
{
|
|
bool shouldHide = false;
|
|
if (!option.IsAvailable && option.Line != null && option.Line.Metadata != null)
|
|
{
|
|
foreach (var tag in option.Line.Metadata)
|
|
{
|
|
if (tag.Equals("hide", System.StringComparison.OrdinalIgnoreCase) ||
|
|
tag.Equals("#hide", System.StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
shouldHide = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!shouldHide)
|
|
{
|
|
filteredOptions.Add(option);
|
|
}
|
|
}
|
|
|
|
return base.RunOptionsAsync(filteredOptions.ToArray(), cancellationToken);
|
|
}
|
|
|
|
protected override OptionItem CreateNewOptionView()
|
|
{
|
|
var targetTransform = canvasGroup != null ? canvasGroup.transform : this.transform;
|
|
|
|
var optionView = Instantiate(advancedOptionViewPrefab, targetTransform, false);
|
|
|
|
if (optionView == null)
|
|
{
|
|
Debug.LogError("Failed to instantiate advancedOptionViewPrefab.");
|
|
return null;
|
|
}
|
|
|
|
optionView.transform.SetAsLastSibling();
|
|
optionView.gameObject.SetActive(false);
|
|
|
|
return optionView;
|
|
}
|
|
}
|
|
}
|