using System; using System.Linq; using UnityEditor; using UnityEngine; [CustomPropertyDrawer(typeof(Resource), true)] public class ResourceDrawer : PropertyDrawer { private static Resource[] resources; // public override float GetPropertyHeight(SerializedProperty property, GUIContent label) // { // if (property.managedReferenceValue == null) // return EditorGUIUtility.singleLineHeight; // // Высота для выпадающего списка + внутренних полей // return EditorGUI.GetPropertyHeight(property, true); // } private static void Initialize() { resources = ResourceStorage.RegisteredResources; // if (resourceTypes == null) // { // resourceTypes = AppDomain // .CurrentDomain.GetAssemblies() // .SelectMany(a => a.GetTypes()) // .Where(t => t.IsSubclassOf(typeof(Resource)) && !t.IsAbstract) // .ToArray(); // } } public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { Initialize(); var currentValue = property.managedReferenceValue; int newIndex = EditorGUILayout.Popup( label.text, Array.IndexOf(resources, currentValue), resources.Select(t => t.Name).ToArray() ); if (newIndex >= 0 && currentValue != resources[newIndex]) { currentValue = resources[newIndex]; property.managedReferenceValue = currentValue; } } }