Search Unity

¿How do a fine DragAndDrop Objects?

Discussion in 'UI Toolkit' started by yackson-cc, Jul 29, 2020.

  1. yackson-cc

    yackson-cc

    Joined:
    May 14, 2016
    Posts:
    48
    Hi! i wish a good day for you :D.

    I have in my .cs code the next lines:

    upload_2020-7-29_2-55-38.png

    In my .uxml file i have this:

    upload_2020-7-29_2-56-27.png

    up to this point, all works fine, but after in the .uss is the wrong:

    upload_2020-7-29_2-58-50.png

    it .uss style looks how this:

    upload_2020-7-29_2-59-35.png

    So ugly, i need do somehow this:

    upload_2020-7-29_3-1-25.png

    my final questions are:

    ¿this is the correct way for do a functionality of drag and drop?
    ¿How i can change the text/style by default of unity for fields or anything ?

    Thanks a lot, save you!.
     
  2. yackson-cc

    yackson-cc

    Joined:
    May 14, 2016
    Posts:
    48
  3. yackson-cc

    yackson-cc

    Joined:
    May 14, 2016
    Posts:
    48
    Hi @uDamian please, i need this info :D, helpme
     
  4. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    780
    It's a bit difficult to answer you precisely so here are some general recommendations:
    - Use the UI Toolkit Debugger (from the Window menu or from the options of each window) to identify which elements you want to affect and which styles you need to modify
    - Use display:none to remove elements you don't want
    - Generally, our controls are not meant to be completely taken over from a functionality perspective, and some cases even styling. Consider doing you own elements from scratch (although in this case I don't think you have a way to show an object selector all by your self).

    Generally though, listen for DragPerformEvent is the way to go to handle multi window drag and drop in Unity Editor. Just make sure to call https://docs.unity3d.com/ScriptReference/DragAndDrop.AcceptDrag.html (although in this case the ObjectField is already doing it).
     
  5. yackson-cc

    yackson-cc

    Joined:
    May 14, 2016
    Posts:
    48
    @antoine-unity Hi, thanks for the response.

    in order to check your response:

    -I use toolkit debugger for search the class/names of the objectField for modify it, i was could modify the style, but no the internal text "None (audioClip)", how i can do it? i was trying change it with code "refLabel.text = "Droop audio clips here" and it not works".

    -I test this option, can work if remove the label style for the text "None (audioClip)" and then i add a new label with code, if this work, i tell to you :D.

    -Exactly, i try a lot of combinations for get some similiar field how ObjectField, but i find nothing :(, is posible how a future request doing this function some how "DropField"?.

    i will wait for your response.

    Thanks for your time, save you, i wish a nice day for you.
     
  6. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    780
    The accepted way to address specific elements is to use class selector in USS or C# to query them. If you look in the debugger, you'll see these really long classnames with are meant to address specific subelements in our controls, like
    unity-object-field-display__label
    .



    Controls usually have constants to help usage with UQuery, for example :
    objectField.Q<Label>(className: ObjectField.labelUssClassName)


    I can't tell if we'll every expose everything needed to re-create an ObjectField (it's not really something we're looking after in our team), but the drag and drop functionality should work as expected with DragPerformEvents.
     
  7. yackson-cc

    yackson-cc

    Joined:
    May 14, 2016
    Posts:
    48
    thanks!!!! it explanation works perfectly, now mi object field looks how i was wanted