#if UNITY_EDITOR using UnityEditor; using UnityEngine; namespace AlicizaX.UI { public class UXControllerSceneViewWindow : EditorWindow { private Vector2 _scrollPosition; private bool _autoRefresh = false; private double _lastRefreshTime; [MenuItem("Window/UX/Controller Scene View")] public static void ShowWindow() { var window = GetWindow("UX Controller Viewer"); window.minSize = new Vector2(350, 400); window.Show(); } private void OnEnable() { _lastRefreshTime = EditorApplication.timeSinceStartup; } private void Update() { if (_autoRefresh && EditorApplication.timeSinceStartup - _lastRefreshTime > 0.5) { _lastRefreshTime = EditorApplication.timeSinceStartup; Repaint(); } } private void OnGUI() { DrawToolbar(); EditorGUILayout.Space(10); DrawControllers(); } private void DrawToolbar() { EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); if (GUILayout.Button("Refresh", EditorStyles.toolbarButton, GUILayout.Width(60))) { Repaint(); } _autoRefresh = GUILayout.Toggle(_autoRefresh, "Auto Refresh", EditorStyles.toolbarButton, GUILayout.Width(100)); GUILayout.FlexibleSpace(); if (GUILayout.Button("Reset All", EditorStyles.toolbarButton, GUILayout.Width(80))) { ResetAllControllers(); } EditorGUILayout.EndHorizontal(); } private void DrawControllers() { var controllers = GameObject.FindObjectsOfType(); if (controllers.Length == 0) { EditorGUILayout.HelpBox("No UXControllers found in the current scene.", MessageType.Info); return; } _scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition); foreach (var controller in controllers) { DrawControllerPanel(controller); EditorGUILayout.Space(5); } EditorGUILayout.EndScrollView(); } private void DrawControllerPanel(UXController controller) { EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUILayout.BeginHorizontal(); var boldLabelStyle = new GUIStyle(EditorStyles.boldLabel) { fontSize = 13 }; EditorGUILayout.LabelField(controller.name, boldLabelStyle); GUILayout.FlexibleSpace(); if (GUILayout.Button("Select", GUILayout.Width(70))) { Selection.activeGameObject = controller.gameObject; SceneView.FrameLastActiveSceneView(); } if (GUILayout.Button("Reset", GUILayout.Width(70))) { ResetController(controller); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(5); EditorGUILayout.LabelField($"Path: {GetGameObjectPath(controller.gameObject)}", EditorStyles.miniLabel); EditorGUILayout.Space(5); for (int i = 0; i < controller.ControllerCount; i++) { DrawControllerStatePanel(controller, i); } EditorGUILayout.Space(3); EditorGUILayout.LabelField($"State Recorders: {controller.Recorders.Count}", EditorStyles.miniLabel); EditorGUILayout.EndVertical(); } private void DrawControllerStatePanel(UXController controller, int controllerIndex) { var handle = controller.GetControllerAt(controllerIndex); if (handle == null) return; EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(handle.Name, EditorStyles.boldLabel, GUILayout.Width(120)); if (!string.IsNullOrEmpty(handle.Description)) { EditorGUILayout.LabelField($"({handle.Description})", EditorStyles.miniLabel); } EditorGUILayout.EndHorizontal(); int currentIndex = handle.SelectedIndex; int length = handle.Length; EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("State:", GUILayout.Width(50)); string[] options = new string[length]; for (int i = 0; i < length; i++) { options[i] = $"Index {i}"; } EditorGUI.BeginChangeCheck(); int newIndex = GUILayout.SelectionGrid(currentIndex, options, Mathf.Min(length, 5)); if (EditorGUI.EndChangeCheck() && newIndex != currentIndex) { Undo.RecordObject(controller, "Change Controller State"); controller.SetControllerIndexInternal(controllerIndex, newIndex); EditorUtility.SetDirty(controller); } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); } private void ResetController(UXController controller) { Undo.RecordObject(controller, "Reset Controller"); for (int i = 0; i < controller.ControllerCount; i++) { controller.SetControllerIndexInternal(i, 0); } EditorUtility.SetDirty(controller); Repaint(); } private void ResetAllControllers() { var controllers = GameObject.FindObjectsOfType(); foreach (var controller in controllers) { ResetController(controller); } } private string GetGameObjectPath(GameObject obj) { string path = obj.name; Transform current = obj.transform.parent; while (current != null) { path = current.name + "/" + path; current = current.parent; } return path; } } } #endif