unity3d画布切换_了解Unity 3D画布

unity3d画布切换

The Canvas in Unity isn't a big painting board on a wooden frame. The Canvas is actually an area in the game where you can draw UI elements.

Unity中的画布不是木制框架上的大画板。 画布实际上是游戏中可以绘制UI元素的区域。

What are UI elements? UI elements are simply elements in the game (and most often, on the screen) that relay useful information to the player. These are usually persistent in their presence. One of the best examples of a UI element is a score counter, or a health meter etc.

什么是UI元素? UI元素只是游戏中(通常是屏幕上)的元素,可以将有用的信息传递给玩家。 这些通常在它们存在时是持久的。 UI元素的最佳示例之一是得分计数器或健康状况表等。

Unity Game Canvas

Unity 3D画布和UI元素 (Unity 3D Canvas and UI Elements)

UI elements are what form Pause menus, Main menus, HUDs or Heads-Up Displays, Score counters and so on. In this tutorial, we'll discuss a bit about how the Canvas works, and in the next tutorial, we'll get on with adding our own UI elements into our game.

UI元素是“ 暂停”菜单 ,“ 主菜单” ,“ HUD”或“ 抬头显示” ,“计分计数器”等形式。 在本教程中,我们将讨论Canvas的工作原理,在下一个教程中,我们将继续在游戏中添加自己的UI元素。

So far, the only thing we have said about it is that it's a big rectangular space in the game. In Unity, the Canvas is also a Game Object with a Canvas component attached to it. This Canvas component acts as the master of all UI elements on the screen. That's why all UI elements are required to be the child gameObject of the Canvas gameObject.

到目前为止,我们唯一谈到的是游戏中很大的矩形空间。 在Unity中,画布也是一个附加有画布组件的游戏对象。 此帆布组件作为屏幕上的所有UI元素的主人 。 这就是为什么所有UI元素都必须是Canvas gameObject的子gameObject的原因。

Canvas example with UI elements

Unity 3D Canvas:Canvas组件属性 (Unity 3D Canvas: Canvas Component Properties)

Let's have a look at the Canvas component.

让我们看一下Canvas组件。

Canvas properties in Inspector view

NOTE: We shrunk the Graphic Raycaster component because it's not as important to us as the other two for now.

注意:我们缩小了Graphic Raycaster组件,因为它对我们来说不如目前其他两个重要。

The first segment in the Canvas's scripting is the Canvas itself. It has properties which change where and how the Canvas is rendered on screen. The second segment, the Canvas Scaler, is used to set the size and scaling of UI elements according to different screen sizes.

Canvas脚本中的第一部分是Canvas本身。 它具有更改画布在屏幕上的显示位置和方式的属性。 第二部分是Canvas Scaler ,用于根据不同的屏幕尺寸设置UI元素的尺寸和缩放比例。

In the Canvas script, our most significant property is the Render Mode.

在Canvas脚本中,我们最重要的属性是Render Mode

Canvas component properties

The three modes in Render Mode determine the way the Canvas is treated and rendered in the game. Let's explore these options further to understand them better.

渲染模式中的三种模式决定了画布在游戏中的处理和渲染方式。 让我们进一步探索这些选项,以更好地理解它们。

Unity 3D画布:屏幕空间-覆盖 (Unity 3D Canvas: Screen Space - Overlay)

This render mode places UI elements at the top of the screen of the scene rendered. It's what you'll be using most of the time when you're making an HUD or any similar, static UI element. It's quite useful because it automatically scales UI elements in that Canvas to the required size as per the screen's size.

此渲染模式将UI元素放置在渲染场景的屏幕顶部。 制作HUD或任何类似的静态UI元素时,大多数时候都会使用它。 这非常有用,因为它会根据屏幕尺寸自动将Canvas中的UI元素缩放到所需的尺寸。

Unity 3D画布:屏幕空间 (Unity 3D Canvas: Screen Space)

This is quite similar to how the Overlay mode works, but in this mode, we specify a camera which renders our UI. As such, changing properties in the camera like its shape, size, area of coverage or resolution will change the way the UI looks on the screen. Developers don't usually use this option, as they find Overlay to be of better use because of its ability to auto-scale UI elements.

这与“ 覆盖”模式的工作原理非常相似,但是在此模式下,我们指定了一个渲染UI的摄像头。 因此,更改相机的属性(例如其形状,大小,覆盖范围或分辨率)将更改UI在屏幕上的显示方式。 开发人员通常不使用此选项,因为他们发现Overlay具有更好的用途,因为它可以自动缩放UI元素。

Unity 3D画布:世界空间 (Unity 3D Canvas: World Space)

This mode is quite different from the other two. In World Space, UI elements are treated simply as another gameObject in the scene instead of having priority rendering on top. World Space is very useful when dealing with UI elements that are part of the game itself, and not simply for the player.

此模式与其他两种模式完全不同。 在世界空间中,UI元素被简单地视为场景中的另一个游戏对象,而不是在顶部具有优先级渲染。 当处理属于游戏本身的UI元素时,World Space非常有用,而不仅仅是针对玩家。

The Canvas

翻译自: https://www.studytonight.com/game-development-in-2D/the-canvas

unity3d画布切换

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页