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是一個應該包含所有UI元素的區域。畫布是一個帶有畫布組件的游戲物體,并且所有的UI元素都應該是這個畫布的子物體。
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.
創建一個UI元素,比如一個圖片,使用路徑GameObject > UI > Image,如果當前場景沒有畫布的時候就會自動創建一個畫布。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元素。
Canvasuses the EventSystem object to help the Messaging System.
Canvas使用事件系統物體來實現信息系統。
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.
改變哪個元素顯示在其他元素的上方,簡單的拖拽改變元素在層級視圖中的順序。這個順序也可以通過使用這些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.
畫布有一個Render Mode設置,這個設置可以用來使它渲染在屏幕空間或世界空間。
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 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很像,但是在這個模式下,畫布被放置在離特定的相機給定的距離。UI元素通過這個相機渲染,也就意味著相機設置影響UI的表現。如果相機被設置為Perspective,UI元素將被渲染為透視,并且透視失真的量可以由相機的Field of View控制。如果屏幕改變大小或者改變方案,或者相機frustrum改變,這個畫布將會自動改變尺寸匹配它。
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”.
在這種渲染模式下,畫布將會像場景中的其它物體一樣。畫布的大小可以用它的Rect Transform手動設置,并且UI元素渲染在其他物體的前面或者后面將基于3D放置位置決定。這對UI來說意味著是世界的一部分。這經常被用來做一個“敘述界面”。
UI in world space canvas
世界空間畫布的UI
總結
以上是生活随笔為你收集整理的Canvas 画布组件(官网翻译)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 悲伤的网名让人看了想哭的100个
- 下一篇: 李若彤个人简介