using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using RPGCoreCommon.DynamicValues; using RPGCoreCommon.Helpers; using RPGCoreCommon.Helpers.CustomTypes; using RPGCoreCommon.Helpers.Exceptions; using UnityEditor; using UnityEditor.UIElements; using UnityEngine; using UnityEngine.UIElements; using Object = UnityEngine.Object; namespace RPGCoreCommon.DynamicValues.Editor { [Serializable] [CustomPropertyDrawer(typeof(DynamicValue))] public class DynamicValueDrawer : PropertyDrawer { [SerializeField] private VisualTreeAsset _visualTreeAsset; private SerializedProperty _property; private SerializedProperty _propertySourceDict; private SerializedProperty _propertyTypeDict; private SerializedProperty _propertyFormula; private DynamicValueAttribute _attribute; // Elements private VisualElement _background; private Foldout _foldoutLabel; private TextField _formulaEdit; private PropertyField _objectDictField; private PropertyField _typeDictField; private ScrollView _markerList; private Label _formulaPreview; public override VisualElement CreatePropertyGUI(SerializedProperty property) { _property = property; _propertySourceDict = property.FindPropertyRelative(nameof(DynamicValue._serializedSources)); _propertyTypeDict = property.FindPropertyRelative(nameof(DynamicValue._serializedTypes)); _propertyFormula = property.FindPropertyRelative(nameof(DynamicValue._serializedFormula)); _attribute = fieldInfo.GetCustomAttribute() ?? new DynamicValueAttribute(); var rootVisualElement = _visualTreeAsset.CloneTree(); // FIND ELEMENTS _background = rootVisualElement.Q("dv-background"); _foldoutLabel = rootVisualElement.Q("dv-foldout-label"); _foldoutLabel.text = property.displayName; _foldoutLabel.Q().RegisterValueChangedCallback(ev => TogglePreview(!ev.newValue)); _formulaEdit = rootVisualElement.Q("dv-formula-edit"); _formulaEdit.BindProperty(_propertyFormula); _objectDictField = rootVisualElement.Q("dv-sources-objects"); _objectDictField.label = ""; _objectDictField.BindProperty(_propertySourceDict); _objectDictField.TrackPropertyValue(_propertySourceDict, _ => OnSourceChanged()); _typeDictField = rootVisualElement.Q("dv-sources-types"); _typeDictField.label = ""; _typeDictField.BindProperty(_propertyTypeDict); _typeDictField.TrackPropertyValue(_propertyTypeDict, _ => OnSourceChanged()); _markerList = rootVisualElement.Q("dv-markers").Q(); _formulaPreview = rootVisualElement.Q