#if UNITY_EDITOR using System.Collections.Generic; using UnityEditor; using UnityEngine; namespace Amanotes.Core { [CustomPropertyDrawer(typeof(WidgetTarget))] public class WidgetTargetDrawer : PropertyDrawer { private const float ToggleW = 16f; private const float ModeW = 62f; private const float RectIdW = 70f; private const float Pad = 2f; private static readonly List _rectIdOptions = new List(8); public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { return EditorGUIUtility.singleLineHeight + Pad; } public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); var enabled = property.FindPropertyRelative("enabled"); var target = property.FindPropertyRelative("target"); var mode = property.FindPropertyRelative("mode"); var rectId = property.FindPropertyRelative("rectId"); var lineH = EditorGUIUtility.singleLineHeight; var y = position.y; // Layout: [✓] [target component] [rectId dropdown] [mode dropdown] var toggleRect = new Rect(position.x, y, ToggleW, lineH); var modeRect = new Rect(position.xMax - ModeW, y, ModeW, lineH); var rectIdRect = new Rect(modeRect.x - RectIdW - Pad, y, RectIdW, lineH); var targetRect = new Rect(toggleRect.xMax + Pad, y, rectIdRect.x - toggleRect.xMax - Pad * 2, lineH); // Toggle enabled.boolValue = EditorGUI.Toggle(toggleRect, enabled.boolValue); var prevEnabled = GUI.enabled; var prevColor = GUI.color; if (!enabled.boolValue) { GUI.enabled = false; GUI.color = new Color(1, 1, 1, 0.5f); } // Target component EditorGUI.PropertyField(targetRect, target, GUIContent.none); // RectId dropdown — build options from sibling _computedRects DrawRectIdDropdown(rectIdRect, rectId, property); // Mode EditorGUI.PropertyField(modeRect, mode, GUIContent.none); GUI.enabled = prevEnabled; GUI.color = prevColor; EditorGUI.EndProperty(); } private void DrawRectIdDropdown(Rect rect, SerializedProperty rectIdProp, SerializedProperty targetProp) { // Build dropdown options from the parent Widget2D's _computedRects list _rectIdOptions.Clear(); _rectIdOptions.Add("Original"); // index 0 = no rectId (empty string) // Walk up to find the _computedRects array on the same serialized object var computedRects = targetProp.serializedObject.FindProperty("_computedRects"); if (computedRects != null && computedRects.isArray) { for (int i = 0; i < computedRects.arraySize; i++) { var idProp = computedRects.GetArrayElementAtIndex(i).FindPropertyRelative("id"); if (idProp != null && !string.IsNullOrEmpty(idProp.stringValue)) _rectIdOptions.Add(idProp.stringValue); } } // Find current selection index var currentValue = rectIdProp.stringValue; int selectedIndex = 0; if (!string.IsNullOrEmpty(currentValue)) { for (int i = 1; i < _rectIdOptions.Count; i++) { if (_rectIdOptions[i] == currentValue) { selectedIndex = i; break; } } } // Draw popup var newIndex = EditorGUI.Popup(rect, selectedIndex, _rectIdOptions.ToArray()); if (newIndex != selectedIndex) { rectIdProp.stringValue = newIndex == 0 ? "" : _rectIdOptions[newIndex]; } } } } #endif