- Implemented WorldStateFlagAttribute to mark string fields as world state flags. - Created NarrativeNPCEditor for custom inspector to visualize dialogue version activation states. - Developed WorldStateFlagDrawer to provide dropdown menu for known flags in the inspector. - Introduced ActorModule for managing DialogueActorSO assets, including viewing, creating, and deleting actors. - Added DialogueModule for managing DialogueSequenceSO assets with detailed previews and action bars. - Established QuestModule for managing QuestSO assets, including objectives and branches. - Implemented QuestManagerPostprocessor to automatically refresh QuestManager's quest list on asset changes.
73 lines
2.7 KiB
C#
73 lines
2.7 KiB
C#
using System;
|
||
using BaseGames.World;
|
||
using UnityEngine;
|
||
|
||
namespace BaseGames.Dialogue
|
||
{
|
||
/// <summary>
|
||
/// 条件对话 NPC(架构 14_NarrativeModule §7)。
|
||
/// 扩展 InteractableNPC,根据 WorldStateRegistry 标志动态选择对话版本。
|
||
/// 版本列表从高到低优先级排列;第一个满足条件的版本生效。
|
||
/// </summary>
|
||
public class NarrativeNPC : InteractableNPC
|
||
{
|
||
[Header("台词版本集(从高到低优先级排列)")]
|
||
[SerializeField] private DialogueVersion[] _dialogueVersions;
|
||
[SerializeField] private DialogueSequenceSO _fallbackDialogue; // 无条件满足时的兜底台词
|
||
[SerializeField] private WorldStateRegistry _worldState; // SO 注入
|
||
|
||
protected override DialogueSequenceSO GetCurrentDialogue()
|
||
{
|
||
if (_dialogueVersions == null) return _fallbackDialogue;
|
||
|
||
foreach (var version in _dialogueVersions)
|
||
{
|
||
if (version != null && version.CheckConditions(_worldState))
|
||
return version.dialogue;
|
||
}
|
||
|
||
if (_fallbackDialogue == null)
|
||
Debug.LogWarning($"[NarrativeNPC] '{name}' 没有版本满足当前条件,且未配置兜底对话 (_fallbackDialogue)。", gameObject);
|
||
|
||
return _fallbackDialogue;
|
||
}
|
||
}
|
||
|
||
// ─────────────────────────────────────────────────────────────────────────
|
||
|
||
/// <summary>
|
||
/// 一个对话版本及其激活条件(架构 14_NarrativeModule §7)。
|
||
/// </summary>
|
||
[Serializable]
|
||
public class DialogueVersion
|
||
{
|
||
[Tooltip("编辑器显示名,如'森林 Boss 击败后'")]
|
||
public string versionLabel;
|
||
public DialogueSequenceSO dialogue;
|
||
|
||
[Tooltip("全部满足才激活此版本(AND 关系)")]
|
||
[WorldStateFlag]
|
||
public string[] requiredFlags;
|
||
|
||
[Tooltip("有任意一个 = 此版本不激活(NOT 关系)")]
|
||
[WorldStateFlag]
|
||
public string[] blockedByFlags;
|
||
|
||
/// <summary>检查此版本的激活条件(AND requiredFlags / NOT blockedByFlags)。</summary>
|
||
public bool CheckConditions(WorldStateRegistry registry)
|
||
{
|
||
if (registry == null) return false;
|
||
|
||
if (requiredFlags != null)
|
||
foreach (var f in requiredFlags)
|
||
if (!registry.HasFlag(f)) return false;
|
||
|
||
if (blockedByFlags != null)
|
||
foreach (var f in blockedByFlags)
|
||
if (registry.HasFlag(f)) return false;
|
||
|
||
return true;
|
||
}
|
||
}
|
||
}
|