47 lines
1.6 KiB
C#
47 lines
1.6 KiB
C#
using Cielonos.Core.Interaction;
|
||
using Cielonos.MainGame.Narrative;
|
||
using Sirenix.OdinInspector;
|
||
using UnityEngine;
|
||
|
||
namespace Cielonos.MainGame.Interactions
|
||
{
|
||
/// <summary>
|
||
/// NPC 交互基类。
|
||
/// 场景中的 NPC 挂载此脚本,交互时会自动将自身的 storyId 投递给 StoryDirector。
|
||
/// </summary>
|
||
public class NpcBase : InteractableObjectBase
|
||
{
|
||
[TitleGroup("Story Settings", "剧情与对话路由配置", Alignment = TitleAlignments.Centered)]
|
||
[SerializeField]
|
||
[Tooltip("对应 NarrativeEntry 剧情路由表中的 storyId (如 'OldMan')")]
|
||
protected string storyId;
|
||
|
||
/// <summary>NPC 的唯一故事 ID。</summary>
|
||
public string StoryId => storyId;
|
||
|
||
protected override void InitializeChoices()
|
||
{
|
||
choices.Add(new InteractionChoice("Talk", Talk));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 触发对话。NPC 并不感知具体播放哪个 Yarn 节点,完全委托给 StoryDirector 进行状态评估。
|
||
/// </summary>
|
||
public virtual void Talk()
|
||
{
|
||
if (string.IsNullOrEmpty(storyId))
|
||
{
|
||
Debug.LogWarning($"[NpcBase] {gameObject.name} 未配置 storyId,无法启动对话。");
|
||
return;
|
||
}
|
||
|
||
if (StoryDirector.Instance == null)
|
||
{
|
||
Debug.LogError("[NpcBase] 启动对话失败:场景中未找到 StoryDirector 实例!");
|
||
return;
|
||
}
|
||
|
||
StoryDirector.Instance.PlayStory(storyId);
|
||
}
|
||
}
|
||
} |