Unity3D说明文档翻译-Transforms

来源:互联网 发布:程序员联合开发王 编辑:程序博客网 时间:2024/05/16 08:21

Transforms

转换组件

The Transform is used to store a GameObject’s position, rotation, scale and parenting state and is thus very important. A GameObject will always have a Transform component attached - it is not possible to remove a Transform or to create a GameObject without one.

转换组件被用于存储一个游戏对象的位置,旋转,大小和父子状态因此非常重要.一个游戏对象将总是有一个转换组件附加-不可以移除转换组件或创建一个游戏对象不用它.

Editing Transforms

编辑转换组件

Transforms are manipulated in 3D space in the X, Y, and Z axes or in 2D space in just X and Y. In Unity, these axes are represented by the colors red, green, and blue respectively.

转换组件在3D空间的X,Y和Z轴或2D空间的X和Y轴上操作.在Unity上,这些轴以红,绿,蓝颜色分别表示.

A transform showing the color-coding of the axes

转化组件显示的颜色标记的轴

 

A Transform can be edited in the Scene View or by changing its properties in the Inspector. In the scene, you can modify Transforms using the Move, Rotate and Scale tools. These tools are located in the upper left-hand corner of the Unity Editor.

一个转换组件可以在场景视图内编辑或在检视面板上改变它的属性.在场景内,你可以使用移动,旋转和大小工具更改转换组件.这些工具坐落在Unity编辑器的左上角.

The View, Translate, Rotate, and Scale tools

转换,旋转和大小工具条视图

 

The tools can be used on any object in the scene. When you click on an object, you will see the tool gizmo appear within it. The appearance of the gizmo depends on which tool is selected.

工具可用于任何场景对象.当你点击一个对象,你将看到工具小图示出现在它里面.小图示的外观取决于选定的工具.

Transform gizmo

转换组件小图示

 

When you click and drag on one of the three gizmo axes, you will notice that its color changes to yellow. As you drag the mouse, you will see the object translate, rotate, or scale along the selected axis. When you release the mouse button, the axis remains selected. If you subsequently drag with the middle mouse button, the axis last selected will be used regardless of the mouse position.

当你点击或拖拽小图示三个轴的一个,你将注意到它的颜色变为黄色.当你拖拽鼠标,你将看到对象选定的轴转换,旋转或缩放.当你释放鼠标按钮,轴保持选定.如果你随后用鼠标中键拖拽,最后选定的轴将被选定不管鼠标位置.

A Transform showing the selected (yellow) X axis

一个转换组件显示被选定的X轴

 

There is also an additional option in Translate mode to lock movement to a particular plane (ie, allow dragging in two of the axes while keeping the third unchanged). The three small coloured squares around the center of the Translate gizmo activate the lock for each plane; the colors correspond to the axis that will be locked when the square is clicked (eg, blue locks the Z axis).

在转换模式上也有一个额外的选项用来锁定在特定平面上移动(例如,允许在两个轴内移动而保持第三个轴不改变).在转换小图示中心周围的着色方形激活锁定各个平面.当方块被点击它的颜色和将被锁定的轴相同(例如,蓝色锁定Z轴).

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. You can think of parenting as being like the relationship between your arms and your body; whenever your body moves, your arms also move along with it. Child objects can also have children of their own and so on. So your hands could be regarded as “children” of your arms and then each hand has several fingers, etc. Any object can have multiple children, but only one parent. These multiple levels of parent-child relationships form a Transform hierarchy. The object at the very top of a hierarchy (ie, the only object in the hierarchy that doesn’t have a parent) is known as the root.

父子关系是使用Unity时须明白的最重要的概念之一.当一个游戏对象是另一个游戏对象的父对象时,子游戏对象的移动,旋转和缩放将匹配它的父对象.你可以认为父子关系就像你手臂和身体的关系.不论你身体如何移动你的手臂也跟着移动.子对象也可以有它们自己的子对象.所以你的收可被认为是你手臂的子对象然后每个手又有几个手指等等.任何对象可以有多个子对象,但只有一个父对象.这些多层级父子关系来自一个转换层级.这些对象最顶端的层级(即,仅剩的在层级上没有父对象的对象)被认为是根.

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.

你可以通过在层级视图上拖拽任何游戏对象到另一个创建一个父对象.这将创建一个父子关系在这两个游戏对象间.

Example of a Parent-Child hierarchy. GameObjects with foldout arrows to the left of their names are parents.

父子层级例子.折页箭头在游戏父对象名称的左边.

 

Note that the Transform values in the Inspector for any child GameObject are displayed relative to the Parent’s Transform values. These values are referred to as local coordinates. Returning to the analogy of body and arms, the position of your body may move as you walk but your arms will still be attached at the same relative position. For scene construction, it is usually sufficient to work with local coordinates for child objects but in gameplay it is often useful to find their exact position in world space or global coordinates. The scripting API for the Transform component has separate properties for local and global position, rotation and scale and also allows you to convert any point between local and global coordinates.

注意任何子游戏对象转换组件在检视面板上的值是相对于负对象的转换组件的值.这些值被称为局部坐标系.返回相当于身体和手臂,当你走时你身体的位置可能移动但你的手臂将依然依附在相同的相对位置上.对于场景结构,通常子对象能充分工作在局部坐标系中,但在游戏内它通常对在世界或局部坐标系上寻找它们的位置是很有用的.关于转换组件的编写脚本API有分开表示局部和全局位置,旋转和缩放的属性且也允许你在任何点之间转换局部和全局坐标系.

