This article or section is a Stub. You can help the Neos Wiki by expanding it.
UIX is Neos's UI system. It allows you to create two-dimensional user interfaces, and is conceptually similar to the Unity UI system. It underpins the Dash Menu and Scene Inspector.
A useful UIX demo, UIX Canvas, can be spawned with the Developer Tooltip, found under the Objects category. It provides examples of layouts, images, buttons, and sliders.
A UI requires a Canvas at its root. The Canvas defines the size of the UI.
Every slot involved in a UI must have a RectTransform on it. RectTransforms are automatically added when you attach other UI components. The RectTransform determines the boundaries of that UI element, expressed as a fraction of the total space available -- so a default RectTransform has anchors at 0,0 and 1,1.
Whilst you can manually position elements by adjusting their RectTransforms, you often want this to be handled automatically. A layout overrides the RectTransforms of its slot's children. For example, the HorizontalLayout will try to position its children in a horizontal line.
WARNING: Layouts calculate the positions and sizes of their children based on the children themselves. If you modify or add or delete a child and don't get the expected result, you may need to force recalculation. The only way to do this currently is to duplicate your entire object (or maybe just the layout?) and delete the original.
Since layouts depend on the order of their children, and you can't drag children around in the inspector, you must specify a child's OrderOffset property. Normally these are 0, but if you change it, the children will be ordered by increasing OrderOffset, with children of equal OrderOffset being ordered by some effectively random process.
Again, if you change the OrderOffset of a child, your layout will have to be recalculated, which may run into the above warning.
To actually display things, your UI needs one or more Graphics components. Image will fill the element, optionally taking a material (to define its appearance) and sprite (to define its shape). Other elements include Text, to display text, and Mask, to hide parts of child UI elements.
Interaction components allow for input. Button will respond visibly to hovering and pressing, and will trigger other components on the slot (as well as on child slots). Slider works similarly, but can also control a child element's RectTransform to move it around.
- Using the Developer Tooltip, Create New > Empty Object.
- In that object, Attach Component > UIX > Canvas.
- Change the Scale of the object to 0.001 on all axes to get the object to be a more reasonable size.
- You can then change the Canvas's Size x and y (in pixels) to your liking.
- Next, on the same empty object, Attach Component > UIX > Graphics > Image. You can change the image's Tint to change the base color of the canvas.
- Again using the Developer Tooltip, Create New > Materials > UI > UI Unlit.
- Change the material's ZWrite property to On, and the OffsetFactor and OffsetUnits properties to 1.
- Grab the material ball and click on your empty object's Image Material slot to load it in. This fixes the "bleed-through" effect which would cause different UIX objects to bleed through each other if placed on top of each other.
- You may also want to make the canvas grabbable (Attach Component > Transform > Interaction > Grabbable).
You can now add children to be displayed on the canvas.
ProbablePrime's public folder, under Tutorials > UIX, contains a CanvasTemplate which has already done all the above steps for you. Simply spawn one out and start from there.
- Add a child to your canvas (or layout or whatever) and call it Button.
- In that object, Attach Component > UIX > Graphics > Image. You can change the image's Tint to change the base color of the button.
- Change the RectTransform's AnchorMin/Max to add a border around the button. This effectively tells the parent where the child is and how to scale it.
- AnchorMin (x,y) is the lower left corner of a rectangle on the parent canvas that the child should be fit into, ranging from 0 to 1. (0,0) is the lower left of the parent.
- AnchorMax (x,y) is the upper right corner of a rectangle on the parent canvas that the child should be fit into, ranging from 0 to 1. (1,1) is the upper right of the parent.
- Adding a small border of, say, 5% of the parent's size, means the AnchorMin should be (0.05,0.05) (i.e. 0,0 plus 5%) and AnchorMax should be (0.95,0.95) (i.e. 1,1 minus 5%).
- Attach Component > UIX > Interaction > Button. Based on the image's Tint, the button will automatically fill out the colors for its normal, highlight, press, and disabled states.
- You may add text to the button:
- Create a child object of the button and call it Text.
- On that child, Attach Component > UIX > Graphics > Text.
- Change the text to what you want.
- Alter the font size, set up autosize, change the alignment to what you want.
- You can hook the button up to LogiX by creating a Button Events node, dragging out the Button interface card, and hooking it up to the Button Events node.
You can also put an icon on a button.
- On the Button object, Attach Component > Assets > SpriteProvider.
- Drop your chosen image into the Texture property of the SpriteProvider.
- Grab the SpriteProvider and drop it into the Sprite property of the Button's Image.
- Use the Tint property on the Image to color the icon.
- You can parent the Button to another object with an Image to set the background.
ProbablePrime's public folder, under UI Stuff > Icons > Shapes, has many icons for your use.
- Add a child to your canvas (or layout or whatever) and call it Mask.
- In that object, Attach Component > UIX > Mask. This effectively makes any graphical elements from children that wander outside the RectTransform invisible.
- In the same object, Attach Component > UIX > Graphics > Image.
- Turn on the Mask's ShowMaskGraphic property.
- Add a child to the Mask object and call it ScrollRect.
- In that object, Attach Component > UIX > Interaction > ScrollRect.
- In the same object, Attach Component > UIX > Layout > ContentSizeFitter.
- Set the ContentSizeFitter's VerticalFit property to MinSize.
- In the same object, Attach Component > UIX > Layout > VerticalLayout.
- Add a child to the ScrollRect object and call it Content.
- In that object, Attach Component > UIX > Graphics > Text.
- Change the text to what you want. Typically for long text that you get from a file, you would import a text file from your computer, inspect the result, navigate to the text component (object > ScrollRect > Content), and grab and drag the Text component's Content property into your object's Text Content.
- Alter the font size, set up autosize, change the alignment to what you want.
- Change the font color to something that will show up against the mask image color!
A simple vertical layout
- Add a child to your canvas (or layout or whatever) and call it Layout.
- In that object, Attach Component > UIX > Graphics > Image. Set the Tint to something that will differentiate this object from child objects.
- Also in that object, Attach Component > UIX > Layout > VerticalLayout.
- Change all the Padding and the Spacing properties on the VerticalLayout to 4.
- Add a child of Layout, and call it Element.
- In that object, Attach Component > UIX > Graphics > Image. Set the Tint to something that will differentiate this object from the layout object.
- Duplicate this object a few times. They will all be children of Layout.
- You may need to heed the warning above, and duplicate the canvas to get the layout to recalculate.
- You can add LayoutElement to each Element. This tells the parent layout how to calculate widths and heights.
ProbablePrime's series on UIX:
- Canvases and rectangles
- Materials, buttons, and text
- Text scrolling
- Images & sprites
- Masking images & nine slices
- Progress bars
- Text fields
- Common UI interactions & UIX
- AxisMultiViewportScanner for sliding forms or UI
- Creating a facet