Unity2017.1官方UGUI文档翻译——Canvas

Canvas

画布

The Canvas is the area that all UI elements should be inside. The Canvas is a Game Object with a Canvas component on it, and all UI elements must be children of such a Canvas.

Creating a new UI element, such as an Image using the menu GameObject > UI > Image, automatically creates a Canvas, if there isn’t already a Canvas in the scene. The UI element is created as a child to this Canvas.

The Canvas area is shown as a rectangle in the Scene View. This makes it easy to position UI elements without needing to have the Game View visible at all times.

Canvas uses the EventSystem object to help the Messaging System.

Canvas是一块区域,所有的UI元素都应该在里面。Canvas就是一个GameObject挂载了一个Canvas组件,所有的UI元素都必须是Canvas的子节点。

如果场景中不存在Canvas,创建一个新的UI元素,例如从GameObject > UI > Image创建一个Image,会自动创建一个Canvas。创建的UI元素会成为这个Canvas的子节点。

Canvas区域在视图场景中显示为一个矩形。这样不需要通过Game视图也可以很容易地摆放UI元素。

Canvas 使用EventSystem对象来帮助消息系统

Draw order of elements

元素的绘制顺序

UI elements in the Canvas are drawn in the same order they appear in the Hierarchy. The first child is drawn first, the second child next, and so on. If two UI elements overlap, the later one will appear on top of the earlier one.

To change which element appear on top of other elements, simply reorder the elements in the Hierarchy by dragging them. The order can also be controlled from scripting by using these methods on the Transform component: SetAsFirstSibling, SetAsLastSibling, and SetSiblingIndex.

Canvas中UI元素的绘制顺序与其在Hierachy中的顺序相同。第一个元素先绘制,然后第二个,依次绘制。如果2个元素重叠了,后面绘制的会显示在先绘制的上面。

通过简单地拖拽Hierarchy中的元素,可以改变元素的绘制顺序。想要用代码改变元素的顺序,可以使用Transform组件中的SetAsFirstSibling、SetAsLastSibling、SetSiblingIndex方法。

Render Modes

渲染模式

The Canvas has a Render Mode setting which can be used to make it render in screen space or world space.

Canvas可以设置渲染模式,让他渲染在屏幕空间或者世界空间

Screen Space - Overlay

屏幕空间--覆盖

This render mode places UI elements on the screen rendered on top of the scene. If the screen is resized or changes resolution, the Canvas will automatically change size to match this.

这种渲染模式把UI放在场景的上方。如果屏幕调整大小或者改变分辨率,Canvas会自动改变它的大小来匹配(意思也就是Canvas的大小永远和屏幕一样大)

UI in screen space overlay canvas

Screen Space - Camera

屏幕空间--相机

This is similar to Screen Space - Overlay, but in this render mode the Canvas is placed a given distance in front of a specified Camera. The UI elements are rendered by this camera, which means that the Camera settings affect the appearance of the UI. If the Camera is set to Perspective, the UI elements will be rendered with perspective, and the amount of perspective distortion can be controlled by the Camera Field of View. If the screen is resized, changes resolution, or the camera frustum changes, the Canvas will automatically change size to match as well.

这个模式和前面的覆盖模式很像,不过在这种渲染模式下,Canvas放在一个指定相机的固定距离前。UI元素被相机渲染,这意味着相机的设置会影响到UI的表现。如果相机设置为透视的,UI元素会被透视渲染,透视变形的程度可以被相机的视野控制。如果屏幕调整大小或分辨率或者改变相机的视锥体,Canvas会自动改变大小去匹配

UI in screen space camera canvas

World Space

世界空间

In this render mode, the Canvas will behave as any other object in the scene. The size of the Canvas can be set manually using its Rect Transform, and UI elements will render in front of or behind other objects in the scene based on 3D placement. This is useful for UIs that are meant to be a part of the world. This is also known as a “diegetic interface”.

在这种渲染模式下,Canvas会像场景中的其他物体一样。Canvas的尺寸可以在RectTransform中手动设置,根据3D空间中的位置,UI元素会渲染在其他物体的前面或后面。这对属于世界的一部分的UI很有用。这个也被称为“剧情界面“

UI in world space canvas

时间: 2024-10-11 21:29:13

Unity2017.1官方UGUI文档翻译——Canvas的相关文章

Unity2017.1官方UGUI文档翻译——Canvas Scaler

Canvas Scaler 画布缩放器 The Canvas Scaler component is used for controlling the overall scale and pixel density of UI elements in the Canvas. This scaling affects everything under the Canvas, including font sizes and image borders. “画布缩放器”组件用于控制画布中UI元素的整

Unity2017.1官方UGUI文档翻译——Position as UV1

Position as UV1 This adds a simple Position as UV1 effect to text and image graphics. 把Canvas空间下的顶点坐标设置到UV1中,用于在Text和Image这样的图形组件中实现一些特效(特效要自定义shader实现) Properties 属性 原文地址:https://www.cnblogs.com/SolarWings/p/8182972.html

Unity2017.1官方UGUI文档翻译——Dropdown

Dropdown 下拉菜单 The Dropdown can be used to let the user choose a single option from a list of options. Dropdown可以让用户从一个列表的选项中选出一个选项. The control shows the currently chosen option. Once clicked, it opens up the list of options so a new option can be ch

Unity2017.1官方UGUI文档翻译——Interaction Components

Interaction Components 交互组件 This section covers components in the UI system that handles interaction, such as mouse or touch events and interaction using a keyboard or controller. The interaction components are not visible on their own, and must be c

Unity2017.1官方UGUI文档翻译——Animation Integration

Animation Integration 动画集成 Animation allows for each transition between control states to be fully animated using Unity’s animation system. This is the most powerful of the transition modes due the the number of properties that can be animated simult

Unity2017.1官方UGUI文档翻译——Rich Text

Rich Text 富文本 The text for UI elements and text meshes can incorporate multiple font styles and sizes. Rich text is supported both for the UI System and the legacy GUI system. The Text, GUIStyle, GUIText and TextMesh classes have a Rich Text setting

Unity2017.1官方UGUI文档翻译——Text

Text 文本 The Text control displays a non-interactive piece of text to the user. This can be used to provide captions or labels for other GUI controls or to display instructions or other text. 文本控件向用户显示一个非交互式的文本片段. 它可以作为其他GUI控件提供标题或标签,或作为说明文本,或者其他用途. P

Unity2017.1官方UGUI文档翻译——Raw Image

Raw Image 原生图片 The Raw Image control displays a non-interactive image to the user. This can be used for decoration, icons, etc, and the image can also be changed from a script to reflect changes in other controls. The control is similar to the Image 

Unity2017.1官方UGUI文档翻译——Mask

Mask 遮罩 A Mask is not a visible UI control but rather a way to modify the appearance of a control’s child elements. The mask restricts (ie, “masks”) the child elements to the shape of the parent. So, if the child is larger than the parent then only t