using UnityEditor; using UnityEngine; using BaseGames.World; namespace BaseGames.Editor { /// /// 为 DestructibleTile 和 DirectionalDestructible 在 Scene 视图中绘制 Gizmo。 /// 红色实心矩形 = 可破坏状态;灰色叉号 = 已破坏(编辑时无法判断,故始终显示可破坏状态)。 /// [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(); 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( "Gizmo:Scene 视图中橙红色边框 = 可破坏物。\n" + "子类 DirectionalDestructible 会额外显示攻击方向箭头。", MessageType.None); } } }