UGUI Canvas使用心得
来源:未知 浏览量: 发布时间:2015-08-25 11:29
RectTransform:
Unity UI 系统使用 RectTransform 实现基本的布局和层次控制。RectTransform 继承于 Transform,所以 Transform 的所有特征 RectTransform 同样拥有。在 Transform 基础上,RectTransform 增加了 轴心(pivot)、锚点(实际上是用 anchorMin、anchorMax 两个点定义的矩形区域)、和 尺寸变化量(sizeDelta)。
UI Unity system uses RectTransform to achieve the basic layout and level control.
RectTransform is inherited from Transform, so all of the Transform's features are also owned
by RectTransform. On the transform basis. RectTransform increase the axial (pivot), anchor
(is actually with anchorMin, anchorMax two points defining the rectangular area), and size
change amount (sizeDelta).
轴心:表示UI元素的中心,使用相对于自身矩形范围的百分比表示的点位置,这会影响定位、缩放和旋转。
Axis: the center of the UI element, which is expressed by the percentage of the rectangular
range of its own, which affects the position, scale, and rotation.
锚点:相对于父级矩形的子矩形区域,这个矩形各个边界值使用百分比表示。
Anchor: relative to the parent sub rectangle rectangle, the rectangle using the percentage
of each boundary value.
尺寸变化量:相对锚点定义的子矩形大小偏移量,与锚点定义的子矩形合并后的区域才是最终的UI矩形。
Size variation: relative anchor definitions of rectangular offset size, and anchor definitions
of rectangular sub merged region is the final UI rectangular.
在 Inspector 界面上,为了更方便的调节 RectTransform 的属性,锚点的两个点重合时会显示位置和宽高(直接调节位置和sizeDelta),否则显示相对锚点矩形边界的偏移量(通过计算后再赋值给位置和sizeDelta)。在程序中,RectTransform 添加了 anchoredPosition 等属性来更方便的编程。
In the inspector interface, to attributes regulating RectTransform more convenient,
anchor two points of coincidence will display position and width and height (directly adjust the
position and sizeDelta) otherwise relatively anchor the rectangle boundary offset (by calculation
and assignment to the location and sizeDelta). In the program, RectTransform added the
anchoredPosition and other attributes to more convenient programming.
RectTransform 组件同样负责组织 GameObject 的层级关系。在 UI 系统中,子级 UI 对象总是覆盖显示在父级 UI 对象上;层级相同的 UI 对象,下方的 UI 对象总是覆盖显示在上方的 UI 对象上。这样的设计避免了繁琐的深度设置。在程序中,Transform 添加了 SetSiblingIndex、GetSiblingIndex、SetAsFirstSibling、SetAsLastSibling 这些方法来方便的修改物体的层级顺序。
RectTransform component is also responsible for the organization of the level of GameObject.
In the UI system, the sub level UI object is always shown to display the UI object at the parent level;
the level of the same UI object, the UI object below the object is always shown above the UI object.
This design avoids the tedious depth settings. In the program, Transform added SetSiblingIndex,
GetSiblingIndex, SetAsLastSibling, SetAsFirstSibling these methods to facilitate the change of
the order of the object.
EventSystem:
如果你使用 UI 系统,那么 EventSystem 对象会自动创建。这个对象负责监听用户输入。默认情况下,在电脑上可以使用键盘和鼠标输入,在移动设备上可以使用触摸输入。但是如果你要为surface这样的设备开发,你也可以同时启用两种输入。当需要屏蔽用户输入时,将此对象关闭即可。UnityEngine.EventSystems.EventSystem.current 可以获得当前活动的 EventSystem 对象。
If you use the UI system, the EventSystem object will be created automatically. This object is
responsible for monitoring user input. By default, you can use the keyboard and mouse input on
the computer, and you can use the touch input on the mobile device. But if you want to develop a
device for surface, you can also enable two inputs. When the user input is required, the object can
be closed. UnityEngine.EventSystems.EventSystem.current can get the EventSystem object of the
current activity.
Canvas:
Canvas 是其他所有 UI 对象的根。在一个场景里 Canvas 数量和层级都没有限制。子 Canvas 使用与父 Canvas 相同的渲染模式。一个 Canvas 有三种模式:
Canvas is the root of all other UI objects. There is no limit to the number and level of Canvas in
a scene. Child Canvas uses the same rendering mode as the parent Canvas. One Canvas has
three modes:
Screen Space - Overlay:UI元素相对于屏幕空间,以2D方式显示在任何相机画面的上面。这是非常标准的 UI 风格。典型例子:大量窗口、文本和按钮的策略游戏。
Space Overlay:UI Screen element relative to the screen space, the 2D display in any of the
camera screen. This is a very standard UI style. Typical example: a large number of window, text
and button strategy game.
Screen Space - Camera:UI元素相对于屏幕空间,由指定的相机负责显示,相机的参数影响显示的结果。你可以把 Canvas 理解为相机的子物体。典型例子:射击游戏屏幕上的 3D HUD。
Space Screen Camera:UI element with respect to the screen space, the camera'sparameters
affect the results displayed by the specified camera. You can understand the Canvas as the object
of the camera. Typical example: shooting game screen on the HUD 3D.
World Space:UI元素相对于世界空间,和其他场景里的物体一样有世界位置、遮挡关系。通常用来做非常创新的 UI 设计。例子:游戏内的手机屏幕、融合场景的游戏指导等。
The Space:UI World element has the world position and the occlusion relationship with the world space, and other objects in the scene. It is usually used to make very innovative UI designs.
Example: the game's mobile phone screen, the integration of the scene of the game guide, etc.