Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Editable Property in UI Element needed

Discussion in 'UI Toolkit' started by Lieene-Guo, Apr 15, 2021.

  1. Lieene-Guo

    Lieene-Guo

    Joined:
    Aug 20, 2013
    Posts:
    547
    For Inspector UI, UI Element can bind to SerializedObject perfectly fine now. But there seems to be no way to bind a Property to UI element (instead of a serialized field).
    There are two things that stopping me from doing it easily:
    1. FloatField is an editor class. There are no runtime class (probably base class for the editor-bindable-FloatFiled)
    2. A Typical Example would be a FloatFiled that has a callback on UI value change, and a repaint API (all set value) to update data value change. But I'm can't find API to do that.
      TextValueField<TValueType> and TextInputBaseField<TValueType> looks promising. But I'm still diving into it.
    So, is there a plan for Reactive ValueFields UI Elements? That could even be used in Runtime?
     
  2. Lieene-Guo

    Lieene-Guo

    Joined:
    Aug 20, 2013
    Posts:
    547
    By the way. Editing Property of a Target Unity Object can be done via IMGUI fairly easily. I can make it work via IMGUI container.
    But that will break all styling for that UI.
     
  3. broots

    broots

    Joined:
    Dec 20, 2019
    Posts:
    54
    Although unity doesn't have a solution to this yet, I had a similar requirement which I've implemented here:
    https://github.com/CoffeeVampir3/Graphify/blob/main/EditorOnly/Blackboard/FieldFactory.cs

    I used a dictionary to do the binding scheme, since you can't use the binding path without a serialized object.


    Code (CSharp):
    1.    
    2. public static BindableElement Create(Type t, object someObject, DataBlackboard bb, string bindTo)
    3.  
    Called using this create method, the data blackboard is the dictionary that contains the lookup string for the bound object. This same method will work at runtime as well.
     
    Last edited: Apr 18, 2021