#if UNITY_EDITOR using System; using System.Linq.Expressions; using UnityEngine.UIElements; using UnityEditor; using UnityEditor.UIElements; namespace AV.UITK { public partial class FluentElement { // TODO: Challenge! Try to achieve complex binding with InspectorPrefs.PatchesTable // TODO: SerializedProperty wrapper with linq-like deep iteration, i.e. Where("key", x => x.stringValue == patch.prefKey) public FluentElement Bind(string bindingPath) { if (x is BindableElement bindable) bindable.bindingPath = bindingPath; else throw new Exception($"{x.name} is not a BindableElement. Can't assign '{bindingPath}' as binding path."); return x; } /// Retrieves full path of a source member and sets it as a binding path. public FluentElement Bind(Expression> member) { var fullPath = FluentUITK.GetMemberPath(member); Bind(fullPath); return x; } public FluentElement Bind(SerializedProperty property) { Bind(property.propertyPath); return x; } public FluentElement Bind(SerializedObject serializedObject) { x.Bind(serializedObject); return x; } public void Unbind() => x.Unbind(); public FluentElement NewField(SerializedProperty property, string label = null) { return new PropertyField(property) { label = label }; } public FluentElement NewField(string bindingPath, string label = null) { return new PropertyField { bindingPath = bindingPath, label = label }; } public FluentElement NewField(Expression> member, string label = null) { var bindingPath = FluentUITK.GetMemberPath(member); return new PropertyField { bindingPath = bindingPath, label = label }; } } } #endif