feat: Add WorldStateFlagAttribute and custom property drawer for enhanced dialogue management
- 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.
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BaseGames.Quest.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 监听 QuestSO 资产的增删/移动事件,自动刷新场景中 QuestManager 的 _allQuests 列表。
|
||||
/// 保证策划通过 DataHub 创建新任务后无需手动触发 OnValidate。
|
||||
/// </summary>
|
||||
internal sealed class QuestManagerPostprocessor : AssetPostprocessor
|
||||
{
|
||||
private static void OnPostprocessAllAssets(
|
||||
string[] imported, string[] deleted, string[] moved, string[] movedFrom)
|
||||
{
|
||||
if (!NeedsRefresh(imported) && !NeedsRefresh(deleted) && !NeedsRefresh(moved))
|
||||
return;
|
||||
|
||||
RefreshAllQuestManagers();
|
||||
}
|
||||
|
||||
private static bool NeedsRefresh(string[] paths)
|
||||
{
|
||||
if (paths == null) return false;
|
||||
foreach (var p in paths)
|
||||
{
|
||||
if (p.EndsWith(".asset", System.StringComparison.OrdinalIgnoreCase)
|
||||
&& AssetDatabase.GetMainAssetTypeAtPath(p) == typeof(QuestSO))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在所有已加载场景中查找 QuestManager,通过反射调用其
|
||||
/// EditorRefreshQuestList 方法(#if UNITY_EDITOR 区块内定义)。
|
||||
/// </summary>
|
||||
private static void RefreshAllQuestManagers()
|
||||
{
|
||||
var managers = Object.FindObjectsByType<QuestManager>(
|
||||
FindObjectsInactive.Include, FindObjectsSortMode.None);
|
||||
|
||||
if (managers == null || managers.Length == 0) return;
|
||||
|
||||
var method = typeof(QuestManager).GetMethod(
|
||||
"EditorRefreshQuestList",
|
||||
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
|
||||
|
||||
if (method == null)
|
||||
{
|
||||
Debug.LogWarning("[QuestManagerPostprocessor] 未找到 EditorRefreshQuestList 方法,请确认 QuestManager 包含该方法。");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var mgr in managers)
|
||||
{
|
||||
method.Invoke(mgr, null);
|
||||
EditorUtility.SetDirty(mgr);
|
||||
}
|
||||
|
||||
Debug.Log($"[QuestManagerPostprocessor] 已刷新 {managers.Length} 个 QuestManager 的任务列表。");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user