Transforms are a key Component in every GameObject. They dictate where the GameObject is positioned, how it is rotated, and its scale. It is impossible to have a GameObject without a Transform. You can adjust the Transform of any GameObject from the Scene View, the Inspector, or through Scripting. 變換是每個游戲物體(GameObject)的關(guān)鍵組件。它們決定GameObject的位置,旋轉(zhuǎn)和縮放。有不帶變換組件的游戲物體是不可能的。可以從場景視圖、檢視面板、或通過腳本調(diào)整任意GameObject的變換。 The remainder of this page's text is from the Transform Component Reference page. 從Transform Component Reference頁面查看更多描述。 Transform 變換The Transform Component determines the actual Position, Rotation, and Scale of all objects in the scene. Every object has a Transform. 變換組件決定場景中所有物體的實際位置、旋轉(zhuǎn)和縮放。每個物體都具有變換組件。
Properties 屬性
All properties of a Transform are measured relative to the Transform's parent. If the Transform has no parent, the properties are measured relative to World Space. 變換的所有屬性相對于變換的父級測量。如果變換沒有父級,該屬性將相對于世界空間測量。 Using Transforms 使用變換Transforms are always manipulated in 3D space using X, Y, and Z axes. In Unity, these axes are represented by the colors red, green, and blue respectively. Remember: XYZ = RGB. 變換總是在3D空間使用x,y,z軸操控。在Unity,這些軸的顏色用紅色,綠色,和藍(lán)色分別代表。這樣記憶:XYZ = RGB 。
Transform Components can be directly manipulated using the Scene View or the Inspector. The Inspector will list the properties stated above for easy editing. You can also modify Transforms in your Scene by interacting with them, using the Move, Rotate, and Scale tools. These tools are located in the upper left-hand corner of the Unity Editor. 變換組件可以使用場景視圖工具或檢視面板直接操作。在檢視面板將列出屬性,輕松的編輯。也可以在場景直接交互修改變換,使用移動、旋轉(zhuǎn)和縮放工具。這些工具在Unity編輯器的左上角。
The tools will be usable on any object in your scene. Click on the object, and you will see the tool gizmo appear around it. Depending on the current tool, the gizmo will look slightly different. Clicking the object will also cause the Transform component to become visible in the Inspector. If the Inspector does not display the Transform component or its properties, then you do not have an object highlighted in the Scene View. 這些工具可以用于場景中任何物體。在物體上點擊,可以看到工具的gizmo顯示。根據(jù)當(dāng)前選擇的工具gizmo的樣式將會不同。點擊物體也會使變換組件在檢視面板變?yōu)榭梢姟H绻跈z視面板不顯示變換組件或它的屬性,那么是你在場景中沒有選擇物體。
在場景視圖中可以直接編輯的三種Gizmo。 To manipulate the Transform, click and drag on one of the 3 gizmo axes, you'll notice its color changes. As you drag the mouse, you will see the object translate, rotate, or scale along the axis. When you release the mouse button, you'll notice that the axis remains selected. You can click the middle mouse button and drag the mouse to manipulate the Transform along the selected axis. To access all 3 axes at once click and drag the center point of all 3 gizmos. 若要操縱變換,點擊并拖拽其中一個gizmo軸,你會發(fā)現(xiàn)軸的顏色會改變。拖動鼠標(biāo)看物體沿軸的移動、旋轉(zhuǎn)和縮放。當(dāng)釋放鼠標(biāo)時,你會發(fā)現(xiàn),軸仍在保持選中狀態(tài),點鼠標(biāo)中鍵拖拽鼠標(biāo)來操作沿著選擇的軸操作變換。要訪問全部3個軸點擊3個軸中間的方塊拖動鼠標(biāo)。
Parenting 父子級Parenting is one of the most important concepts to understand when using Unity. When a GameObject is a Parent of another GameObject, the Child GameObject will move, rotate, and scale exactly as its Parent does. Just like your arms are attached to your body, when you turn your body, your arms move because they're attached. Any object can have multiple children, but only one parent. 在使用Unity時,父子級是一個需要理解的很重要的概念。當(dāng)你游戲物體是另一個游戲物體的父級時,子游戲物體將準(zhǔn)確的按照父物體那樣移動、旋轉(zhuǎn)和縮放,就如同胳膊附著在身體上一樣,當(dāng)你活動身體,胳膊也會移動,因為它是附著在身體上的。任何物體可以有多個子物體,但只會有一個父物體。 You can create a Parent by dragging any GameObject in the Hierarchy View onto another. This will create a Parent-Child relationship between the two GameObjects. 同在層級視圖拖拽任意游戲物體到另一個上面就可以創(chuàng)建父物體,這會在兩個游戲物體直接創(chuàng)建父子關(guān)系。
父子級的例子,所有帶有向左箭頭的都是父物體 In the above example, we say that the arms are parented to the body, and the hands are parented to the arms. The scenes you make in Unity will contain collections of these Transform hierarchies. The topmost parent object is called the Root object. When you move, scale, or rotate a parent, all the changes in its Transform are applied to its children as well. 在上面的例子中我們說身體是胳膊的父物體,而胳膊又是手的父物體。在Unity中制作場景包含這些變換層級,最頂級父物體被稱為Root object(根物體)。當(dāng)移動、縮放或旋轉(zhuǎn)父級,所有變換的改變將應(yīng)用到它的子物體。 It is worth pointing out that the Transform values in the Inspector of any Child GameObject are displayed relative to the Parent's Transform values. These are also called the Local Coordinates. Through scripting, you can access the Global Coordinates as well as the Local Coordinates. 需要特別指出的是,在檢視面板任何子游戲物體顯示的變換的值相對于父變換的值。這也稱為局部坐標(biāo),通過腳本,也可以訪問全局坐標(biāo),像訪問局部坐標(biāo)一樣。 You can build compound objects by parenting multiple separate objects together, like the skeletal structure of a human ragdoll. You can also create small yet effective objects with single parents. For example, if you have a horror game that takes place at night, you can create an effective atmosphere with a flashlight. To create this object, you would parent a spotlight Transform to the flashlight Transform. Then, any alteration of the flashlight Transform will affect the spotlight, creating a convincing flashlight effect. 可以通過父子級多個單獨的物體到一起,來構(gòu)建復(fù)合物體,像人偶的骨骼結(jié)構(gòu)。還可以創(chuàng)建只帶一個父物體小而有效的物體。例如,你有一個恐怖游戲,發(fā)生在夜間,可以創(chuàng)建帶有手電筒的實際氛圍。要創(chuàng)建這個物體,需要父子化聚光燈變換到手電筒變換,然后,手電筒變換的任何改變將影響聚光燈,創(chuàng)建一個具有說服力的手電筒效果。 Importance of Scale 縮放的重要性The scale of the Transform determines the difference between the size of your mesh in your modeling application, and the size of your mesh in Unity. The mesh's size in Unity (and therefore the Transform's scale) is very important, especially during physics simulation. There are 3 factors that can determine the Scale of your object: 變換的縮放決定網(wǎng)格物體在建模程序和Unity中的大小。在Unity網(wǎng)格物體的大小是非常重要的,尤其是在物理模擬時。有三個因素決定物體的縮放:
Ideally, you should not adjust the Scale of your object in the Transform Component. The best option is to create your models at real-life scale, so you won't have to change your Transform's scale. The second-best option is to adjust the scale at which your mesh is imported in the Import Settings for your individual mesh. Certain optimizations occur based on the import size, and instantiating an object that has an adjusted scale value can decrease performance. For more information, read through the Rigidbody component's section on optimizing scale. 理想的情況是不在物體的變換組件中調(diào)整縮放。最佳選項是建模時按照實際大小,這樣就不用修改變換的縮放。第二較好的選項是,針對個別網(wǎng)格導(dǎo)入時,在導(dǎo)入設(shè)置中來調(diào)節(jié)縮放。某些優(yōu)化是基于導(dǎo)入時的大小,實例化一個物體要調(diào)整縮放值,可能會影響性能。更多信息參考剛體組件章節(jié)中的優(yōu)化縮放。 Hints 提示
頁面最后更新:2007-11-16 |
|