摄像机区域的架构改动
This commit is contained in:
161
Assets/_Game/Scripts/Editor/Events/CreateEventChannelAssets.cs
Normal file
161
Assets/_Game/Scripts/Editor/Events/CreateEventChannelAssets.cs
Normal file
@@ -0,0 +1,161 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using BaseGames.Core.Events;
|
||||
using BaseGames.Combat;
|
||||
using BaseGames.Player;
|
||||
using BaseGames.Dialogue;
|
||||
using BaseGames.Progression;
|
||||
using System.IO;
|
||||
|
||||
namespace BaseGames.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// Editor 工具:一键在 Assets/_Game/Data/Events/ 下生成所有全局事件频道 .asset 资产。
|
||||
/// 菜单:BaseGames → Tools → Create Event Channel Assets
|
||||
/// 已存在的资产会自动跳过(幂等)。
|
||||
/// </summary>
|
||||
public static class CreateEventChannelAssets
|
||||
{
|
||||
private const string RootPath = "Assets/_Game/Data/Events";
|
||||
|
||||
[MenuItem("BaseGames/Tools/Create Event Channel Assets")]
|
||||
public static void CreateAll()
|
||||
{
|
||||
// ── Core 原始类型频道 ──────────────────────────────────────────────
|
||||
CreateAsset<VoidEventChannelSO> ("Core", "EVT_Void");
|
||||
CreateAsset<BoolEventChannelSO> ("Core", "EVT_Bool");
|
||||
CreateAsset<IntEventChannelSO> ("Core", "EVT_Int");
|
||||
CreateAsset<FloatEventChannelSO> ("Core", "EVT_Float");
|
||||
CreateAsset<StringEventChannelSO> ("Core", "EVT_String");
|
||||
CreateAsset<Vector2EventChannelSO> ("Core", "EVT_Vector2");
|
||||
CreateAsset<TransformEventChannelSO> ("Core", "EVT_Transform");
|
||||
CreateAsset<GameStateEventChannelSO> ("Core", "EVT_GameState");
|
||||
CreateAsset<GameStateEventChannelSO> ("Core", "EVT_GameStateChanged");
|
||||
CreateAsset<SceneLoadRequestEventChannelSO>("Core", "EVT_SceneLoadRequest");
|
||||
CreateAsset<StringEventChannelSO> ("Core", "EVT_SceneLoaded");
|
||||
CreateAsset<VoidEventChannelSO> ("Core", "EVT_FadeInRequest");
|
||||
CreateAsset<VoidEventChannelSO> ("Core", "EVT_FadeOutRequest");
|
||||
|
||||
// ── 难度 ──────────────────────────────────────────────────────────
|
||||
CreateAsset<DifficultyChangedEventChannel>("Difficulty", "EVT_DifficultyChanged");
|
||||
|
||||
// ── 战斗 ────────────────────────────────────────────────────────── CreateAsset<DamageInfoEventChannelSO> ("Combat", "EVT_DamageDealt"); CreateAsset<HitConfirmedEventChannelSO> ("Combat", "EVT_HitConfirmed");
|
||||
CreateAsset<VoidEventChannelSO> ("Combat", "EVT_PlayerDied");
|
||||
CreateAsset<VoidEventChannelSO> ("Combat", "EVT_DeathScreenConfirmed");
|
||||
CreateAsset<VoidEventChannelSO> ("Combat", "EVT_EnemyDied");
|
||||
CreateAsset<VoidEventChannelSO> ("Combat", "EVT_ParrySuccess");
|
||||
CreateAsset<VoidEventChannelSO> ("Combat", "EVT_PlayerRespawn");
|
||||
CreateAsset<VoidEventChannelSO> ("Combat", "EVT_PlayerRespawned");
|
||||
CreateAsset<VoidEventChannelSO> ("Combat", "EVT_RespawnStarted");
|
||||
CreateAsset<VoidEventChannelSO> ("Combat", "EVT_RespawnCompleted");
|
||||
|
||||
// ── Boss ──────────────────────────────────────────────────────────
|
||||
CreateAsset<BossSkillEventChannelSO> ("Boss", "EVT_BossSkill");
|
||||
CreateAsset<BossPhaseEventChannelSO> ("Boss", "EVT_BossPhase");
|
||||
CreateAsset<StatusEffectEventChannelSO> ("Boss", "EVT_StatusEffect");
|
||||
CreateAsset<StringEventChannelSO> ("Boss", "EVT_BossFightStarted");
|
||||
CreateAsset<BoolEventChannelSO> ("Boss", "EVT_BossFightEnded");
|
||||
|
||||
// ── 任务 ──────────────────────────────────────────────────────────
|
||||
CreateAsset<QuestStateChangedEventChannel>("Quest", "EVT_QuestStateChanged");
|
||||
CreateAsset<QuestObjectiveEventChannelSO> ("Quest", "EVT_QuestObjective");
|
||||
|
||||
// ── UI ────────────────────────────────────────────────────────────
|
||||
CreateAsset<VoidEventChannelSO> ("UI", "EVT_PauseRequested");
|
||||
CreateAsset<VoidEventChannelSO> ("UI", "EVT_PauseResumed");
|
||||
CreateAsset<VoidEventChannelSO> ("UI", "EVT_FastTravelOpen");
|
||||
CreateAsset<StringEventChannelSO> ("UI", "EVT_ShopOpen");
|
||||
CreateAsset<VoidEventChannelSO> ("UI", "EVT_MapOpen");
|
||||
CreateAsset<ColorblindModeEventChannelSO> ("UI", "EVT_ColorblindMode");
|
||||
|
||||
// ── World ─────────────────────────────────────────────────────────
|
||||
CreateAsset<StringEventChannelSO> ("World", "EVT_SavePointActivated");
|
||||
|
||||
// ── 对话/商店 ─────────────────────────────────────────────────────
|
||||
CreateAsset<ShopPurchaseEventChannelSO> ("Dialogue", "EVT_ShopPurchase");
|
||||
CreateAsset<DialogueEventChannelSO> ("Dialogue", "EVT_DialogueStartRequest");
|
||||
CreateAsset<VoidEventChannelSO> ("Dialogue", "EVT_DialogueEnded");
|
||||
|
||||
// ── 玩家能力 ──────────────────────────────────────────────────────
|
||||
CreateAsset<TransformEventChannelSO> ("Player", "EVT_PlayerSpawned"); CreateAsset<IntEventChannelSO> ("Player", "EVT_HPChanged");
|
||||
CreateAsset<IntEventChannelSO> ("Player", "EVT_MaxHPChanged");
|
||||
CreateAsset<IntEventChannelSO> ("Player", "EVT_SoulPowerChanged");
|
||||
CreateAsset<IntEventChannelSO> ("Player", "EVT_SpiritPowerChanged");
|
||||
CreateAsset<IntEventChannelSO> ("Player", "EVT_SpringChargesChanged");
|
||||
CreateAsset<IntEventChannelSO> ("Player", "EVT_LingZhuChanged"); CreateAsset<AbilityTypeEventChannelSO> ("Player", "EVT_AbilityUnlocked");
|
||||
CreateAsset<StringEventChannelSO> ("Player", "EVT_AbilityUnlockedStr");
|
||||
|
||||
// ── 音频 ──────────────────────────────────────────────────────────
|
||||
CreateAsset<StringEventChannelSO> ("Audio", "EVT_BGMRequest");
|
||||
CreateAsset<VoidEventChannelSO> ("Audio", "EVT_BGMStop");
|
||||
|
||||
// ── 进度/成就 ─────────────────────────────────────────────────────
|
||||
CreateAsset<ToolUsedEventChannelSO> ("Progression", "EVT_ToolUsed");
|
||||
CreateAsset<AchievementEventChannelSO> ("Progression", "EVT_AchievementUnlocked");
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
Debug.Log("[CreateEventChannelAssets] 所有事件频道资产生成完毕。");
|
||||
}
|
||||
|
||||
[MenuItem("BaseGames/Tools/Reimport Event Channel Assets")]
|
||||
public static void ReimportAllEventAssets()
|
||||
{
|
||||
if (!AssetDatabase.IsValidFolder(RootPath))
|
||||
{
|
||||
Debug.LogWarning($"[CreateEventChannelAssets] 未找到目录: {RootPath}");
|
||||
return;
|
||||
}
|
||||
|
||||
string absoluteRoot = Path.Combine(Directory.GetCurrentDirectory(), RootPath);
|
||||
string[] files = Directory.GetFiles(absoluteRoot, "*.asset", SearchOption.AllDirectories);
|
||||
|
||||
int count = 0;
|
||||
foreach (string file in files)
|
||||
{
|
||||
string relativePath = "Assets" + file.Replace('\\', '/').Substring(Directory.GetCurrentDirectory().Length);
|
||||
AssetDatabase.ImportAsset(relativePath, ImportAssetOptions.ForceUpdate);
|
||||
count++;
|
||||
}
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
Debug.Log($"[CreateEventChannelAssets] 已重导入 {count} 个事件资产。");
|
||||
}
|
||||
|
||||
private static void CreateAsset<T>(string subfolder, string assetName) where T : ScriptableObject
|
||||
{
|
||||
string folderPath = $"{RootPath}/{subfolder}";
|
||||
EnsureDirectory(folderPath);
|
||||
|
||||
string fullPath = $"{folderPath}/{assetName}.asset";
|
||||
if (AssetDatabase.LoadAssetAtPath<T>(fullPath) != null)
|
||||
{
|
||||
Debug.Log($"[CreateEventChannelAssets] 已跳过(已存在): {fullPath}");
|
||||
return;
|
||||
}
|
||||
|
||||
T asset = ScriptableObject.CreateInstance<T>();
|
||||
AssetDatabase.CreateAsset(asset, fullPath);
|
||||
Debug.Log($"[CreateEventChannelAssets] 已创建: {fullPath}");
|
||||
}
|
||||
|
||||
/// <summary>递归创建所有缺失的中间文件夹(使用 AssetDatabase API)。</summary>
|
||||
private static void EnsureDirectory(string path)
|
||||
{
|
||||
if (AssetDatabase.IsValidFolder(path))
|
||||
return;
|
||||
|
||||
string[] parts = path.Split('/');
|
||||
string current = parts[0];
|
||||
for (int i = 1; i < parts.Length; i++)
|
||||
{
|
||||
string next = $"{current}/{parts[i]}";
|
||||
if (!AssetDatabase.IsValidFolder(next))
|
||||
AssetDatabase.CreateFolder(current, parts[i]);
|
||||
current = next;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8c6f33a6c3ce1f6469e1a2ac17c95b6b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
124
Assets/_Game/Scripts/Editor/Events/EventBusMonitorWindow.cs
Normal file
124
Assets/_Game/Scripts/Editor/Events/EventBusMonitorWindow.cs
Normal file
@@ -0,0 +1,124 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using BaseGames.Core.Events;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BaseGames.Editor
|
||||
{
|
||||
public sealed class EventBusMonitorWindow : EditorWindow
|
||||
{
|
||||
private string _filter = string.Empty;
|
||||
private bool _pauseCapture;
|
||||
private bool _autoScroll = true;
|
||||
private Vector2 _scroll;
|
||||
|
||||
[MenuItem("BaseGames/Tools/Event Bus Monitor %#e")]
|
||||
public static void OpenWindow()
|
||||
{
|
||||
EventBusMonitorWindow window = GetWindow<EventBusMonitorWindow>("Event Bus Monitor");
|
||||
window.minSize = new Vector2(760f, 320f);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
EditorApplication.update += RepaintWhilePlaying;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
EditorApplication.update -= RepaintWhilePlaying;
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
DrawToolbar();
|
||||
DrawHeader();
|
||||
DrawRows();
|
||||
}
|
||||
|
||||
private void DrawToolbar()
|
||||
{
|
||||
using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar))
|
||||
{
|
||||
_filter = EditorGUILayout.TextField(_filter, EditorStyles.toolbarSearchField,
|
||||
GUILayout.MinWidth(180f), GUILayout.ExpandWidth(true));
|
||||
|
||||
if (!string.IsNullOrEmpty(_filter)
|
||||
&& GUILayout.Button(GUIContent.none, "ToolbarSeachCancelButton"))
|
||||
{
|
||||
_filter = "";
|
||||
GUI.FocusControl(null);
|
||||
}
|
||||
|
||||
GUILayout.Space(8f);
|
||||
_pauseCapture = GUILayout.Toggle(_pauseCapture, "Pause", EditorStyles.toolbarButton, GUILayout.Width(56f));
|
||||
_autoScroll = GUILayout.Toggle(_autoScroll, "Auto Scroll", EditorStyles.toolbarButton, GUILayout.Width(82f));
|
||||
|
||||
if (GUILayout.Button("Clear", EditorStyles.toolbarButton, GUILayout.Width(48f)))
|
||||
EventBusMonitor.Clear();
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
GUILayout.Label(EditorApplication.isPlaying ? "Play Mode" : "Edit Mode", EditorStyles.miniLabel);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawHeader()
|
||||
{
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Time", EditorStyles.boldLabel, GUILayout.Width(80f));
|
||||
GUILayout.Label("Frame", EditorStyles.boldLabel, GUILayout.Width(60f));
|
||||
GUILayout.Label("Channel", EditorStyles.boldLabel, GUILayout.Width(220f));
|
||||
GUILayout.Label("Payload", EditorStyles.boldLabel, GUILayout.ExpandWidth(true));
|
||||
GUILayout.Label("Subs", EditorStyles.boldLabel, GUILayout.Width(48f));
|
||||
}
|
||||
EditorGUILayout.LabelField(GUIContent.none, GUI.skin.horizontalSlider);
|
||||
}
|
||||
|
||||
private void DrawRows()
|
||||
{
|
||||
var records = EventBusMonitor.Records;
|
||||
if (!string.IsNullOrWhiteSpace(_filter))
|
||||
{
|
||||
records = records.Where(record =>
|
||||
record.ChannelName.IndexOf(_filter, StringComparison.OrdinalIgnoreCase) >= 0 ||
|
||||
record.Payload.IndexOf(_filter, StringComparison.OrdinalIgnoreCase) >= 0);
|
||||
}
|
||||
|
||||
var displayRecords = records.ToArray();
|
||||
|
||||
_scroll = EditorGUILayout.BeginScrollView(_scroll);
|
||||
foreach (var record in displayRecords)
|
||||
DrawRow(record);
|
||||
EditorGUILayout.EndScrollView();
|
||||
|
||||
if (_autoScroll && Event.current.type == EventType.Repaint)
|
||||
_scroll.y = float.MaxValue;
|
||||
}
|
||||
|
||||
private void DrawRow(EventBusMonitor.EventRecord record)
|
||||
{
|
||||
Color oldColor = GUI.color;
|
||||
if (record.ListenerCount == 0)
|
||||
GUI.color = new Color(1f, 0.65f, 0.65f);
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label(record.Timestamp.ToString("HH:mm:ss.fff"), GUILayout.Width(80f));
|
||||
GUILayout.Label($"#{record.FrameCount}", GUILayout.Width(60f));
|
||||
GUILayout.Label(record.ChannelName, GUILayout.Width(220f));
|
||||
GUILayout.Label(record.Payload, GUILayout.ExpandWidth(true));
|
||||
GUILayout.Label(record.ListenerCount.ToString(), GUILayout.Width(48f));
|
||||
}
|
||||
|
||||
GUI.color = oldColor;
|
||||
}
|
||||
|
||||
private void RepaintWhilePlaying()
|
||||
{
|
||||
if (!_pauseCapture)
|
||||
Repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 861ce74d8a5c0ce4f957719423a0be7b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
92
Assets/_Game/Scripts/Editor/Events/EventChannelEditor.cs
Normal file
92
Assets/_Game/Scripts/Editor/Events/EventChannelEditor.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using BaseGames.Core.Events;
|
||||
|
||||
namespace BaseGames.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 为 VoidEventChannelSO 提供 Inspector 内的"Raise(测试触发)"按钮。
|
||||
/// 仅在 Play Mode 下可用,防止在编辑状态误触发副作用。
|
||||
/// </summary>
|
||||
[CustomEditor(typeof(VoidBaseEventChannelSO), true)]
|
||||
public class VoidEventChannelSOEditor : UnityEditor.Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
DrawDefaultInspector();
|
||||
|
||||
EditorGUILayout.Space(6);
|
||||
EditorGUI.BeginDisabledGroup(!Application.isPlaying);
|
||||
if (GUILayout.Button("▶ Raise(测试触发)", GUILayout.Height(28)))
|
||||
{
|
||||
var channel = (VoidBaseEventChannelSO)target;
|
||||
channel.Raise();
|
||||
Debug.Log($"[EventChannelEditor] Raised: {target.name}");
|
||||
}
|
||||
EditorGUI.EndDisabledGroup();
|
||||
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
EditorGUILayout.HelpBox("进入 Play Mode 后可点击 Raise 触发此事件。", MessageType.Info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 为所有 BaseEventChannelSO<T> 子类提供 Inspector 内的订阅者数量显示和说明标签。
|
||||
/// 因泛型限制,Raise 按钮由具体类型的派生 Editor 提供(见下方注册器)。
|
||||
/// </summary>
|
||||
[CustomEditor(typeof(ScriptableObject), true)]
|
||||
public class GenericEventChannelSOEditor : UnityEditor.Editor
|
||||
{
|
||||
// 仅对 BaseEventChannelSO<T> 子类生效
|
||||
private bool _isEventChannel;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
var t = target.GetType();
|
||||
while (t != null && t != typeof(object))
|
||||
{
|
||||
if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(BaseEventChannelSO<>))
|
||||
{
|
||||
_isEventChannel = true;
|
||||
break;
|
||||
}
|
||||
t = t.BaseType;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (!_isEventChannel)
|
||||
{
|
||||
DrawDefaultInspector();
|
||||
return;
|
||||
}
|
||||
|
||||
DrawDefaultInspector();
|
||||
|
||||
EditorGUILayout.Space(6);
|
||||
EditorGUI.BeginDisabledGroup(true);
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
// 反射获取订阅者数量
|
||||
var field = target.GetType().GetField("OnEventRaised",
|
||||
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
||||
if (field != null)
|
||||
{
|
||||
var del = field.GetValue(target) as Delegate;
|
||||
int count = del?.GetInvocationList().Length ?? 0;
|
||||
EditorGUILayout.LabelField("当前订阅者数量", count.ToString());
|
||||
}
|
||||
}
|
||||
EditorGUI.EndDisabledGroup();
|
||||
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
EditorGUILayout.HelpBox("进入 Play Mode 可查看实时订阅者数量。", MessageType.Info);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 39fd6fe0ebb5ceb4db85f82919217956
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
173
Assets/_Game/Scripts/Editor/Events/EventConfigEditor.cs
Normal file
173
Assets/_Game/Scripts/Editor/Events/EventConfigEditor.cs
Normal file
@@ -0,0 +1,173 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using BaseGames.Animation;
|
||||
|
||||
namespace BaseGames.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// AnimationEventConfigSO 自定义 Inspector(架构 §AnimationModule)。
|
||||
/// 功能:
|
||||
/// - 以时间线色块可视化事件分布
|
||||
/// - 自动检测 Clip 长度漂移(超过 5 帧则显示警告)
|
||||
/// - 验证归一化时间范围 [0, 1]
|
||||
/// - 一键对事件按归一化时间排序
|
||||
/// </summary>
|
||||
[CustomEditor(typeof(AnimationEventConfigSO))]
|
||||
public class EventConfigEditor : UnityEditor.Editor
|
||||
{
|
||||
// ── 事件类型 → 色块颜色映射 ────────────────────────────────────────
|
||||
private static readonly Dictionary<AnimationEventType, Color> _colorMap = new()
|
||||
{
|
||||
{ AnimationEventType.EnableHitBox, new Color(0.9f, 0.2f, 0.2f, 0.8f) }, // 红
|
||||
{ AnimationEventType.DisableHitBox, new Color(0.9f, 0.2f, 0.2f, 0.8f) },
|
||||
{ AnimationEventType.AttackImpact, new Color(0.9f, 0.2f, 0.2f, 0.8f) },
|
||||
|
||||
{ AnimationEventType.EnableIFrame, new Color(0.2f, 0.8f, 0.2f, 0.8f) }, // 绿
|
||||
{ AnimationEventType.DisableIFrame, new Color(0.2f, 0.8f, 0.2f, 0.8f) },
|
||||
|
||||
{ AnimationEventType.Footstep, new Color(0.2f, 0.4f, 0.9f, 0.8f) }, // 蓝
|
||||
{ AnimationEventType.PlaySFX, new Color(0.2f, 0.4f, 0.9f, 0.8f) },
|
||||
{ AnimationEventType.LandImpact, new Color(0.2f, 0.4f, 0.9f, 0.8f) },
|
||||
{ AnimationEventType.JumpLaunch, new Color(0.2f, 0.4f, 0.9f, 0.8f) },
|
||||
|
||||
{ AnimationEventType.EnableParryWindow, new Color(0.9f, 0.8f, 0.1f, 0.8f) }, // 黄
|
||||
{ AnimationEventType.DisableParryWindow,new Color(0.9f, 0.8f, 0.1f, 0.8f) },
|
||||
|
||||
{ AnimationEventType.TriggerFeedback, new Color(0.6f, 0.2f, 0.9f, 0.8f) }, // 紫
|
||||
|
||||
{ AnimationEventType.CancelWindowOpen, new Color(0.9f, 0.5f, 0.1f, 0.8f) }, // 橙
|
||||
{ AnimationEventType.CancelWindowClose, new Color(0.9f, 0.5f, 0.1f, 0.8f) },
|
||||
|
||||
{ AnimationEventType.SpawnProjectile, new Color(0.9f, 0.9f, 0.9f, 0.8f) }, // 白
|
||||
{ AnimationEventType.RoarStart, new Color(0.9f, 0.9f, 0.9f, 0.8f) },
|
||||
{ AnimationEventType.RoarEnd, new Color(0.9f, 0.9f, 0.9f, 0.8f) },
|
||||
{ AnimationEventType.PhaseTwoStart, new Color(0.9f, 0.9f, 0.9f, 0.8f) },
|
||||
};
|
||||
|
||||
private const float TimelineHeight = 24f;
|
||||
private const float MarkerWidth = 3f;
|
||||
private const float DriftThresholdFrames = 5f;
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
var config = (AnimationEventConfigSO)target;
|
||||
serializedObject.Update();
|
||||
|
||||
// ── 时间线预览 ───────────────────────────────────────────────
|
||||
EditorGUILayout.LabelField("事件时间线预览", EditorStyles.boldLabel);
|
||||
DrawTimeline(config);
|
||||
EditorGUILayout.Space(4f);
|
||||
|
||||
// ── 标准字段 ─────────────────────────────────────────────────
|
||||
DrawDefaultInspector();
|
||||
EditorGUILayout.Space(4f);
|
||||
|
||||
// ── 验证警告 ─────────────────────────────────────────────────
|
||||
ValidateEntries(config);
|
||||
|
||||
// ── Clip 长度漂移检测 ─────────────────────────────────────────
|
||||
if (config.targetClip != null && config.ExpectedClipLength > 0f)
|
||||
{
|
||||
float fps = config.targetClip.frameRate;
|
||||
float actualLen = config.targetClip.length;
|
||||
float drift = Mathf.Abs(actualLen - config.ExpectedClipLength) * fps;
|
||||
|
||||
if (drift > DriftThresholdFrames)
|
||||
{
|
||||
EditorGUILayout.HelpBox(
|
||||
$"⚠ Clip 长度已变化 {drift:F1} 帧(期望 {config.ExpectedClipLength:F3}s," +
|
||||
$"实际 {actualLen:F3}s)。\n请检查事件时机是否需要更新。",
|
||||
MessageType.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.Space(4f);
|
||||
|
||||
// ── 操作按钮 ─────────────────────────────────────────────────
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
if (GUILayout.Button("按时间排序"))
|
||||
{
|
||||
SortEvents(config);
|
||||
}
|
||||
|
||||
if (config.targetClip != null && GUILayout.Button("记录当前 Clip 长度"))
|
||||
{
|
||||
Undo.RecordObject(config, "记录 Clip 长度");
|
||||
config.ExpectedClipLength = config.targetClip.length;
|
||||
EditorUtility.SetDirty(config);
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
// ── 时间线绘制 ────────────────────────────────────────────────────
|
||||
|
||||
private static void DrawTimeline(AnimationEventConfigSO config)
|
||||
{
|
||||
Rect rect = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none,
|
||||
GUILayout.Height(TimelineHeight), GUILayout.ExpandWidth(true));
|
||||
|
||||
// 背景轨道
|
||||
EditorGUI.DrawRect(rect, new Color(0.15f, 0.15f, 0.15f, 1f));
|
||||
|
||||
// 标尺刻度(每 10% 一条)
|
||||
for (int i = 0; i <= 10; i++)
|
||||
{
|
||||
float x = rect.x + rect.width * i / 10f;
|
||||
float h = (i % 5 == 0) ? rect.height * 0.6f : rect.height * 0.3f;
|
||||
var tick = new Rect(x, rect.y + rect.height - h, 1f, h);
|
||||
EditorGUI.DrawRect(tick, new Color(0.5f, 0.5f, 0.5f, 0.8f));
|
||||
}
|
||||
|
||||
if (config.events == null) return;
|
||||
|
||||
foreach (var entry in config.events)
|
||||
{
|
||||
float nx = Mathf.Clamp01(entry.normalizedTime);
|
||||
float xPos = rect.x + rect.width * nx - MarkerWidth * 0.5f;
|
||||
var markerRect = new Rect(xPos, rect.y + 2f, MarkerWidth, rect.height - 4f);
|
||||
|
||||
Color color = _colorMap.TryGetValue(entry.eventType, out var c)
|
||||
? c
|
||||
: new Color(0.8f, 0.8f, 0.8f, 0.8f);
|
||||
|
||||
EditorGUI.DrawRect(markerRect, color);
|
||||
}
|
||||
}
|
||||
|
||||
// ── 验证 ──────────────────────────────────────────────────────────
|
||||
|
||||
private static void ValidateEntries(AnimationEventConfigSO config)
|
||||
{
|
||||
if (config.events == null) return;
|
||||
|
||||
for (int i = 0; i < config.events.Length; i++)
|
||||
{
|
||||
float t = config.events[i].normalizedTime;
|
||||
if (t < 0f || t > 1f)
|
||||
{
|
||||
EditorGUILayout.HelpBox(
|
||||
$"事件 [{i}] {config.events[i].eventType}:" +
|
||||
$"normalizedTime = {t:F3} 超出 [0, 1] 范围。",
|
||||
MessageType.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ── 排序 ──────────────────────────────────────────────────────────
|
||||
|
||||
private static void SortEvents(AnimationEventConfigSO config)
|
||||
{
|
||||
if (config.events == null || config.events.Length < 2) return;
|
||||
|
||||
Undo.RecordObject(config, "排序动画事件");
|
||||
System.Array.Sort(config.events, (a, b) =>
|
||||
a.normalizedTime.CompareTo(b.normalizedTime));
|
||||
EditorUtility.SetDirty(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/_Game/Scripts/Editor/Events/EventConfigEditor.cs.meta
Normal file
11
Assets/_Game/Scripts/Editor/Events/EventConfigEditor.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c992100309cc05a40bb06a3e23076c5b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user