using System; using System.Linq.Expressions; using Object = UnityEngine.Object; namespace RosettaUI.Editor { public static class UIEditor { public static Element ObjectField(Expression> targetExpression) where T : Object { return ObjectField(ExpressionUtility.CreateLabelString(targetExpression), targetExpression); } public static Element ObjectField(LabelElement label, Expression> targetExpression) where T : Object { var binder = UIInternalUtility.CreateBinder(targetExpression); return ObjectField(label, binder); } public static Element ObjectField(Expression> targetExpression, Action writeValue) where T : Object => ObjectField(ExpressionUtility.CreateLabelString(targetExpression), targetExpression.Compile(), writeValue); public static Element ObjectField(LabelElement label, Func readValue, Action writeValue) where T : Object => ObjectField(label, Binder.Create(readValue, writeValue)); public static Element ObjectField(LabelElement label, IBinder binder) where T : Object { var objectBinder = new CastBinder(binder); var element = new ObjectFieldElement(label, objectBinder, typeof(T)); UIInternalUtility.SetInteractableWithBinder(element, binder); return element; } public static Element ObjectFieldReadOnly(Expression> targetExpression) where T : Object => ObjectFieldReadOnly( ExpressionUtility.CreateLabelString(targetExpression), ExpressionUtility.CreateReadFunc(targetExpression )); public static Element ObjectFieldReadOnly(LabelElement label, Func readValue) where T : Object => ObjectField(label, readValue, null); } }