朱峰社區(qū)首頁 朱峰社區(qū)

搜索資源 注冊|登陸

等待

返回 展開菜單
按功能 按軟件

Unity3D游戲制作教程

Unity3D游戲制作教程

包含5節(jié)視頻教程

本系列包含Unity3D介紹、Unity3D導(dǎo)出人物、Unity3D導(dǎo)出場景、Unity3D導(dǎo)出動作、游戲測試最終完成一個簡單的游戲。是一套非常完整的Unity3D游戲制作教程。

關(guān)閉

Unity組件:Transform 變換

關(guān)注:1037 留言:0 樓主:zxt19880310 發(fā)帖時間:15年11月16日

zxt19880310

普通會員

zxt19880310

社區(qū)領(lǐng)袖:10級

關(guān)注2174人

  • 性別

  • 年齡

    18

  • 積分

    1866

  • 登陸

    1

  • 發(fā)帖

    2

  • 留言

    1

間隔線

The Transform Component determines the actual Position, Rotation, and Scale of all objects in the scene. Every object has a Transform.

變換組件決定了場景中所有物體的方位,旋轉(zhuǎn)和縮放。每個物體都有一個變換組件。


The Transform Component is viewable and editable in the Inspector
變換組件在檢查窗中是可見且可編輯的

Properties 屬性
  • Position 位置
    Position of the Transform in X, Y, and Z coordinates.
    以X、Y、Z坐標(biāo)系表示變換的位置。
  • Rotation 旋轉(zhuǎn)
    Rotation of the Transform around the X, Y, and Z axes, measured in degrees.
    表示此變換以X,Y,Z軸為準(zhǔn)的旋轉(zhuǎn)程度,以角度為單位。
  • Scale 縮放
    Scale of the Transform along X, Y, and Z axes. Value "1" is the original size (size at which the object was imported).
    沿著X,Y,Z軸縮放此變換。值為"1"時表示原始尺寸(物體最初被導(dǎo)入時的大。

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.

變換組件的所有屬性都是相對其父物體進(jìn)行衡量的,如果此物體沒有父物體,這些屬性則相對于世界坐標(biāo)進(jìn)行計算。

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.

變換組件在三維空間中始終使用X,Y,Z軸進(jìn)行操作,在Unity中,這些坐標(biāo)軸分別被標(biāo)注為紅,綠,藍(lán)三種顏色,牢記:XYZ=RGB


Color-coded relationship between 3 axes and Transform properties
變換組件屬性中三個坐標(biāo)軸所對應(yīng)的顏色關(guān)系。

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.

變換組件可以在Scene視圖或監(jiān)視窗中即時的進(jìn)行操作,在監(jiān)視窗上會列出它的屬性并且可以簡單的進(jìn)行編輯,你也可以通過使用移動,旋轉(zhuǎn)和縮放工具來修改場景中物體的變換屬性,這些工具在Unity編輯器的坐上角位置可以找到。


The View, Translate, Rotate, and Scale tools
觀察,移動,旋轉(zhuǎn)和縮放工具。

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.

這些工具可以用于你場景中的任何物體,在物體上單擊,你將會看到當(dāng)前選中的工具的線框顯示在物體周圍,這些線框看起來各不相同,點(diǎn)擊物體也會使變換組件的屬性顯示在監(jiān)視窗中,如果如果監(jiān)視窗中沒有顯示任何變換組件或?qū)傩,那么此時場景中沒有高亮的物體(沒有被選中的物體)。



All three Gizmos can be directly edited in Scene View.

這三種線框可以直接在Scene視圖中進(jìn)行操作。

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.

若想操作變換屬性,只需在三個線框坐標(biāo)軸上點(diǎn)擊并拖動,你會發(fā)現(xiàn)被點(diǎn)擊的軸顏色改變了,當(dāng)你用鼠標(biāo)拖動時,你會看到物體會沿著這些軸移動,旋轉(zhuǎn)或縮放。當(dāng)你釋放鼠標(biāo)按鍵時,你會發(fā)現(xiàn)坐標(biāo)軸仍處于選中狀態(tài),你可以點(diǎn)擊鼠標(biāo)中鍵并拖動來操作物體沿著選中坐標(biāo)軸的變換,如果想同時操作三個坐標(biāo)軸,那么就點(diǎn)擊并拖動三個坐標(biāo)軸線框的中點(diǎn)。


