![]() ![]() ![]() We can directly add a child element to the root – but if we do that it’ll keep adding new ones every time you refresh or close/open the window: UIToolkit will then persist it until it’s closed/destroyed/re-compiled. Unlike Unity’s oldest GUI system (IMGUI) which lays the GUI out immediately, and unlike Unity’s current GUI system (UnityUI) which lays the GUI out in the editor, we normally layout UIToolkit inside OnEnable: every time the EditorWindow is re-displayed/re-loaded/closed-and-opened-again, we’ll auto-recreate the GUI. This way we can embed our sub-container inside other GUI’s and know it will work without any code changes. To do that, we’ll have our GUI immediately create a dedicated sub-container, and only alter the sub-container. For simple cases you might think: “I don’t care”, but you stand to lose one of the super powerful features of UIToolkit: write a GUI once, then re-use it in different parts of your app/game/editor. However, that’s bad practice: it’s like making all the variables in your game “global”. ![]() …and we can immediately start adding things to that, changing its layout, etc. Unity gives us one in the built-in EditorWindow property “rootVisualElement”. Our first challenge is: we need a container to embed things into (recall from Part 1 that CSS Flexbox always requires things to be embedded in / parented to an existing UI item). EditorWindow: Creating/finding a Root container For this example we’ll start with an EditorWindow, scroll down to see examples of Custom Inspector etc. Now we’ll build a super-simple example UI using pure code (no external files!).Įach place that you want to use UIToolkit works slightly differently, and requires slightly different setup. UIToolkit UI’s have to be embedded in something, and make heavy use of the Q method.Everything in UIToolkit is laid-out using CSS Flexbox (which also exists for the more mainstream UnityUI system, if you get the Flexbox4Unity add-on linked on this site).You can create UIToolkit UI’s entirely in code, with no CSS files, no extra documents, everything in one place: easy to write, easy to maintain, simple and efficient. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |