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

53 lines
2.0 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.
using UnityEditor;
using UnityEngine;
using BaseGames.World;
namespace BaseGames.Editor
{
/// <summary>
/// 为 DestructibleTile 和 DirectionalDestructible 在 Scene 视图中绘制 Gizmo。
/// 红色实心矩形 = 可破坏状态;灰色叉号 = 已破坏(编辑时无法判断,故始终显示可破坏状态)。
/// </summary>
[CustomEditor(typeof(DestructibleTile), true)]
public class DestructibleTileEditor : UnityEditor.Editor
{
[DrawGizmo(GizmoType.NotInSelectionHierarchy | GizmoType.InSelectionHierarchy)]
private static void DrawGizmo(DestructibleTile tile, GizmoType gizmoType)
{
if (tile == null) return;
var col = tile.GetComponent<Collider2D>();
Bounds bounds = col != null ? col.bounds : new Bounds(tile.transform.position, Vector3.one * 0.5f);
bool isSelected = (gizmoType & GizmoType.InSelectionHierarchy) != 0;
// 可破坏物:橙红色边框;选中时更亮
Gizmos.color = isSelected
? new Color(1f, 0.35f, 0.1f, 0.85f)
: new Color(1f, 0.35f, 0.1f, 0.45f);
Gizmos.DrawWireCube(bounds.center, bounds.size);
// 内部半透明填充
Gizmos.color = new Color(1f, 0.35f, 0.1f, 0.08f);
Gizmos.DrawCube(bounds.center, bounds.size);
// 中心锤子符号(用 GUI label 显示)
Handles.Label(
bounds.center + Vector3.up * (bounds.extents.y + 0.15f),
"💥",
new GUIStyle(GUI.skin.label) { fontSize = 10, alignment = TextAnchor.MiddleCenter });
}
public override void OnInspectorGUI()
{
DrawDefaultInspector();
EditorGUILayout.Space(4);
EditorGUILayout.HelpBox(
"GizmoScene 视图中橙红色边框 = 可破坏物。\n" +
"子类 DirectionalDestructible 会额外显示攻击方向箭头。",
MessageType.None);
}
}
}