#if UNITY_EDITOR && UNITY_2021_2_OR_NEWER using UnityEditor; using UnityEditor.Overlays; using UnityEngine; using UnityEngine.UIElements; namespace RR.Common.InspectorOverrides { [Overlay(typeof(SceneView), id: "hierarchy-selection-count", displayName: "Hierarchy Selection Count")] [Icon("d_UnityEditor.SceneHierarchyWindow")] public sealed class HierarchySelectionCountOverlay : Overlay { private Label _countLabel; public override void OnCreated() { Selection.selectionChanged += UpdateSelectionLabel; EditorApplication.hierarchyChanged += UpdateSelectionLabel; } public override void OnWillBeDestroyed() { Selection.selectionChanged -= UpdateSelectionLabel; EditorApplication.hierarchyChanged -= UpdateSelectionLabel; } public override VisualElement CreatePanelContent() { VisualElement root = new() { style = { minWidth = 180 } }; Label titleLabel = new("Выделение в Hierarchy") { style = { unityFontStyleAndWeight = FontStyle.Bold, marginBottom = 4 } }; root.Add(titleLabel); _countLabel = new Label(); root.Add(_countLabel); UpdateSelectionLabel(); return root; } private void UpdateSelectionLabel() { if (_countLabel == null) return; int selectedCount = HierarchySelectionCounter.GetSelectedHierarchyObjectCount(); _countLabel.text = selectedCount == 0 ? "Сейчас ничего не выделено" : $"Выделено объектов: {selectedCount}"; } } } #endif