Placeholder Image

字幕列表 影片播放

  • Cameras.

    本章介紹相機

  • The camera is one of the most

    相機是Unity最重要的元件之一

  • essential components in Unity.

    相機將場景的內容呈現給使用者

  • The camera takes the contents of our scene

    每個場景至少要一台相機來著色場景物件 不然甚麼都秀不出來

  • and displays it to our users.

    當建立一個新場景時 同時也會產生一台相機

  • Every scene must have at least

    這台相機叫主相機(Main camera)

  • one camera to render out scene objects

    遊戲相機是建立在物件裡的元件

  • otherwise we have nothing to show.

    代表我們可以像操縱其他物件一樣操縱它 給予結構、腳本控制或物理

  • When a new scene is created

    要建立第一或第三人稱相機或橫向捲軸 我們可以讓Player物件成為相機的父物件

  • one game object is always created.

    將相機調整到角色眼睛的高度 並往前看可以模擬第一人稱

  • This is the main camera.

    將相機調整到角色的後上方來模擬第三人稱

  • The game view camera is a

    要呈現益智遊戲或俯視射擊遊戲 相機應該是靜止並對著遊戲場景

  • component attached to a game object.

    在範例裡,我們將相機置中 並移除任何不需要的旋轉數值

  • This means we can manipulate, or move our camera

    讓鏡頭由上往下看並抬高點 模擬一個俯視射擊遊戲場景

  • like any other game object,

    這裡我們用正射模式(Orthographic) 後面會解釋這個模式

  • including parenting, scripting,

    一個場景裡可以有很多台相機 每台相機負責著色不同的環境區塊

  • or physical interaction.

    本範例我們有三個相機

  • To create a first or third person camera,

    第一台著色場景的動態物件,第二台 著色靜態背景第三台著色使用者介面

  • including side scrollers,

    三台相機結合在一起就可以 呈現一個完整畫面給玩家

  • we can use the player object as the parent.

    待會我們會討論如何一次使用三台相機

  • For first person cameras, make sure the camera

    當在階層裡點選相機時會看到預覽畫面

  • is at the character's eye height

    當場景有複數相機時我們可以 透過預覽來了解不同相機的內容

  • looking forward from the character's point of view.

    全螢幕編輯時預覽的好處更明顯 就算場景裡只有一台相機

  • For a third person view, make sure the camera is

    相機會呈現它看到的所有東西

  • above and behind the character.

    呈現多少取決於相機前的白色框體

  • For a simple puzzle game or top-down shooter

    這個叫做視錐

  • the camera would be static, simply

    視錐像削去頂部的金字塔或錐體

  • looking at and rendering the game.

    最頂端叫近視切面(Near Clipping Plane) 最底端叫遠視切面(Far Clipping Plane)

  • In this example we are going to centre the camera,

    近端和遠端視切面控制相機的繪製距離

  • remove any unwanted rotation,

    物件必須在遠端和近端中間才會被呈現

  • point it straight down and lift it above

    四邊代表上下左右的可視範圍

  • the game board to simulate a top-down game.

    任何在錐體裡的場景會被著色

  • In this case we are using the orthographic

    相機有透視模式(Perspective) 和正射模式(Orthographic)兩種模式

  • mode on the camera, which we will cover

    這兩種模式影響視錐的形狀和大小 以及相機看到的場景畫面

  • later in this lesson.

    在透視模式下相機如同真實世界的相機 有遞減透視的感覺

  • We can have any number of cameras in our scene.

    可以看到場景裡代表視野的白色視錐 距離相機越遠越大

  • Each rendering different parts of the environment.

    這是普遍製作遊戲用的模式

  • In this example we have three cameras.

    正射模式不會有遞減透視的感覺

  • One rendering all of the dynamic

    所有的物件都是使用 平行投影的方式來呈現

  • objects in the scene. Another rendering

    可以看到場景的視錐是前後一樣寬的長方體

  • the static background and a third

    這個模式通常使用在等距(Isometric)

  • rendering a User Interface overlay.

    像是即時戰略、桌遊或2D遊戲、益智遊戲 或製作遊戲的小地圖或抬頭顯示器介面

  • All three cameras can be brought together to

    要控制場景顯示多少內容 可調整Near和Far屬性改變視錐的形狀大小

  • make a single presentation to our user.

    視野(Field of View)和真實相機的Zoom很像 用來控制相機視野有多廣

  • We will talk about how to properly use all

    當相機使用正射模式時 屬性檢視的Field of View會變成Size

  • three cameras at once later on in this lesson.

    用來控制可視區域的大小

  • When a camera is selected in the hierarchy

    它和視野很像

  • we see a preview of the camera in the scene.

    只是它會同時改變前後視切面的大小 因為正射相機沒有透視概念

  • When we have multiple cameras in the scene

    我們的場景須要一個背景

  • this helps us to see what the camera is rendering.

    可以用Clear Flags和Background來設定

  • This preview is also helpful when we are in

    設定背景的顏色會影響 所有場景物件背後的顏色

  • full screen mode to see what the camera is rendering,

    新建場景預設值是藍色

  • even if it's the only camera in the scene.

    Clear Flags決定顯示背景的方式

  • Cameras will render everything that's in

    這個設定在複數相機時特別重要

  • front of them and within their view.

    每台相機在著色時會儲存顏色和深度資料 如果畫面被認為是空的就不會被呈現出來

  • How much of the scene is within their view

    而Clear Flags屬性決定呈現在背後的是甚麼

  • is shown in the scene view as a white outline.

    如果我們設定一個天空盒(Skybox) 背景就會變成天空盒

  • This shape is a view frustum.

    天空盒是相機預設的選項

  • A view frustum is a pyramid, or cone,

    天空盒是材質的一種,提供場景 一個紋理背景包含環繞場景的圖

  • with the top cut off.

    更多天空盒的細節和使用方式 請參閱相關章節

  • The cut off top of the pyramid is the

    如果我們不是選Skybox或是選了Solid color

  • near clipping plane and the base

    所有物件的背景就會呈現指定的顏色

  • is the far clipping plane.

    Depth Only主要用在多個相機的配合 等一下我們會討論

  • The near and far clipping planes control

    Don't Clear產生的新畫面會蓋在舊畫面上 而製造出一種殘影效果,這功能不太常用

  • the draw distance from the camera.

    Depth only運用在多個相機是很實用的功能

  • Objects must be between the near and far

    透過這個設定相機被賦予深度這個變數

  • clipping planes to be rendered. The sides

    每個相機的內容會依照深度 從最小的開始往上疊

  • indicate how much the camera can see

    通常主相機的深度視應該是最小 而且Clear flag應該是skybox或solid color

  • side to side and top to bottom.

    其他的相機就設為Depth only

  • and any part of the scene that's within

    這樣就有一個最後面的背景 然後其他相機的畫面層層疊在主相機之上

  • the frustum will be rendered.

    相機呈現哪些物件 可以用剔除遮罩(Culling Mask)來限制

  • Cameras have two different ways of

    剔除遮罩下拉選單會列出 場景內圖層(Layer)的清單

  • looking at the scene. Perspective mode

    相機只會顯示有勾選的圖層項目

  • and orthographic mode.

    更多關於圖層和使用方法請參閱相關章節

  • These dramatically effect the shape and

    關於將使用者介面(UI)疊在畫面上的方法

  • size of the frustum and the

    我們將UI物件指定到名為UI的圖層

  • look of the scene through the camera.

    照著UI的相機在遮罩設定只顯示UI圖層

  • In perspective mode the camera will render

    然後設定Clear flag為Depth only 並設定深度設定大於其他相機

  • the scene like a real world camera with

    這樣這台相機將只顯示遮罩指定的UI物件 並依照深度設定顯示在畫面最上面

  • a sense of diminishing perspective.

    還有就是設定相機為正射(Orthographic) 可避免產生UI元件的不需要的透視感

  • We can see this in the scene view as the

    一般這種多相機會用在介面像是 小地圖、遊戲世界抬頭顯示器

  • white representation of the cameras

    模擬後照鏡或遙控導彈的液晶螢幕 或用來強制物件顯示順序

  • frustum gets larger as it extends

    例如讓FPS玩家手上的槍 不會插入到遊戲建築場景內

  • away from the camera.

    其他關於可視區規格化、著色路徑 目標貼圖和高動態範圍(HDR)性能

  • This is the most common camera mode to use

    和更多高階功能會在其他章節介紹

  • when creating a game.

  • In orthographic mode there is no

  • diminishing perspective. All objects are

  • rendered using a form of parallel

  • projection from the camera. We can see this

  • in the scene view as the frustum is straight

  • and the front and back are the same size.

  • This mode is usually seen in isometric

  • games like some real time strategy or

  • board games, or for 2D

  • games, simple puzzle games and when using

  • an additional camera for rendering UI elements

  • on top of the game view, like mini

  • maps or heads-up displays.

  • To control what is being rendered in our

  • scenes, adjust the near and far clipping

  • planes and the size or shape of the frustum.

  • Field Of View controls how wide the view

  • of the camera will be. This is very much

  • like using the zoom on a real world camera.

  • When the camera is in orthographic mode

  • size replaces the field of view property.

  • This controls the size of the

  • orthographic viewport.

  • This is similar to field of view but

  • the value of the size property changes

  • the size of both the front and back planes

  • at the same time as there is no perspective

  • with an orthographic camera.

  • Our scenes must have some sort of a background.

  • This controlled by the Clear Flags and

  • Background properties.

  • The colour values set in the background

  • property will be what's drawn behind any

  • of the objects in our scene, if no other

  • settings have been changed. This is the

  • default blue colour we see in a new empty scene.

  • Clear Flags determines what the background

  • will be for a camera. This setting is particularly

  • important when using multiple cameras.

  • Each camera stores colour and depth information

  • when it renders it's view. The portions of the

  • screen that are not drawn upon are considered empty.

  • The Clear Flags property will determine

  • what is shown in this empty space.

  • If we have a skybox set in our render

  • settings the background will be a skybox.

  • Skybox is the default clear flag for any camera.

  • A skybox is a material that contains

  • several images that surround the entire scene

  • providing a textured background for that scene.

  • For more information on skyboxes and

  • render settings see the appropriate lessons.

  • If we don't have a skybox set, or we choose

  • solid colour as our clear flag.

  • The colour value from the background property

  • will be used behind any of our objects

  • in the scene.

  • Depth Only is primarily used for

  • multiple cameras. We will cover depth only

  • in a moment.

  • Don't Clear will result in each frame

  • being drawn over the last, creating

  • a smear effect. This setting isn't typically

  • used in games.

  • When using multiple cameras the most practical

  • setting for clear flags is depth only.

  • With this setting each camera is given a

  • value and depth and the contents of each

  • camera's view are layered on top of each other

  • in depth order, starting with

  • lowest depth first.

  • Normally the main camera is assigned

  • the lowest depth value

  • and has it's clear flag set to either

  • skybox or solid colour.

  • All of the other cameras have their clear

  • flags set to depth only. This way there is

  • one ultimate background, and the images

  • of all the other cameras are

  • layered on top of the main camera.

  • The content of what the camera is rendering

  • is limited by the Culling Mask property.

  • The Culling Mask drop down will list

  • all the layers available in the scene.

  • The camera will render only those objects

  • on the layers selected in it's culling mask.

  • For more information on layers and how to

  • use then see the appropriate lesson.

  • In the case of the User Interface overlay

  • we have the interface element set to the

  • UI layer. Our UI camera has it's culling mask

  • set to render only the objects on the User Interface layer

  • We have our clear flag set to depth only

  • and the depth set to the highest value

  • of all the cameras in the scene.

  • This way the UI camera only draws

  • the UI element based on the culling mask

  • setting and the UI element draws on top

  • of all of the other layers, based on the depth.

  • It is also worth noting that the camera is set to

  • orthographic to remove any possible

  • perspective on the UI element.

  • Typical uses of multiple cameras

  • are to render UI elements like

  • mini maps or heads-up displays over the

  • world view, make rear-view mirrors and

  • missile cameras, or to force the drawing order

  • of objects in the scene, like making

  • sure that a gun in a first person shooter

  • doesn't get drawn inside the level geometry.

  • The normalised viewport rect, render path,

  • target texture and HDR properties

  • are more advanced and will be covered in an other lesson.

Cameras.

本章介紹相機

字幕與單字

單字即點即查 點擊單字可以查詢單字解釋