Search Unity

Examples of using UIElements for scene view

Discussion in 'UI Toolkit' started by taylank, May 24, 2019.

  1. taylank

    taylank

    Joined:
    Nov 3, 2012
    Posts:
    182
    Hi,
    I'm just dipping my toes in the new UIElements framework, and I'm looking for examples on how to utilize it for things I would have previously done in OnSceneGUI(). All the examples I can find on UIElements seem to work within their own editor windows. Is drawing to scene view possible at all with UI Elements?
     
  2. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    It's possible but we don't have a solid API around it. You basically get a reference to the Scene window and from that you get a reference to its rootVisualElement (all EditorWindows have one). With the root element, you can now add any VisualElements you want. The catch is that you are in full control and have to do all the cleanup yourself. It's not as slick as OnSceneGUI(). Proper OnSceneGUI() equivalency will come later.
     
    Lahcene likes this.
  3. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    547
    Any news since?
     
    Prodigga likes this.
  4. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    The ProBuilder team has been working on extensibility features for the Scene view, with full support for UI Toolkit. There's nothing public yet to point to but you could follow the World Building forum or the @ProBuilder3D twitter account for updates.
     
  5. AtomsInTheVoid

    AtomsInTheVoid

    Joined:
    Jul 27, 2015
    Posts:
    251
    What does this really mean? What cleanup would I be responsible for? I'm tempted...
     
  6. uMathieu

    uMathieu

    Unity Technologies

    Joined:
    Jun 6, 2017
    Posts:
    398
    What uDamanian meant was that any change you make to the SceneView's visual tree will be permanent, ie: you will be responsible to remove your elements once you component is deselected.
     
  7. AtomsInTheVoid

    AtomsInTheVoid

    Joined:
    Jul 27, 2015
    Posts:
    251
    That's fine, I was experimenting pretty heavy with it and got some cool results, but ultimately I might have to abandon the idea because of a funny little issue.

    Say I have an element that calculates it's size based on the dimensions of the Scene View window, like Screen.width / 2. This 'works' but, now if you resize the window, it'll update itself but flicker as it recalcs. The reason being is because the window resize action happens first, and the recalculation only happens as I release the mouse on the resize. If there was a way to inject the logic of resizing before repaint then I think it would just update itself smoothly. I believe Update() in Monobehavior during Playmode always runs it's logic before painting the frame, but as far as I know nothing with that kind of "OnBeforeRepaint()" exists for Editor scripts. Perhaps I'm wrong?
     
  8. uMathieu

    uMathieu

    Unity Technologies

    Joined:
    Jun 6, 2017
    Posts:
    398
    Maybe you can hook on the resize notification:
    sceneView.rootVisualElement.RegisterCallback<GeometryChangedEvent>((evt)=> DebugLog("Size: + evt.newRect ))
     
  9. AtomsInTheVoid

    AtomsInTheVoid

    Joined:
    Jul 27, 2015
    Posts:
    251
    Interesting.. I'll give that a go sometime