Any individual axis will become selected when you click on it
當(dāng)你點(diǎn)擊一個單獨(dú)的坐標(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)一個游戲?qū)ο笫橇硪粋游戲?qū)ο蟮母肝矬w時,其子游戲?qū)ο髸S著它移動、旋轉(zhuǎn)和縮放,就像你的胳膊屬于你的身體,當(dāng)你旋轉(zhuǎn)身體時,你的胳膊也會跟著旋轉(zhuǎn)一樣。任何物體都可以有多個子物體,但只能有一個父物體。

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)系關(guān)聯(lián)這兩個游戲?qū)ο蟆?/p>


A real-world example of a Parent-Child hierarchy. All the GameObjects with arrows to the left are Parents.
一個父子層級實(shí)例。左側(cè)帶有箭頭的都是父物體。

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中的場景會包含這些變換層級的集合,最外層的父物體對象被稱作根對象,當(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.

由此可見監(jiān)視窗中任意一個子物體所顯示的值都是相對于其父物體的,這也稱作局部坐標(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.

你可以通過子化多個獨(dú)立的對象來建立符合對象,例如人體骨骼結(jié)構(gòu)玩偶,你也可以使用單層父物體來創(chuàng)建小而有效的對象,例如,你想做一個夜晚時分的恐怖游戲,你可以使用閃光燈來創(chuàng)造一個很好的氣氛,創(chuàng)建這個對象時,你可以用一個聚光燈作為閃光燈的子物體,然后任何對于閃光燈的改動都會影響到聚光燈,制作出一個逼真的閃光燈。

Importance of Scale 縮放的重點(diǎn)內(nèi)容

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)格在建模應(yīng)用程序和Unity之間的尺寸差異,網(wǎng)格的尺寸(取決于變換縮放)在Unity中十分的重要,特別是在物理仿真時。我們有三個系數(shù)來控制物體的縮放:

  • The size of your mesh in your 3D modeling application.
    網(wǎng)格在3D建模應(yīng)用程序中的尺寸。
  • The Mesh Scale Factor setting in the object's Import Settings.
    導(dǎo)入設(shè)置中的網(wǎng)格縮放比例系數(shù)
  • The Scale values of your Transform Component.
    變換組件的縮放值

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)整物體變換組件中的縮放參數(shù),最好的選擇是在創(chuàng)建模型時使用顯示比例縮放,這樣你就可以不用調(diào)整變換縮放,第二種選擇是在導(dǎo)入設(shè)置中調(diào)整每個網(wǎng)格的縮放比例。某些優(yōu)化是基于導(dǎo)入尺寸的,假如一個對象進(jìn)行縮放調(diào)整時會降低一些性能。想要了解更多信息,閱讀剛體組件的最佳化縮放一節(jié)。

Hints 提示
  • When parenting Transforms, put the parent's location at 0,0,0 before applying the child. This will save you many headaches later.
    當(dāng)父子化變換組件時,在添加子物體之前將父物體放置到坐標(biāo)0,0,0位置,這將免去你之后的很多麻煩。
  • Particle Systems are not affected by the Transforms Scale. In order to scale a Particle System, you need to modify the properties in the System's Particle Emitter, Animator and Renderer.
    粒子系統(tǒng)不受縮放變換影響,如果想要縮放粒子系統(tǒng),你需要修改粒子系統(tǒng)中粒子發(fā)射器、動畫、和渲染屬性。
  • If you are using Rigidbodies for physics simulation, there is some important information about the Scale property to be read on the Rigidbody page.
    如果你使用剛體用于物理仿真,剛體頁面這里讀到一些重要信息關(guān)于縮放屬性。
  • You can change the colors of the Transform axes (and other UI elements) from the Unity Menu->Preferences->Colors & keys.
    你可以修改變換組件坐標(biāo)軸(和其他用戶界面元素)的顏色通過菜單調(diào)用Unity Menu->Preferences->Colors & keys
  • If you can avoid scaling, do so. Try to have the scales of your object finalized in your 3D modeling application, or in the Import Settings of your mesh.
    如果你想避免縮放,那就這樣做,試著在3D建模應(yīng)用程序中或?qū)朐O(shè)置中定型你的網(wǎng)格。

贊0 踩0

未知用戶

2005-2024 朱峰社區(qū) 版權(quán)所有 遼ICP備2021001865號-1
2005-2024 ZhuFeng Community All Rights Reserved

VIP

朱峰社區(qū)微信公眾號

回頂部

1.復(fù)制文本發(fā)給您的QQ好友或群、微信等;好友點(diǎn)擊鏈接以后,轉(zhuǎn)發(fā)就成功了。 2.如朋友點(diǎn)擊您的鏈接,您需要需刷新一下才行;同一個好友僅能點(diǎn)擊一次。
購買VIP,觀看所有收費(fèi)教程!