Unity3D说明文档翻译-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.

画布是一个区域,所有UI元素必需放入其中.画布是一个游戏对象,带有一个画布组件,而所有UI元素必须是画布的子对象.

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.

创建一个UI元素,诸如一张图片,使用菜单游戏对象>UI>图片,如果场景内还没有一个画布,将自动创建一个画布.UI元素被创建为此画布的子对象.

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.

画布区域在场景视图显示为一个矩形.这使得它容易定位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.

在画布上的UI元素按它们在层级上的次序绘制在画布上.第一个子对象第一个绘制,接着第二个,以此类推.如果两个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.

要改变哪个元素显示在其他元素上面,只需在层级上通过拖拽它们重新排列元素次序.次序也可以通过脚本使用它们在转换组件上的方法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.

画布有一个渲染模式设置,可用于使它渲染在屏幕空间上或世界空间上.

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元素在屏幕渲染在场景的上面.如果屏幕重置大小或改变分辨率,画布将自动改变大小以匹配它.

UI in screen space overlay canvas

UI在屏幕空间上覆盖模式画布下

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.

这和屏幕空间-覆盖相似,但在此渲染模式,画布被放置在一个特定摄像机前给定的距离上.UI元素通过此摄像机渲染,意味着摄像机设置影响着UI的外观.如果摄像机设置为视角模式,UI元素将被渲染为视角,视角变形程度可同过摄像机视野属性设置.如果屏幕重置大小或改变分辨率,或者摄像机的视锥改变,画布也将同样自动改变大小来匹配.

UI in screen space camera canvas

UI在屏幕空间相机模式画布下

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”.

在此渲染模式,画布将对场景内任何其他对象起作用.画布大小可手动使用它的矩形转换组件设置,且UI元素在场景内按3D位置将渲染在其他对象的前面或后面.这很有用,意味着UI可作为世界的一部分.这被称为剧情界面.

UI in world space canvas

UI在世界空间模式画布

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值