Categories: All - unity - position

by Mike Ton 10 years ago

533

UnityGUI

In Unity, the Canvas forms an essential part of the user interface, where the Rect Transform property is fundamental in defining the position and size of UI elements. Unlike the standard Transform, the Rect Transform deals with both local and global coordinates, providing a pivot point centered by default and allowing for the adjustment of anchors relative to a parent Rect Transform.

UnityGUI

Unity:GUI

EventSystem

EventTrigger
custom function

must

0 or 1 param

Unity Object ref

MonoBehaviour

GameObject

string

int

float

return void

public

(script)
Touch Input Module
Standalone Input Module

Allow Activation on Mobile Device

Input Actions Per Second

10

(io)

Button

Cancel

Submit

Axis

FirstSelected

(defaultUI element)

Unity

Scene (Hiearchy)
MainCamera
Canvas

(prop)

Anchor Point

4

relative size

average %

1

single

Rect Transform

Rect Tool (t)

used to move all UI elements

rotate

click out side corners

SHIFT : snaps 15 degrees

drag

Click corners and side to rescale

SHIFT : maintain proportions

different from transform :

(local vs. global)

global bounding box is world aligned

local bounding box is axis aligned

(pivot point)

defaults to center of UI element

(anchor)

(only if world space)

scale

rotation

xyz

Pivot

Anchors

max

min

x & y

size : width & height

position : xyz

Position values are relative to anchor point

z is usually zero

if parent has rect transform, anchor can be a child of that

RenderMode

World Space

when set to world space, Rect Transform becomes available.

You can rotate and position canvas as desired

Screen Space

(Will overrideRect Component)

Rect uneditable in this mode

Camera

(attached to a specific camera)

use camera specific settings; fits to frustrum

UI can be seen in all cameras

Clear depth, background ...etc in cameras you don't want to see UI

perspective camera to give UI feeling of depth

Overlay

(default)

overlays all other element, UI drawn on top of everything

(children)

MUST have 1 available canvas to use UI element. Possible to have multiple canvas per scene.

All UI Elements must be children of a canvas.

UI Element

Image

Fill Center

bool

Type

Filled

Preserve Aspect

Fill

Amount

0 ... 1.0

Origin

Right

Left

Method

Radial

360

180

90

Vertical

Horizontal

Tiled

Sliced

9-Slice

Simple

(dispData)

Material

Color

Source

(render order)

top down

top items rendered firs, lower items rendered on top