Unity4.6.1 UGUI之Canvas学习笔记

本文是Unity4.6.1中UGUI Canvas的学习笔记,介绍了Canvas作为UI元素容器的性质,以及Canvas的绘制次序与渲染模式。Canvas的绘制顺序遵循Hierarchy中的顺序,可以通过调整子元素顺序或使用Transform组件方法改变。渲染模式包括Screen Space - Overlay(屏幕空间-覆盖,自动适应屏幕大小),Screen Space - Camera(基于特定Camera的屏幕空间渲染,受Camera影响)和World Space(世界空间渲染,UI元素随3D场景交互)。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Canvas(画板)

The Canvas is the area for all UI elements to 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.(Canvas是所有UI元素的父节点)

When you create a new UI element, such as an Image using the menu GameObject > UI > Image, a Canvas is automatically created too, if there isn’t already a Canvas in the scene. The UI element is created as a child to this Canvas.(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在场景里是一个矩形区域,很容易定位UI元素)

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.(渲染次序按照Hierarchy里的顺序来排,如果两UI元素重叠,新的覆盖旧的上面)

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.(渲染次序有两种方式设置,一种是在Hierarchy里排序,第二种在脚本里调用SetAsFirstSibling、SetAsLastSibling、SetSiblingIndex设置Transfrom组件)

Render Modes(渲染模式)

The Canvas has a Render Mode setting which can be used to make it render in screen space or world space.(设置渲染模式,屏幕or世界)

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 as well.(Screen Space-overlay模式把UI元素摆在屏幕上,位于场景最上,自动适配屏幕的缩放)

UI in screen space overlay canvasUI 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 or changes resolution, or the camera frustrum changes, the Canvas will automatically change size to match as well.(与Screen Space-Overlap类似,Canvas被设置在一个指定Camera前面设定的一段位置上。UI元素被指定的Camera渲染,被Camera的设置影响。例:Camera设置为透视投影,UI元素按照透视渲染,透视变形的程度由Camera的视界控制。如果屏幕尺寸和像素变化,或者Camera的视椎体变化,会自适应。

UI in screen space camera canvasUI in screen space camera canvas

World Space

This render mode makes the Canvas 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, also sometimes referred to as diegetic interfaces.(这种模式使得Canvas像场景中的任何一个Object,Canvas的Rect Transform和UI元素任意放置取决于在3D场景中的位置。)

UI in world space canvasUI in world space canvas
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值