using UnityEngine; using UnityEngine.UIElements; [RequireComponent(typeof(UIDocument))] public sealed class ToolkitCounterProbe : MonoBehaviour { private Button incrementButton; private Label countLabel; private int count; private void OnEnable() { Rebind(); } [ContextMenu("Rebind Current Document (Play Mode)")] public void Rebind() { Detach(); if (!Application.isPlaying || !isActiveAndEnabled) return; UIDocument document = GetComponent(); if (document == null || !document.isActiveAndEnabled) { Debug.LogWarning("Enable the assigned UIDocument before rebinding.", this); return; } VisualElement root = document.rootVisualElement; if (root == null) { Debug.LogWarning("UIDocument has no current root; rebind after it is ready.", this); return; } incrementButton = root.Q