Files
zeling_v2/Assets/Scripts/Editor/Combat/HurtBoxEditor.cs
2026-05-12 15:34:08 +08:00

65 lines
2.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
using BaseGames.Combat;
namespace BaseGames.Editor
{
/// <summary>
/// HurtBox 运行时注入状态可视化面板。
/// 通过 HurtBox 上的 Editor* 属性读取注入状态,以颜色区分是否注入成功。
/// 绿色 = 注入完成;橙色 = 未注入(该能力静默不生效);灰色 = 非 PlayMode。
/// </summary>
[CustomEditor(typeof(HurtBox))]
public class HurtBoxEditor : UnityEditor.Editor
{
// (属性访问器, 标签, 缺席说明)
private static readonly (System.Func<HurtBox, object> getter, string label, string absentNote)[] _fields =
{
(hb => hb.EditorOwner, "Owner (IDamageable)", "— 注入失败ReceiveDamage 将无效"),
(hb => hb.EditorShieldable, "Shieldable", "— 未注入(玩家专属,敌人无需)"),
(hb => hb.EditorParrySystem, "ParrySystem", "— 未注入(弹反静默不生效)"),
(hb => hb.EditorPoiseSource, "PoiseSource", "— 未注入(霸体静默不生效)"),
(hb => hb.EditorStatusEffectable, "StatusEffectable", "— 未注入(状态效果静默不生效)"),
};
public override void OnInspectorGUI()
{
DrawDefaultInspector();
EditorGUILayout.Space(4);
EditorGUILayout.LabelField("── 运行时注入状态 ──", EditorStyles.boldLabel);
if (!Application.isPlaying)
{
EditorGUILayout.HelpBox("进入 PlayMode 后查看注入状态。", MessageType.Info);
return;
}
var hurtBox = (HurtBox)target;
foreach (var (getter, label, absentNote) in _fields)
{
var value = getter(hurtBox);
bool present = value != null;
var savedColor = GUI.contentColor;
GUI.contentColor = present
? new Color(0.3f, 0.9f, 0.4f) // 绿
: new Color(1.0f, 0.6f, 0.1f); // 橙
string displayValue = present
? $"✓ {value.GetType().Name}"
: $"✗ null {absentNote}";
EditorGUILayout.LabelField(label, displayValue);
GUI.contentColor = savedColor;
}
// 持续刷新(避免只显示初始状态)
if (Application.isPlaying) Repaint();
}
}
}
#endif