Canvas 画布组件(官网翻译)
Canvas
畫布
TheCanvasis 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.
Canvas是一個(gè)應(yīng)該包含所有UI元素的區(qū)域。畫布是一個(gè)帶有畫布組件的游戲物體,并且所有的UI元素都應(yīng)該是這個(gè)畫布的子物體。
Creating a new UI element, such as an Image using the menuGameObject > 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.
創(chuàng)建一個(gè)UI元素,比如一個(gè)圖片,使用路徑GameObject > UI > Image,如果當(dāng)前場景沒有畫布的時(shí)候就會(huì)自動(dòng)創(chuàng)建一個(gè)畫布。UI元素作為這個(gè)畫布的子物體被創(chuàng)建。
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.
畫布區(qū)域在場景視圖中顯示為一個(gè)矩形。這使得不用一直開啟游戲視圖就可以簡單的放置UI元素。
Canvasuses the EventSystem object to help the Messaging System.
Canvas使用事件系統(tǒng)物體來實(shí)現(xiàn)信息系統(tǒng)。
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元素在畫布的渲染順序和他們顯示在層級視圖的順序一致。第一個(gè)子物體第一個(gè)渲染,第二個(gè)子物體下一個(gè)渲染,以此類推。如果兩個(gè)UI元素有交疊,后渲染的那個(gè)將會(huì)顯示在先渲染的那個(gè)的上面。
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.
改變哪個(gè)元素顯示在其他元素的上方,簡單的拖拽改變元素在層級視圖中的順序。這個(gè)順序也可以通過使用這些Transform組件在腳本中控制:SetAsFirstSibling, SetAsLastSibling, 和SetSiblingIndex。
Render Modes
渲染模式
The Canvas has aRender Modesetting which can be used to make it render in screen space or world space.
畫布有一個(gè)Render Mode設(shè)置,這個(gè)設(shè)置可以用來使它渲染在屏幕空間或世界空間。
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.
這個(gè)渲染模式把UI元素放置屏幕上在場景的最上方。如果屏幕改變大小或者改變方案,這個(gè)畫布將會(huì)自動(dòng)改變尺寸匹配它。
UI in screen space overlay canvas
屏幕空間覆蓋畫布的UI
Screen Space - Camera
屏幕空間——相機(jī)
This is similar toScreen Space - Overlay, but in this render mode, the Canvas is placed a given distance in front of a specifiedCamera. 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 toPerspective, the UI elements will be rendered with perspective, and the amount of perspective distortion can be controlled by the CameraField 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 - Overlay很像,但是在這個(gè)模式下,畫布被放置在離特定的相機(jī)給定的距離。UI元素通過這個(gè)相機(jī)渲染,也就意味著相機(jī)設(shè)置影響UI的表現(xiàn)。如果相機(jī)被設(shè)置為Perspective,UI元素將被渲染為透視,并且透視失真的量可以由相機(jī)的Field of View控制。如果屏幕改變大小或者改變方案,或者相機(jī)frustrum改變,這個(gè)畫布將會(huì)自動(dòng)改變尺寸匹配它。
UI in screen space camera canvas
屏幕空間相機(jī)畫布的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”.
在這種渲染模式下,畫布將會(huì)像場景中的其它物體一樣。畫布的大小可以用它的Rect Transform手動(dòng)設(shè)置,并且UI元素渲染在其他物體的前面或者后面將基于3D放置位置決定。這對UI來說意味著是世界的一部分。這經(jīng)常被用來做一個(gè)“敘述界面”。
UI in world space canvas
世界空間畫布的UI
總結(jié)
以上是生活随笔為你收集整理的Canvas 画布组件(官网翻译)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 悲伤的网名让人看了想哭的100个
- 下一篇: 李若彤个人简介