青岛建站软件,做网站建设公司排名,wordpress本地建站,石家庄建设集团有限公司网站Transform类继承自Component类#xff0c;并实现了IEnumberable接口。Transform是GameObject必须拥有得一个组件#xff0c;用来管理所在GameObject对象的坐标位置、选择角度、和大小缩放。 Transform实现了IEnumberable接口#xff0c;因此可以在程序中使用foreach()方法快…Transform类继承自Component类并实现了IEnumberable接口。Transform是GameObject必须拥有得一个组件用来管理所在GameObject对象的坐标位置、选择角度、和大小缩放。 Transform实现了IEnumberable接口因此可以在程序中使用foreach()方法快速遍历子物体的Transform结构。
Transfrom类实例属性
在Transform类中涉及的实例属性有 eulerAngles 、forwardr 、hasChanged、localPosition、localToWorldMatrix 、parent 和 worldToLocalMatrix属性
eulerAngles属性欧拉角
基本语法
public Vector3 eulerAngles{ get; set; }功能说明 此属性用于返回或设置GameObject对象的欧拉角 1、在Unity引擎中使用四元数Quaternion来存储和表示GameObject的旋转角度无论是在Inspector面板中对Rotation设置了数值还是在脚本中对transform.eulerAngles赋予了数值程序在编译运行时都会把它们转换成Quaternion类型再计算。 2、只能对transform.eulerAngles进行整体赋值如transform.eulerAnglesnew Vector(1.0f,2.0f,3.0f)不可以对transform.eulerAngles的单独分量进行赋值。 3、transform.eulerAngles.x返回值的范围为[0,90]和[270,360)transform.eulerAngles.y和transform.eulerAngles.z返回值的范围为[0,360)。 4、对transform.eulerAngles进行赋值或获取transform.eulerAngles的值都是相对世界坐标系而言的若要相对transform的父物体(如果有的话)进行角度的变换则需要使用属性localEulerAngles来设置 5、设在脚本中有代码transform.eulerAnglesnew Vector3(10.0f, 20.0f ,30.0f)则GameObject对象会先沿着z轴旋转30度再沿着x轴旋转10度最后再沿着y轴旋转20度。(不同的旋转执行顺序物体的最终状态是不同的)
forward属性z轴单位向量
基本语法
public Vector3 forward{get ; set;}功能说明此属性用于返回或设置transform自身坐标系中z轴方向的单位向量对应的世界坐标系中的单位向量。transform.forward即为transform.TransformDirection(new Vector3(0.0f , 0.0f ,1.0f))的简化方式。
hasChanged属性transform组件是否被修改
基本语法
public bool hasChanged{ get; set;}功能说明 此属性用于判断GameObject对象从上次将此属性设为false以来其transform组件的属性是否被修改过。 注意即使transform某个属性修改后的值与修改前的值相同hasChanged的返回值仍然为true
localPosition属性局部坐标系位置
基本语法
public Vector3 localPosition{ get; set; }功能说明 此属性用于设置或返回GameObject对象在局部坐标系中的位置若无父级对象则和属性Transform.position返回值相同。 transform.loaclPosition的值受父级对象属性影响当transform.localPosition的值增加1时transform.position值的赠量不一定是1而是在相对父级坐标系中增加父级对象的值。
localToWorldMatrix属性转换矩阵
基本语法
public Matrix4x4 localToWorldMatrix{ get; }功能说明 此属性用于返回从transform局部坐标系向世界坐标系转换的Matrix4x4矩阵
parent属性父物体Transform实例
基本语法
public Transform parent{get;set;}功能说明 此属性用于返回父物体的Transform实例。 transform.parent只能返回父一级对象的Transform若要返回父物体的父物体可以使用transform.parent.parent更多级父物体以此类推。 若父物体不存在则返回null。 若想返回transform的最顶层的父物体可以使用transform.rooot属性
worldToLocalMatrix属性转换矩阵
基本语法
public Matrix4x4 worldToLocalMatrix{ get; }功能说明 此属性用于返回物体从世界坐标系向transform自身坐标系转换的Matrix4x4矩阵
Transform类实例方法
DetachChildren方法分离物体层级关系
基本语法
public void DetachChildren();功能说明 此方法的功能是使GameObject对象的所有子物体和自身分离层级关系当子物体的行为不再依赖父物体时可以用此方法使父子关系分离。 若子物体仍有子物体分离后的子物体将保留子物体的子物体的层级关系
GetChild方法获取GameObject对象子类
基本语法
public Transform GetChild(int index);功能说明 此方法用于返回transform的索引值为index的子类Transform实例。 参数index的值要小于transform的childCount值
InverseTransformDirection方法坐标系转换
基本语法
1、public Vector3 InverseTransformDirection(Vector3 direction);
其中参数direction为待转换的向量
2、public Vector3 InverseTransformDirection(float x,float y,float z);功能说明 此方法用于将参数direction从世界坐标系转换到GameObject对象的局部坐标系。
InverseTransformPoint方法点的相对坐标向量
基本语法
1、public Vector3 InverseTransformPoint(Vector3 position);
2、public Vector3 InverseTransformPoint(float x, float y, float z);功能说明 此方法用于返回参数position向量相对于GameObject对象局部坐标系的差向量即返回向量position和向量transform.position的差值。
IsChildOf方法是否为子物体
基本语法
public bool IsChildOf(Transform parent);
其中参数parent为父物体的Transform实例功能说明 此方法用于判断transform对应的GameObject对象是否为参数parent的子物体
LookAt方法物体朝向
基本语法
1、public void LookAt(Transform target);
2、public void LookAt(Vector3 worldPosition);
3、public void LookAt(Transform target,Vector3 worldUp);
4、public void LookAt(Vector3 worldPosition , Vector3 worldUp);
其中参数target为transform自身坐标系中z轴指向的目标参数worldUp为transform自身坐标系中y轴最大限度指向的方向功能说明 此方法的功能是使得GameObject对象自身坐标系中的z轴指向targety轴方向最大限度地指向worldUp方向。
Rotate方法绕坐标轴旋转
基本语法
1、public void Rotate(Vector3 eulerAngles);
2、public void Rotate(Vector3 eulerAngles , Space relativeTo);
3、public void Rotate(float xAngle , float yAngle ,float zAngle);
4、public void Rotate(flaot xAngle , float yAngle ,float zAngle ,Space relativeTo);
其中参数eulerAngles为transform要旋转的欧拉角参数relativeTo为transform旋转时参考的坐标系默认为Space.Self。功能说明 此方法的功能是使得transform实例在相对参数relativeTo的坐标系中旋转欧拉角eulerAngles。
Rotate方法绕某个向量旋转
基本语法
1、public void Rotate(Vector3 axis ,float angle);
2、public void Rotate(Vector3 axis ,float angle ,Space relativeTo);
其中参数axis为旋转轴方向参数angle为旋转角度参数relativeTo为参考坐标系默认为Space.self。功能说明 此方法的功能是使得GameObject对象在relativeTo坐标系中绕轴向量axis旋转angle度。
RotateAround方法绕轴点旋转
基本语法
1、public void RotateAround(Vector3 axis ,float angle);
2、public void RotateAround(Vector3 point,Vector3 axis ,float angle);
其中参数point为参考点坐标参数axis为旋转轴方向参数angle为旋转角度功能说明 此方法的功能是使得GameObject对象绕着point点的axis方向旋转angle度
TransformDirection方法坐标系转换
基本语法
1、public Vector3 TransformDirection(Vector3 direction);
其中参数direction为待转换的Vector3实例向量。
2、public Vector3 TransformDirection(float x ,float y ,float z);功能说明 此方法用于将向量direction从transform局部坐标系转换到世界坐标系
TransformPoint方法点的世界坐标位置
基本语法
1、public Vector3 TransformPoint(Vector3 position);
其中参数position为transform局部坐标系的向量
2、public Vector3 TransformPoint(float x,float y,float z);功能说明 此方法用于返回GameObject对象局部坐标系中向量position在世界坐标系中的位置
Translate方法相对坐标系移动
基本语法
1、public void Translate(Vector3 translation);
2、public void Translate(Vector3 translation ,Space relativeTo);
3、public void Translate(float x ,float y , float z);
4、public void Translate(float x ,float y , float z , Space relativeTo);
其中参数transform为移动向量包括方向和大小参数relativeTo为参考坐标系空间默认为Space.Self功能说明 此方法的功能是使得GameObject对象在参数relativeTo的坐标系空间中移动参数transform指定的向量
Translate方法相对其他物体移动
基本语法
1、public void Translate(Vector3 translation , Transform relativeTo);
2、public void Translate(float x ,float y,float z, Transform relativeTo);
其中参数translation为移动向量包括方向和大小参数relativeTo为移动参考物体默认为Space.World。功能说明 此方法的功能是使得GameObject对象在相对relativeTo的坐标系中移动向量translation。 文章转载自: http://www.morning.mnslh.cn.gov.cn.mnslh.cn http://www.morning.tongweishi.cn.gov.cn.tongweishi.cn http://www.morning.zbqry.cn.gov.cn.zbqry.cn http://www.morning.ykwbx.cn.gov.cn.ykwbx.cn http://www.morning.qklff.cn.gov.cn.qklff.cn http://www.morning.wwnb.cn.gov.cn.wwnb.cn http://www.morning.kxypt.cn.gov.cn.kxypt.cn http://www.morning.fcpjq.cn.gov.cn.fcpjq.cn http://www.morning.pflpb.cn.gov.cn.pflpb.cn http://www.morning.jypsm.cn.gov.cn.jypsm.cn http://www.morning.fxjnn.cn.gov.cn.fxjnn.cn http://www.morning.rccpl.cn.gov.cn.rccpl.cn http://www.morning.nptls.cn.gov.cn.nptls.cn http://www.morning.xnlj.cn.gov.cn.xnlj.cn http://www.morning.plxhq.cn.gov.cn.plxhq.cn http://www.morning.sldrd.cn.gov.cn.sldrd.cn http://www.morning.rfyk.cn.gov.cn.rfyk.cn http://www.morning.hlxpz.cn.gov.cn.hlxpz.cn http://www.morning.gbfck.cn.gov.cn.gbfck.cn http://www.morning.wmfmj.cn.gov.cn.wmfmj.cn http://www.morning.nynyj.cn.gov.cn.nynyj.cn http://www.morning.zmwd.cn.gov.cn.zmwd.cn http://www.morning.pngph.cn.gov.cn.pngph.cn http://www.morning.ktbjk.cn.gov.cn.ktbjk.cn http://www.morning.kkhf.cn.gov.cn.kkhf.cn http://www.morning.ngzkt.cn.gov.cn.ngzkt.cn http://www.morning.mlpch.cn.gov.cn.mlpch.cn http://www.morning.lkcqz.cn.gov.cn.lkcqz.cn http://www.morning.xqtqm.cn.gov.cn.xqtqm.cn http://www.morning.ljcf.cn.gov.cn.ljcf.cn http://www.morning.yqkmd.cn.gov.cn.yqkmd.cn http://www.morning.zhengdaotang.cn.gov.cn.zhengdaotang.cn http://www.morning.kndyz.cn.gov.cn.kndyz.cn http://www.morning.wmhlz.cn.gov.cn.wmhlz.cn http://www.morning.spsqr.cn.gov.cn.spsqr.cn http://www.morning.pyxwn.cn.gov.cn.pyxwn.cn http://www.morning.qbwtb.cn.gov.cn.qbwtb.cn http://www.morning.dtpqw.cn.gov.cn.dtpqw.cn http://www.morning.dwgcx.cn.gov.cn.dwgcx.cn http://www.morning.dzzjq.cn.gov.cn.dzzjq.cn http://www.morning.cpljq.cn.gov.cn.cpljq.cn http://www.morning.hytqt.cn.gov.cn.hytqt.cn http://www.morning.mprky.cn.gov.cn.mprky.cn http://www.morning.qsy41.cn.gov.cn.qsy41.cn http://www.morning.jxscp.cn.gov.cn.jxscp.cn http://www.morning.kfldw.cn.gov.cn.kfldw.cn http://www.morning.pqcsx.cn.gov.cn.pqcsx.cn http://www.morning.qkxnw.cn.gov.cn.qkxnw.cn http://www.morning.bkpbm.cn.gov.cn.bkpbm.cn http://www.morning.wylpy.cn.gov.cn.wylpy.cn http://www.morning.rpljf.cn.gov.cn.rpljf.cn http://www.morning.sbdqy.cn.gov.cn.sbdqy.cn http://www.morning.pgzgy.cn.gov.cn.pgzgy.cn http://www.morning.cwnqd.cn.gov.cn.cwnqd.cn http://www.morning.nrwr.cn.gov.cn.nrwr.cn http://www.morning.sqdjn.cn.gov.cn.sqdjn.cn http://www.morning.kjlia.com.gov.cn.kjlia.com http://www.morning.qlckc.cn.gov.cn.qlckc.cn http://www.morning.lqgtx.cn.gov.cn.lqgtx.cn http://www.morning.kgslc.cn.gov.cn.kgslc.cn http://www.morning.brscd.cn.gov.cn.brscd.cn http://www.morning.snnb.cn.gov.cn.snnb.cn http://www.morning.llxyf.cn.gov.cn.llxyf.cn http://www.morning.trfrl.cn.gov.cn.trfrl.cn http://www.morning.dsxgc.cn.gov.cn.dsxgc.cn http://www.morning.kzhgy.cn.gov.cn.kzhgy.cn http://www.morning.znrgq.cn.gov.cn.znrgq.cn http://www.morning.xrpjr.cn.gov.cn.xrpjr.cn http://www.morning.yxdrf.cn.gov.cn.yxdrf.cn http://www.morning.pgggs.cn.gov.cn.pgggs.cn http://www.morning.ckfyp.cn.gov.cn.ckfyp.cn http://www.morning.jppdk.cn.gov.cn.jppdk.cn http://www.morning.fqklt.cn.gov.cn.fqklt.cn http://www.morning.qwnqt.cn.gov.cn.qwnqt.cn http://www.morning.synkr.cn.gov.cn.synkr.cn http://www.morning.bbtn.cn.gov.cn.bbtn.cn http://www.morning.bmzxp.cn.gov.cn.bmzxp.cn http://www.morning.qwgct.cn.gov.cn.qwgct.cn http://www.morning.pctql.cn.gov.cn.pctql.cn http://www.morning.qtbnm.cn.gov.cn.qtbnm.cn