using System; using System.Linq; using System.Reflection; using RPGCoreCommon.Helpers.CustomTypes; using UnityEditor; using UnityEditor.UIElements; using UnityEngine; using UnityEngine.UIElements; namespace RPGCoreCommon.Helpers.Editor.Drawers { [Serializable] [CustomPropertyDrawer(typeof(SerializableDictionary<,>), true)] public class SerializableDictionaryDrawer : PropertyDrawer { [SerializeField] private VisualTreeAsset _visualTreeAsset; private SerializedProperty _property; private SerializedProperty _tempKeyProperty; private SerializedProperty _keysProperty; private SerializedProperty _valuesProperty; private SerializableDictionaryAttribute _sdAttribute; private Type _keyType; private Type _valueType; public override VisualElement CreatePropertyGUI(SerializedProperty property) { _property = property; _sdAttribute = fieldInfo.GetCustomAttribute() ?? new SerializableDictionaryAttribute(); _tempKeyProperty = property.FindPropertyRelative("_tempKey"); _keysProperty = property.FindPropertyRelative("_keys"); _valuesProperty = property.FindPropertyRelative("_values"); if (_keysProperty == null || _valuesProperty == null) return new HelpBox("Keys and Values in SerializableDictionary must be serializable!", HelpBoxMessageType.Error); var genericTypes = property.boxedValue.GetType().FindGenericDefinitionType(typeof(SerializableDictionary<,>)).GetGenericArguments(); _keyType = genericTypes[0]; _valueType = genericTypes[1]; var root = _visualTreeAsset.CloneTree(); root.Q