using System; using System.Collections.Generic; using System.Linq; using Goap.Core; using UnityEditor; using UnityEngine; namespace Goap.Goap.Editor { public abstract class ClassDrawerBase : PropertyDrawer { private List types = new(); // Draw the property inside the given rect public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { property.stringValue = this.DrawTypeSelect(position, property.stringValue, this.GetAllOfType()); } private string DrawTypeSelect(Rect position, string currentValue, List options) { var index = options.FindIndex(x => x == currentValue); index = EditorGUI.Popup(position, "Class", index, options.ToArray()); if (index == -1) return ""; return options[index]; } private List GetAllOfType() { if (!this.types.Any()) { this.types = this.LoadAllOfType(); } return this.types; } private List LoadAllOfType() { var type = typeof(TType); return AppDomain.CurrentDomain.GetAssemblies() .Where(a => !a.IsDynamic && !a.FullName.ToLower().Contains("test")) .SelectMany(TypeReSolveHelper.ResolveTypes) .Where(t => type.IsAssignableFrom(t) && t.IsClass && !t.IsAbstract) .Select(x => x.AssemblyQualifiedName).ToList(); } } }