关于TransForm,大家都很熟悉,每个世界中的 Object 都会有这么一个组件
既然是组件,所以继承自组件Component
命名空间为UnityEngine
它的功能是储存和操作世界中的物体的三个属性位置,旋转,缩放。
这个三个属性是相对的,因此每个TransForm 都有一个父Transform。
在层级面板中,可以看到它的层级关系。
TransForm是支持枚举的,因此可以像这样来控制它的子级
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
void Example() {
foreach (Transform child in transform) {
child.position += Vector3.up * 10.0F;
}
}
}
childCount | 子对象个数 |
eulerAngles | 欧拉角度 |
forward | 正前方 |
hasChanged | 自从上次标志位设置为false之后,是否有改变 |
localEulerAngles | 本地坐标系下的欧拉角度 |
localPosition | 相对坐标 |
localRotation | 相对角度 |
localScale | 相对缩放 |
localToWorldMatrix | 将本地坐标系转换为世界坐标系的矩阵 |
lossyScale | 世界坐标系下的缩放值(只读) |
parent | 父Transform |
position | 世界坐标 |
right | 右方向 |
root | 顶级Transform |
rotation | 世界坐标旋转角度 |
up | 上方向 |
worldToLocalMatrix | 世界坐标系转换为本地坐标系的矩阵 |
属性都很简单,我们来看看方法
DetachChildren | 移除父物体的所有子对象 |
Find | 根据名字返回子对象 |
GetChild | 根据索引值返回子对象(索引值必须比子对象个数小,同Flash中的索引) |
GetSiblingIndex | 返回索引 |
InverseTransformDirection | 世界方向转换为本地方向.与Transform.TransformDirection.相反 |
InverseTransformPoint | 世界坐标点转换为本地坐标点. 与Transform.TransformPoint.相反 |
IsChildOf | 是否为其子对象 |
LookAt | 旋转角度使其注视一个物体 |
Rotate | 旋转角度 |
RotateAround | 按照angle度通过在世界坐标某个轴旋转物体。 |
SetAsFirstSibling | 将该对象移到同级对象的首位 |
SetAsLastSibling | 将该对象移到同级对象的最后一位 |
SetSiblingIndex | 将该对象移到指定的索引处 |
TransformDirection | 将某个方向向量从当前坐标系转换到世界坐标系 |
TransformPoint | 将某个点坐标从当前坐标系转换到世界坐标系 |
Translate | 移动 |