UNITY 5.2 Transform类

来源:互联网 发布:友情女王网络调教 编辑:程序博客网 时间:2024/04/28 17:06

概述:

用于在场景中控制对象的 坐标、旋转、缩放。每个变换对象都有一个父层级,变换对象支持遍历。

变量:

public int childCount { get; }
说明:只读属性,返回当前变换对象中的子对象数

public Matrix4x4 localToWorldMatrix { get; }
说明:只读属性,返回将局部坐标转换为世界坐标的矩阵

public Matrix4x4 worldToLocalMatrix { get; }
说明:只读属性,返回将世界坐标转为为局部坐标的矩阵

public Transform root { get; }
说明:只读属性,返回该变换对象的最上级根节点,若没有则返回自己

public Vector3 lossyScale { get; }
说明:返回转换对象的世界缩放

public Vector3 right { get; set; }
说明:x 轴正方向在世界坐标系中的方向向量

public Vector3 up { get; set; }
说明:y 轴正方向在世界坐标系中的方向向量

public Vector3 forward { get; set; }
说明:Z 轴正方向在世界坐标系中的方向向量
 
public bool hasChanged { get; set; }
说明:从上一次设置为 false 到现在是否发生了改变,只要更新了数据,都会设置为 true,在调用后设置为 false
 
public Vector3 eulerAngles { get; set; }
说明:变换对象的欧拉角(度数),x 为绕 x 轴旋转的角度,y 为绕 y 轴旋转的角度,z 为绕 z 轴旋转的角度。度数设置的值为绝对值而且小于360,向量值最好同时设置
 
public Vector3 localEulerAngles { get; set; }
说明:放回变换对象相对于父节点的欧拉角

public Vector3 position { get; set; }
说明:返回变换对象的世界坐标

public Vector3 localPosition { get; set; }
说明:返回变换对象相对于父节点的坐标

Public Quaternion rotation { get; set; }
说明:返回变换对象的世界坐标中的旋转角度

public Quaternion localRotation { get; set; }
说明:返回变换对象相对于父节点的旋转角度

public Transform parent { get; set; }
说明:返回变换对象的父级,更改父级会保持世界变换的值,改变局部变换的值


Public函数:
public void DetachChildren();
说明:将所有子节点提升到与该节点同级,用于删除节点,但不删除子节点

public Transform Find(string name);
public Transform FindChild(string name);
说明;查找名称为 name 的子节点,若带 '/' 则转换为层级结构,若未找到返回null

public Transform GetChild(int index);
说明:通过一个所引值返回一个转换对象,索引应该小于 Transform.childCount

public int GetSiblingIndex();
说明:获取同级的索引

public Vector3 InverseTransformDirection(Vector3 direction);
public Vector3 InverseTransformDirection(float x, float y, float z);
说明:将方向向量从世界坐标中转换为本地坐标系中的向量

public Vector3 TransformDirection(Vector3 direction);
public Vector3 TransformDirection(float x, float y, float z);
说明:将方向向量从本地坐标中转换为世界坐标系中的向量

public Vector3 InverseTransformPoint(Vector3 position);
public Vector3 InverseTransformPoint(float x, float y, float z);
说明:将坐标向量从世界坐标中转换为本地坐标系中的向量

public Vector3 TransformPoint(Vector3 position);
public Vector3 TransformPoint(float x, float y, float z);
说明:将坐标向量从本地坐标中转换为世界坐标系中的向量


public Vector3 InverseTransformVector(Vector3 vector);
public Vector3 InverseTransformVector(float x, float y, float z);
说明:将向量从世界坐标中转换为本地坐标系中的向量

public Vector3 TransformVector(Vector3 vector);
public Vector3 TransformVector(float x, float y, float z);
说明:将向量从本地坐标总转换为世界坐标系中的向量

public bool IsChildOf(Transform parent);
说明:是否在 parent 的层级下

public void LookAt(Transform target);
public void LookAt(Transform target, Vector3 worldUp);
说明:指定某个对象的 Z轴(向前向量) 指向目标对象(target),向上向量默认为 Y轴 (向上向量) 或指定

public void Rotate(Vector3 eulerAngles);
public void Rotate(Vector3 eulerAngles, Space relativeTo);
说明:eulerAngles 三个轴的旋转角度, relativeTo 是否为局部坐标轴 或者 世界坐标轴

public void Rotate(Vector3 axis, float angle);
public void Rotate(Vector3 axis, float angle, Space relativeTo);
说明:axis 某一个坐标轴的向量, angle 旋转角度, relativeTo是否为局部坐标轴 或者世界坐标轴

public void Rotate(float xAngle, float yAngle, float zAngle);
public void Rotate(float xAngle, float yAngle, float zAngle, Space relativeTo);
说明:xAngle,yAngle,zAngle 三根轴的旋转角度, relativeTo是否为局部坐标轴 或者世界坐标轴

public void RotateAround(Vector3 point, Vector3 axis, float angle);
说明:在世界坐标中 point 处,绕轴 axis 旋转 angle度

public void SetAsFirstSibling();
说明:将该 变换对象在父节点中的索引设置为第一个

public void SetAsLastSibling();
说明:将该 变换对象在父节点中的索引设置为最后一个

public void SetParent(Transform parent);
public void SetParent(Transform parent, bool worldPositionStays);
说明;设置该对象的父对象为 parent, worldPositionStays 是否保持该对象在世界中的属性

public void SetSiblingIndex(int index);
说明:设置该对象在父对象中的所引值

public void Translate(Vector3 translation);
public void Translate(float x, float y, float z);
说明:将该变换对象沿该向量指定的方向移动该向量指定距离,默认为本地坐标系

public void Translate(Vector3 translation, Space relativeTo);
public void Translate(float x, float y, float z, Space relativeTo);
说明:将该变换对象沿该向量指定的方向移动该向量指定距离,通过 relativeTo 指定本地坐标系 或者 世界坐标系

public void Translate(Vector3 translation, Transform relativeTo);
public void Translate(float x, float y, float z, Transform relativeTo);
说明:将该变换对象沿该向量指定的方向移动该向量指定距离,指定坐标系为 relativeTo,若为null则为世界坐标系

public void LookAt(Vector3 worldPosition);
public void LookAt(Vector3 worldPosition, Vector3 worldUp);
说明:指定某个对象的 Z轴(向前向量) 指向世界坐标(worldPosition),向上向量默认为 Y轴 (向上向量) 或指定


0 0
原创粉丝点击