Performance Issues and Limitations with Non-Uniform Scaling

性能问题和非等比缩放限制

Non-uniform scaling is when the Scale in a Transform has different values for x, y, and z; for example (2, 4, 2). In contrast, uniform scaling has the same value for x, y, and z; for example (3, 3, 3). Non-uniform scaling can be useful in a few specific cases but you should usually avoid it since it slows down graphic rendering. Also, it introduces a few oddities that don’t occur with uniform scaling:-

非等比缩放是当缩放在转换组件有不同的X,Y,Z值时,例如(2,4,2).相对的,等比缩放有相同的X,Y,Z值,如(3,3,3).非等比缩放可被用于一些特别情况但你需要尽量避免使用它因为它的图形渲染慢.且他引入一些不会在等比缩放中出现的古怪:

1. Certain components do not fully support non-uniform scaling. For example, some components have a circular or spherical element defined by a radius property, among them Sphere ColliderCapsule ColliderLight and Audio Source. In cases like this the circular shape will not become elliptical under non-uniform scaling as you would expect and will simply remain circular.

某些组件不完全支持非等比缩放.如,一些组件有一个由半径属性定义的环形或球形元素,其中包括球形碰撞器,胶囊体碰撞器,灯光和声音资源.像这些情况下圆形在非等比缩放下将不会变成你期待的椭圆并将简单的保持圆形.

2. When a child object has a non-uniformly scaled parent and is rotated relative to that parent, it may appear skewed or “sheared”. There are components that support simple non-uniform scaling but don’t work correctly when skewed like this. For example, a skewed Box Collider will not match the shape of the rendered mesh accurately.

当一个子对象有一个非等比缩放父对象且相等此父对象旋转,它将出现偏斜或剪切.有些组件支持简单的非对称缩放,但不能正常工作就像这样出现偏斜.如,一个偏斜盒子碰撞器将不会精确匹配此形状的渲染网格.

3. For performance reasons, a child object of a non-uniformly scaled parent will not have its scale automatically updated when it rotates. As a result, the child’s shape may appear to change abruptly when the scale eventually is updated, say if the child object is detached from the parent.

由于性能的原因,一个非对称缩放父对象的子对象当旋转时将不能自动更新它的大小.结果,子对象的形状当大小最后更新时如果子对象从父对象脱离,将出现意外的改变.

Importance of Scale

缩放的重要性

The scale of the Transform determines the difference between the size of a mesh in your modeling application and the size of that mesh in Unity. The mesh’s size in Unity (and therefore the Transform’s scale) is very important, especially during physics simulation. By default, the physics engine assumes that one unit in world space corresponds to one metre. If an object is very large, it can appear to fall in “slow motion”; the simulation is actually correct since effectively, you are watching a very large object falling a great distance.

转换组件的缩放确定了网格大小在你的模型软件和在Unity中的不同.网格的大小在Unity(和转换组件的缩放)是非常重要的,特别是在物理模拟期间.默认的,物理引擎假的一个世界空间单位相当于1米.如果一个对象非常大,它可能出现陷入慢镜头.模拟实际上是正确的,只是因为你在一个遥远的距离观看一个巨大的对象.

There are three factors that can affect the scale of your object:

这里有3个因素影响你对象的缩放:

1. The size of your mesh in your 3D modeling application.

2. The Mesh Scale Factor setting in the object’s Import Settings.

3. The Scale values of your Transform Component.

1.在你3D模型程序中你网格的大小.

2.在对象导入设置中的网格比例因子设置.

3.你的转换组件中的缩放值.

 

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 next 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, see the section about optimizing scale on the Rigidbody component reference page.

理想上,你不需要调整你的对象中转换组件的缩放.最好的选择是按现实大小创建你的模型,所以你不必改变你的转换组件大小.下一个选择是在你的网格导入的导入设置中单独给你的网格调整大小.几个优化发生基于导入大小并实例一个对象,有一个调整缩放值可以降低表现.更多信息,参考有关章节关于在刚体组件优化大小引用页面.

Tips for Working with Transforms

使用变换组件技巧

1. When parenting Transforms, it is useful to set the parent’s location to <0,0,0> before adding the child. This means that the local coordinates for the child will be the same as global coordinates making it easier to be sure you have the child in the right position.

当设置转换组件父子关系时,在添加子对象前设置父对象的位置为(0,0,0)很有用.这意味着子对象的局部坐标系恒全局坐标系一样,使他更容易确定你的子对象在正确位置.

2. Particle Systems are not affected by the Transform’s Scale. In order to scale a Particle System, you need to modify the properties in the System’s Particle Emitter, Animator and Renderer.

粒子系统不受转换组件缩放的影响.为了缩放一个粒子系统,你需要改变粒子系统的粒子发射器,动画制作器和渲染器的属性.

3. If you are using Rigidbodies for physics simulation then be sure to read about the Scale property on the Rigidbody component reference page.

如果你使用刚体做物理仿真,则务必阅读刚体组件上关于缩放属性的参考页面.

4. You can change the colors of the Transform axes (and other UI elements) from the preferences (Menu: Unity > Preferences and then select the Colors & keys panel).

你可以从首选项改变转变轴(和其他UI元素)的颜色(菜单:Unity>首选项然后选择颜色与键面板).

5. Changing the Scale affects the position of child transforms. For example scaling the parent to (0,0,0) will position all children at (0,0,0) relative to the parent.

改变大小影响子对象转换组件位置.如改变父对象为(0,0,0)将定位所以子对象相对于父对象为(0,0,0).

 

0 0
原创粉丝点击