using UnityEditor; using UnityEngine; using IndianOceanAssets.Engine2_5D; namespace IndianOceanAssets.EditorTools { [InitializeOnLoad] public class EnemySpawnPointSceneGUI { /// 全局开关:是否在 Scene 视图中显示所有出生点编号 public static bool ShowLabels = true; static EnemySpawnPointSceneGUI() { SceneView.duringSceneGui += OnSceneGUI; } static void OnSceneGUI(SceneView sceneView) { if (!ShowLabels) return; var spawnPoints = Object.FindObjectsByType(FindObjectsSortMode.None); foreach (var sp in spawnPoints) { if (sp.Index < 0) continue; Vector3 labelPos = sp.transform.position + Vector3.up * 2.5f; Vector2 screenPos = HandleUtility.WorldToGUIPoint(labelPos); Handles.BeginGUI(); GUIStyle style = new GUIStyle("Label") { fontSize = 14, fontStyle = FontStyle.Bold, alignment = TextAnchor.MiddleCenter, normal = { textColor = Color.yellow } }; GUIContent content = new GUIContent($"#{sp.Index}"); Vector2 size = style.CalcSize(content); Rect rect = new Rect(screenPos.x - size.x * 0.5f, screenPos.y - size.y * 0.5f, size.x + 8, size.y + 4); EditorGUI.DrawRect(rect, new Color(0, 0, 0, 0.7f)); GUI.Label(rect, content, style); Handles.EndGUI(); } } } [CustomEditor(typeof(EnemySpawnPoint))] public class EnemySpawnPointEditor : UnityEditor.Editor { public override void OnInspectorGUI() { DrawDefaultInspector(); EditorGUILayout.Space(); EnemySpawnPointSceneGUI.ShowLabels = EditorGUILayout.Toggle( "显示所有编号", EnemySpawnPointSceneGUI.ShowLabels); } } }