版本 |
作者 |
参与者 |
完成日期 |
备注 |
UnityAPI_Transform_V01_1.0 |
严立钻 |
|
2020.06.07 |
|
|
|
|
|
|
立钻哥哥:Unity是一个入门快、提高难的游戏引擎,想要提升能力,至少需要越过3道坎:API+Shader+综合能力;++1、API的积累:对API的合理利用不仅可以减轻自己的编码负担,而且往往可以提高程序的运行效率;这也是钻哥开始“Unity API”独立打造分类的初衷; ++2、Shader编程:想要做出一款精品游戏往往需要有高效的Shader的支持;Unity提供了一套改良的“Shader Lab”系统,优化了繁杂的“Open GL”编程; ++3、综合能力(技术+业务+管理):一款产品的制作除了功能编程外,往往会涉及很多其他领域,例如产品架构、UI交互设计、模型制作等,作为主要的编程人员,对其他相关领域的了解程序往往会影响到产品制作直至最后的产品体验; ++++立钻哥哥一直在推动【VR云游戏=Unity+SteamVR+云技术+5G+AI】,这个只是一个引子,抛砖引玉让大家对整个知识体系有一个明确的落地方向,宝宝们可以根据自己的兴趣方向进行拓展:比如Unity这里是指一种“3D游戏引擎”,也可拓展至“UE4、Cocos2dx”等游戏引擎;SteamVR是一种跨硬件解决方案,也可拓展至“VRTK”等第三方插件;“云技术+5G”是一种跨平台解决方案的核心技术,同样可拓展至其他平台解决方案;AI也是一种先进技术的举例,也可以拓展至任何一种前沿技术; |
++++【Unity API】分类:https://blog.csdn.net/vrunsoftyanlz/category_7637520.html
++++【Unity开发基础】分类:https://blog.csdn.net/vrunsoftyanlz/category_7309057.html
++++【Linux系统编程】分类:https://blog.csdn.net/vrunsoftyanlz/category_9694767.html
++++【C++C铸就生存利器】分类:https://blog.csdn.net/vrunsoftyanlz/category_9325802.html
++++【人工智能AI2026】分类:https://blog.csdn.net/vrunsoftyanlz/category_9212024.html
++++【立钻哥哥CSDN空间】:https://blog.csdn.net/VRunSoftYanlz/
#Transform变换 |
#Transform变换++A1、Description描述++B2、Variables变量++C3、Public Function共有函数++D4、Message消息 |
#A1、Description描述 |
++++场景中的每一个对象都有一个Transform;用于储存并操控物体的位置、旋转和缩放;每一个Transform可以有一个父级,允许分层次应用位置、旋转和缩放;可以在Hierarchy面板查看层次关系;它们也支持计数器(enumerator),因此可以使用循环遍历子对象;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{
void MyTestFunc(){ foreach(Transform child in transform){ child.position += Vector3.up * 10.0F; } } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzTransform{} |
#B2、Variables变量 |
++B2、Variables变量++++B2.1、childCount++++B2.2、eulerAngles++++B2.3、forward++++B2.4、hasChanged++++B2.5、localEulerAngles++++B2.6、localPosition++++B2.7、localRotation++++B2.8、localScale++++B2.9、localToWorldMatrix++++B2.10、lossyScale++++B2.11、parent++++B2.12、position++++B2.13、right++++B2.14、root++++B2.15、rotation++++B2.16、up++++B2.17、worldToLoaclMatrix++++B2.18、YanlzXREngine.Transform.Variables |
++B2.1、childCount |
int childCount; |
++++该变换的子对象数量;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{
void MyTestFunc(){ Debug.Log(transform.childCount); } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzTransform{} |
++B2.2、eulerAngles |
Vector3 eulerAngles; |
++++此旋转作为欧拉角度;
++++x、y、z角代表绕z轴旋转z度,绕x轴旋转x度,绕y轴旋转y度(这个顺序);
++++仅使用这个变量读取和设置角度为绝对值;不要递增它们,当超过角度360度,它将错误;使用Transform.Rotate替代;
++++不要分别设置欧拉角其中一个轴(例如:eulerAngles.x=10;),因为这将导致偏移和不希望的旋转;当设置它们一个新的值时,要同时设置全部;Unity从存储在transform.localrotation的旋转自动转换角度;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{ public float yRotation = 5.0F;
void Update(){ yRotation += Input.GetAxis(“Horizontal”); transform.eulerAngles = new Vector3(10, yRotation, 0); } //立钻哥哥:void Update(){}
void MyTestFunc(){ Debug.Log(transform.eulerAngles.x); Debug.Log(transform.eulerAngles.y); Debug.Log(transform.eulerAngles.z); } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzTransform{} |
++B2.3、forward |
Vector3 forward; |
++++在世界空间坐标,变换的蓝色轴;也就是z轴;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{
void MyTestFunc(){ rigidbody.velocity = transform.forward * 10; } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzTransform{}
|
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{ public float angleBetween = 0.0F; public Transform target;
void Update(){ Vector3 targetDir = target.position - transform.position; angleBetween = Vector3.Angle(transform.forward, targetDir); } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzTransform{} |
++B2.4、hasChanged |
bool hasChanged; |
++++此变换自从上次标识是否被设置为false了?
++++对变换的任何改变会导致矩阵的重新计算:任意调节它的位置、旋转或缩放;请注意此操作,是否在设置此标识之前新旧的值不同,也将不会实际检查;因此,对于实例化,transform.position将总是设置此变换的hasChanged,无论是否有实际的变化;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{
void OnUpdate(){ if(transform.hasChanged){ Debug.Log(“立钻哥哥:The transform has changed!”); transform.hasChanged = false; } } //立钻哥哥:void OnUpdate(){}
} //立钻哥哥:public class YanlzTransform{} |
++B2.5、localEulerAngles |
Vector3 localEulerAngles; |
++++旋转作为欧拉角度,相对于父级的变换旋转;
++++x、y、z角代表绕z轴旋转z度,绕x轴旋转x度,绕y轴旋转y度(这个顺序);
++++仅使用这个变量读取和设置角度为绝对值;不要递增它们,当超过角度360度,它将错误;使用Transform.Rotate替代;
++++Unity从存储在transform.localrotation的旋转自动转换角度;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{
void MyTestFunc(){ Debug.Log(transform.localEulerAngles.x); Debug.Log(transform.localEulerAngles.y); Debug.Log(transform.localEulerAngles.z); } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzTransform{} |
++B2.6、localPosition |
Vector3 localPosition; |
++++相对于父级的变换的位置;
++++如果该变换没有父级,那么等同于Transform.position;
++++注意:当计算世界的位置时,父级变换的世界旋转和缩放被应用到自身的位置;意思是说Transform.position的1个单位是1个单位,Transform.localPosition的1个单位将由所有父级的缩放获得缩放,简单来说自身位置的1单位将受它所有上级的缩放影响;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{
void MyTestFunc(){ transform.localPosition = new Vector3(0, 0, 0); Debug.Log(transform.localPosition.y); } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzTransform{} |
++B2.7、localRotation |
Quaternion localRotation; |
++++该变换的旋转角度相对于父级变换的旋转角度;
++++Unity作为四元数存旋转角度;要旋转一个物体,使用Transform.Rotate,使用Transform.localEulerAngles为设置作为欧拉角的旋转角度;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{
void MyTestFunc(){ //transform.localPosition = new Vector3(0, 0, 0); transform.localRotation = Quaternion.identity; } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzTransform{} |
++B2.8、localScale |
Vector3 localScale; |
++++相对于父级变换的缩放;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{
void MyTestFunc(){ transform.localScale += new Vector3(0.1F, 0, 0); } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzTransform{} |
++B2.9、localToWorldMatrix |
Matrix4x4 localToWorldMatrix; |
++++变换点的矩阵从局部坐标到世界坐标(只读);
++++如果不熟悉使用矩阵为坐标转换,使用Transform.TransformPoint代替;
++++重要:如果设置shader参数,必须使用Renderer.localToWorldMatrix替代;
++B2.10、lossyScale |
Vector3 lossyScale; |
++++该对象的整体缩放(只读);
++++请注意:如果有一个带有缩放的父变换和有任意旋转的子变换,此缩放将有偏差;因此缩放不能正确的表示在3组件的向量,而是一个3*3矩阵;这样表示工作十分不方便,lossyScale是个很方便的属性,它尽量匹配实际世界缩放,如果物体不是有偏差的,这个值将是完全正确的,如果物体包含偏差,这个值也不会有很大的不同;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{
void MyTestFunc(){ Debug.Log(transform.lossyScale); } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzTransform{} |
++B2.11、parent |
Transform parent; |
++++该变换的父对象;
++++改变父对象,将修改相对父级的位置、缩放和旋转角度,但是保持和世界坐标的位置、旋转角度和缩放相同;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{ public Transform cameraTransform = Camera.main.transform;
void MyTestFunc(){ cameraTransform.parent = transform; cameraTransform.localPosition = -Vector3.forward * 5; cameraTransform.LookAt(transform); } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzTransform{}
|
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{
void MyTestFunc(){ transform.parent = null; } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzTransform{}
|
++B2.12、position |
Vector3 position; |
++++在世界空间坐标transform的位置;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{
void MyTestFunc(){ transform.position = new Vector3(0, 0, 0); Debug.Log(transform.position.x); } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzTransform{} |
++B2.13、right |
Vector3 right; |
++++在世界坐标空间,变换的红色轴;也就是x轴;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{
void MyTestFunc(){ rigidbody.velocity = transform.right * 10; } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzTransform{} |
++B2.14、root |
Transform root; |
++++返回最高层次的变换;
++++从来不返回null,如果这个变换没有父级,将返回自身;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{
void OnCollisionEnter(Collision collision){ if(collision.transform.root != transform.root){ Debug.Log(“立钻哥哥:The colliding objects are not in the same hierarchy.”); } } //立钻哥哥:void OnCollisionEnter(){}
} //立钻哥哥:public class YanlzTransform{} |
++B2.15、rotation |
Quaternion rotation; |
++++变换的旋转,在世界坐标空间储存为四元数;
++++Unity以四元数储存旋转角度;要旋转一个对象使用Transform.Rotate,使用Transform.eulerAngles以欧拉角设置旋转角度;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{
void MyTestFunc(){ transform.rotation = Quaternion.identity; } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzTransform{}
|
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{ public float smooth = 2.0F; public float tiltAngle = 30.0F;
void Update(){ float tiltAroundZ = Input.GetAxis(“Horizontal”) * tiltAngle; float tiltAroundX = Input.GetAxis(“Vertical”) * tiltAngle;
Quaternion target = Quaternion.Euler(tiltAroundX, 0, tiltAroundZ); transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth); } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzTransform{} |
++B2.16、up |
Vector3 up; |
++++在世界坐标空间,变换的绿色轴;也就是Y轴;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{
void MyTestFunc(){ //rigidbody.velocity = transform.right * 10; rigidbody.velocity = transform.up * 10; } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzTransform{} |
++B2.17、worldToLoaclMatrix |
Matrix4x4 worldToLocalMatrix; |
++++变换点的矩阵从世界坐标到局部坐标(只读);
++++如果不熟悉使用矩阵为坐标转换,使用Transform.TransformPoint代替;
++++重要:如果设置shader参数,必须使用Renderer.localToWorldMatrix替代;
#C3、Functions函数 |
++C3、Functions函数++++C3.1、DetachChildren++++C3.2、Find++++C3.3、GetChild++++C3.4、GetSiblingIndex++++C3.5、InverseTransformDirection++++C3.6、InverseTransformPoint++++C3.7、InverseTransformVector++++C3.8、IsChildOf++++C3.9、LookAt++++C3.10、Rotate++++C3.11、RotateAround++++C3.12、SetAsFirstSibling++++C3.13、SetAtLastSibling++++C3.14、SetParent++++C3.15、SetSiblingIndex++++C3.16、TransformDirection++++C3.17、TransformPoint++++C3.18、TransformVector++++C3.19、Translate++++C3.20、YanlzXREngine.Transform.Functions |
++C3.1、DetachChildren |
void DetachChildren(); |
++++所有子对象解除父子关系;
++++如果想要销毁层级的根,而不销毁子对象是很有用的;
++++参见:Transform.parent去分离/改变单个变换的父级;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{
void MyTestFunc(){ transform.DetachChildren(); Destroy(gameObject); } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzTransform{} |
++C3.2、Find |
Transform Find(string name); |
++++通过名字查找子对象并返回它;
++++如果没有查找到子对象名字,将返回null;如果名字包含“/”字符它将向路径一样穿越层次;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{ Transform aFinger;
void Start(){ aFinger = transform.Find(“YanlzTestModule/LeftShoulder/Arm/Hand/Finger”); } //立钻哥哥:void Start(){}
void Update(){ aFinger.Rotate(Time.deltaTime * 20, 0, 0); } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzTransform{} |
++C3.3、GetChild |
Transform GetChild(int index); |
++++[index]:要返回的子变换索引;必须小于该变换的Transform.childCount;
++++通过索引返回一个变换的子对象;
++C3.4、GetSiblingIndex |
int GetSiblingIndex(); |
++++获取该对象的同级索引;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{
void Start(){ Debug.Log(this.transform.GetSiblingIndex()); } //立钻哥哥:void Start(){}
} //立钻哥哥:public class YanlzTransform{} |
++C3.5、InverseTransformDirection |
Vector3 InverseTransformDirection(Vector3 direction);Vector3 InverseTransformDirection(float x, float y, float z); |
++++变换的方向从世界坐标转换到局部坐标;和Transform.TransformDirection相反;
++++变换方向x,y,z从世界坐标转换到局部坐标,和Transform.TransformDirection相反;
++++此操作不受缩放影响;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{
void MyTestFunc(){ relative = transform.InverseTransformDirection(Vector3.forward); Debug.Log(relative); } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzTransform{}
|
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{ private Vector3 relative;
void MyTestFunc(){ //relative = transform.InverseTransformDirection(Vector3.forward); relative = transform.InverseTransformDirection(0, 0, 1); Debug.Log(relative); } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzTransform{} |
++C3.6、InverseTransformPoint |
public Vector3 InverseTransformPoint(Vector3 position);public Vector3 InverseTransformPoint(float x, float y, float z); |
++++变换位置从世界坐标到局部坐标;和Transform.TransformPoint相反;
++++变换位置x,y,z从世界坐标到局部坐标;和Transform.TransformPoint相反;
++++注意:返回位置受缩放影响;如果是处理方向使用;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{ public Transform cam = Camera.main.transform; public Vector3 cameraRelative = cam.InverseTransformPoint(transform.position);
void MyTestFunc(){ if(cameraRelative.z > 0){ Debug.Log(“立钻哥哥:The object is in front of the camera.”); }else{ Debug.Log(“立钻哥哥:The object is behind the camera.”); } } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzTransform{}
|
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{
void MyTestFunc(){ relativePoint = transform.InverseTransformPoint(0, 0, 0);
if(cameraRelative.z > 0){ Debug.Log(“立钻哥哥:The world origin is in front of this object.”); }else{ Debug.Log(“立钻哥哥:The world origin is behind of this object.”); } } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzTransform{} |
++C3.7、InverseTransformVector |
public Vector3 InverseTransformVector(Vector3 vector);public Vector3 InverseTransformVector(float x, float y, float z); |
++++变换一个向量从世界坐标空间到局部坐标空间;这个操作与Transform.TransformVector相反;
++++变换一个向量(x,y,z)从世界坐标空间到局部坐标空间;这个操作与Transform.TransformVector相反;
++++这个操作受缩放影响;
++C3.8、IsChildOf |
bool IsChildOf(Transform parent); |
++++这个变换是parent的子对象;
++++返回布尔值,是指这个变换是否是指定变换的子对象;如果该变换是子物体、深层子物体(孩子的孩子)或者同级,返回真,否则返回假;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{
void OnTriggerEnter(Collider col){ if(col.transform.IsChildOf(transform)){ return; }
Debug.Log(“立钻哥哥:Do something here.”); } //立钻哥哥:void OnTriggerEnter(){}
} //立钻哥哥:public class YanlzTransform{} |
++C3.9、LookAt |
void LookAt(Transform target, Vector3 worldUp=Vector3.up);void LookAt(Vector3 worldPosition, Vector3 worldUp=Vector3.up); |
++++[target]:要指向的对象;
++++[worldUp]:向量指定的向上的方向;
++++[worldPosition]:要看向的点;
++++旋转此变换,让向前向量指向target的当前位置;简单说,旋转物体使z轴指向目标物体;
++++在由worldUp向量示意的方向的y轴旋转物体,如果忽略worldUp参数,这个函数将使用世界的y轴;worldUp只是一个示意向量,如果向前方向是与worldUp垂直的,旋转的向上向量将仅匹配worldUp向量;
++++当该物体设置了LookAt并指定了目标物体时,该物体的z轴将始终指向目标物体,在设置了worldUp轴向时,该物体在更接近指定的轴向时旋转变得灵活,注意:worldUp指的是世界空间,不论物体在什么位置,只要接近指定的轴方向,旋转会变得更灵活;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{ public Transform target;
void Update(){ //transform.LookAt(target); transform.LookAt(Vector3.zero); } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzTransform{} |
++C3.10、Rotate |
void Rotate(Vector3 eulerAngles, Space relativeTo=Space.Self);void Rotate(float xAngle, float yAngle, float zAngle, Space relativeTo=Space.Self);void Rotate(Vector3 axis, float angle, Space relativeTo=Space.Self); |
++++应用一个欧拉角的旋转角度,eulerAngles.z度围绕z轴,eulerAngles.x度围绕x轴,eulerAngles.y度围绕y轴(这样的顺序);
++++应用一个旋转角度,zAngle度围绕z轴,xAngle度围绕x轴,yAngle度围绕y轴(这样的顺序);
++++按照angle度围绕axis轴旋转变换;
++++如果相对于留空或者设置为Space.Self旋转角度被应用围绕变换的自身轴;(当在场景视图选择物体时,x、y和z轴显示),如果相对于Space.World旋转角度被应用围绕世界的x、y、z轴;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{
void Update(){ transform.Rotate(Vector3.right * Time.deltaTime); transform.Rotate(Vector3.up * Time.deltaTime, Space.World); } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzTransform{}
|
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{
void Update(){ transform.Rotate(Time.deltaTime, 0, 0); transform.Rotate(0, Time.deltaTime, 0, Space.World); } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzTransform{}
|
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{
void Update(){ transform.Rotate(Vector3.right, Time.deltaTime); transform.Rotate(Vector3.up, Time.deltaTime, Space.World); } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzTransform{} |
++C3.11、RotateAround |
void RotateAround(Vector3 point, Vector3 axis, float angle); |
++++围绕世界坐标的point点的axis旋转该变换angle度;
++++这个修改变换的位置和旋转角度;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{
void Update(){ transform.RotateAround(Vector3.zero, Vector3.up, 20 * Time.deltaTime); } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzTransform{} |
++C3.12、SetAsFirstSibling |
void SetAsFirstSibling(); |
++++移动该变换到此局部变换列表的开始;
++C3.13、SetAtLastSibling |
void SetAsLastSibling(); |
++++移动该变换到此局部变换列表的末尾;
++C3.14、SetParent |
public void SetParent(Transform parent, bool worldPositionStays); |
++++[parent]:要使用的父级变换;
++++[worldPositionStays]:如果为true,则相对于父级位置、缩放和旋转修改该对象,使得该对象保持与之前世界坐标空间一样的位置,旋转和缩放;
++++设置该变换的父级;
++++这个方法是把一个对象找个父级,如果worldPositionStays为true,那么该对象会保持世界坐标不变;如果为false那么该对象会保持局部坐标不变;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{ public Transform parent;
void Start(){ this.transform.SetParent(parent, false); } //立钻哥哥:void Start(){}
} //立钻哥哥:public class YanlzTransform{} |
++C3.15、SetSiblingIndex |
void SetSiblingIndex(int index); |
++++[index]:设置索引;
++++设置同级对象的索引;
++C3.16、TransformDirection |
Vector3 TransformDirection(Vector3 direction);Vector3 TransformDirection(float x, float y, float z); |
++++变换方向从局部坐标转换到世界坐标;
++++变换方向x,y,z从局部坐标到世界坐标;
++++这个操作不会受到变换的缩放和位置的影响;返回的向量与direction有同样的长度;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{ public Transform cam = Camera.main.transform;
public Vector3 cameraRelativeRight = cam.TransformDirection(Vector3.right); //public Vector3 cameraRelativeRight = cam.TransformDirection(1, 0, 0);
void MyTestFunc(){ rigidbody.AddForce(cameraRelativeRight * 10); } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzTransform{} |
++C3.17、TransformPoint |
Vector3 TransformPoint(Vector3 position);Vector3 TransformPoint(float x, float y, float z); |
++++变换位置从局部坐标到世界坐标;
++++变换位置x, y, z从局部坐标到世界坐标;
++++注意:返回位置受缩放影响;如果是处理方向使用;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{ public GameObject someObject;
public Vector3 thePosition = transform.TransformPoint(Vector3.right * 2); //public Vector3 thePosition = transform.TransformPoint(2, 0, 0);
void MyTestFunc(){ Instantiate(someObject, thePosition, someObject.transform.rotation) as GameObject; } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzTransform{} |
++C3.18、TransformVector |
public Vector3 TransformVector(Vector3 vector);public Vector3 TransformVector(float x, float y, float z); |
++++变换一个向量从局部坐标空间到世界坐标空间;
++++变换一个向量(x,y,z)从局部坐标空间到世界坐标空间;
++++这个操作不受变换位置的影响,但是受缩放的影响;
++C3.19、Translate |
void Translate(Vector3 translation, Space relativeTo=Space.Self);void Translate(float x, float y, float z, Space relativeTo=Space.Self);void Translate(Vector3 translation, Transform relativeTo);void Translate(float x, float y, float z, Transform relativeTo); |
++++移动transform在translation的方向和距离;
++++移动变换由x沿着x轴,y沿着y轴,z沿着z轴;
++++移动被应用相对于(relativeTo : Transform)的自身坐标系统;日光相对于为null,则移动被应用相对于世界坐标系统;
++++简单的说,向某方向移动物体多少距离;
++++如果relativeTo留空或者设置为Space.Self,移动被应用相对于变换的自身轴;(当在场景视图选择物体时,x、y和z轴显示)如果相对于Space.World移动被应用相对于世界坐标系统;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{
void Update(){ transform.Translate(Vector3.forward * Time.deltaTime); transform.Translate(Vector3.up * Time.deltaTime, Space.World); } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzTransform{}
|
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{
void Update(){ transform.Translate(0, 0, Time.deltaTime); transform.Translate(0, Time.deltaTime, 0, Space.World); } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzTransform{}
|
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzTransform : MonoBehaviour{
void Update(){ transform.Translate(Vector3.right * Time.deltaTime, Camera.main.transform); //transform.Translate(Time.deltaTime, 0, 0, Camera.main.transform); } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzTransform{}
|
#D4、立钻哥哥对Transform类的拓展 |
++++【Unity API】分类:https://blog.csdn.net/vrunsoftyanlz/category_7637520.html
++++【Unity开发基础】分类:https://blog.csdn.net/vrunsoftyanlz/category_7309057.html
++++【Linux系统编程】分类:https://blog.csdn.net/vrunsoftyanlz/category_9694767.html
++++【C++C铸就生存利器】分类:https://blog.csdn.net/vrunsoftyanlz/category_9325802.html
++++【人工智能AI2026】分类:https://blog.csdn.net/vrunsoftyanlz/category_9212024.html
++++【立钻哥哥CSDN空间】:https://blog.csdn.net/VRunSoftYanlz/
立钻哥哥推荐的拓展学习链接(Link_Url) |
++++立钻哥哥Unity 学习空间: http://blog.csdn.net/VRunSoftYanlz/
++++虚拟现实VR资讯: https://blog.csdn.net/VRunSoftYanlz/article/details/89165846
++++HTC_VIVE开发基础:https://blog.csdn.net/VRunSoftYanlz/article/details/81989970
++++Oculus杂谈:https://blog.csdn.net/VRunSoftYanlz/article/details/82469850
++++Oculus安装使用:https://blog.csdn.net/VRunSoftYanlz/article/details/82718982
++++Unity+SteamVR=>VR:https://blog.csdn.net/VRunSoftYanlz/article/details/88809370
++++Unity减少VR晕眩症:https://blog.csdn.net/VRunSoftYanlz/article/details/89115518
++++SteamVR简介:https://blog.csdn.net/VRunSoftYanlz/article/details/86484254
++++SteamVR脚本功能分析:https://blog.csdn.net/VRunSoftYanlz/article/details/86531480
++++SteamVR2.0开发指南:https://blog.csdn.net/VRunSoftYanlz/article/details/86618187
++++SteamVR2.2.0开发指南:https://blog.csdn.net/VRunSoftYanlz/article/details/88784527
++++SteamVR2.2.0快速入门:https://blog.csdn.net/VRunSoftYanlz/article/details/88833579
++++SteamVR2.2.0交互系统:https://blog.csdn.net/VRunSoftYanlz/article/details/89199778
++++SteamVR2.2.0传送机制:https://blog.csdn.net/VRunSoftYanlz/article/details/89390866
++++SteamVR2.2.0教程(一):https://blog.csdn.net/VRunSoftYanlz/article/details/89324067
++++SteamVR2.2.0教程(二):https://blog.csdn.net/VRunSoftYanlz/article/details/89894097
++++SteamVR_Skeleton_Poser:https://blog.csdn.net/VRunSoftYanlz/article/details/89931725
++++SteamVR实战之PMCore:https://blog.csdn.net/VRunSoftYanlz/article/details/89463658
++++SteamVR/Extras:https://blog.csdn.net/VRunSoftYanlz/article/details/86584108
++++SteamVR/Input:https://blog.csdn.net/VRunSoftYanlz/article/details/86601950
++++OpenXR简介:https://blog.csdn.net/VRunSoftYanlz/article/details/85726365
++++VRTK杂谈:https://blog.csdn.net/VRunSoftYanlz/article/details/82562993
++++VRTK快速入门(杂谈):https://blog.csdn.net/VRunSoftYanlz/article/details/82955267
++++VRTK官方示例(目录):https://blog.csdn.net/VRunSoftYanlz/article/details/82955410
++++VRTK代码结构(目录):https://blog.csdn.net/VRunSoftYanlz/article/details/82780085
++++VRTK(SceneResources):https://blog.csdn.net/VRunSoftYanlz/article/details/82795400
++++VRTK_ControllerEvents:https://blog.csdn.net/VRunSoftYanlz/article/details/83099512
++++VRTK_InteractTouch:https://blog.csdn.net/VRunSoftYanlz/article/details/83120220
++++虚拟现实行业应用:https://blog.csdn.net/VRunSoftYanlz/article/details/88360157
++++Steam平台上的VR:https://blog.csdn.net/VRunSoftYanlz/article/details/88960085
++++Steam平台热销VR:https://blog.csdn.net/VRunSoftYanlz/article/details/89007741
++++VR实验:以太网帧的构成:https://blog.csdn.net/VRunSoftYanlz/article/details/82598140
++++实验四:存储器扩展实验:https://blog.csdn.net/VRunSoftYanlz/article/details/87834434
++++FrameVR示例V0913:https://blog.csdn.net/VRunSoftYanlz/article/details/82808498
++++FrameVR示例V1003:https://blog.csdn.net/VRunSoftYanlz/article/details/83066516
++++SwitchMachineV1022:https://blog.csdn.net/VRunSoftYanlz/article/details/83280886
++++PlaySceneManagerV1022:https://blog.csdn.net/VRunSoftYanlz/article/details/83280886
++++Unity5.x用户手册:https://blog.csdn.net/VRunSoftYanlz/article/details/81712741
++++Unity面试题ABC:https://blog.csdn.net/vrunsoftyanlz/article/details/78630687
++++Unity面试题D:https://blog.csdn.net/VRunSoftYanlz/article/details/78630838
++++Unity面试题E:https://blog.csdn.net/vrunsoftyanlz/article/details/78630913
++++Unity面试题F:https://blog.csdn.net/VRunSoftYanlz/article/details/78630945
++++Cocos2dx面试题:https://blog.csdn.net/VRunSoftYanlz/article/details/78630967
++++禅道[zentao]:https://blog.csdn.net/VRunSoftYanlz/article/details/83964057
++++Lua快速入门篇(Xlua拓展):https://blog.csdn.net/VRunSoftYanlz/article/details/81173818
++++Lua快速入门篇(XLua教程):https://blog.csdn.net/VRunSoftYanlz/article/details/81141502
++++Lua快速入门篇(基础概述):https://blog.csdn.net/VRunSoftYanlz/article/details/81041359
++++框架知识点:https://blog.csdn.net/VRunSoftYanlz/article/details/80862879
++++游戏框架(UI框架夯实篇):https://blog.csdn.net/vrunsoftyanlz/article/details/80781140
++++游戏框架(初探篇):https://blog.csdn.net/VRunSoftYanlz/article/details/80630325
++++.Net框架设计:https://blog.csdn.net/VRunSoftYanlz/article/details/87401225
++++从零开始学架构:https://blog.csdn.net/VRunSoftYanlz/article/details/88095895
++++设计模式简单整理:https://blog.csdn.net/vrunsoftyanlz/article/details/79839641
++++专题:设计模式(精华篇):https://blog.csdn.net/VRunSoftYanlz/article/details/81322678
++++U3D小项目参考:https://blog.csdn.net/vrunsoftyanlz/article/details/80141811
++++Unity小游戏算法分析:https://blog.csdn.net/VRunSoftYanlz/article/details/87908365
++++Unity案例(Vehicle):https://blog.csdn.net/VRunSoftYanlz/article/details/82355876
++++UML类图:https://blog.csdn.net/vrunsoftyanlz/article/details/80289461
++++PowerDesigner简介:https://blog.csdn.net/VRunSoftYanlz/article/details/86500084
++++Unity知识点0001:https://blog.csdn.net/vrunsoftyanlz/article/details/80302012
++++Unity知识点0008:https://blog.csdn.net/VRunSoftYanlz/article/details/81153606
++++U3D_Shader编程(第一篇:快速入门篇):https://blog.csdn.net/vrunsoftyanlz/article/details/80372071
++++U3D_Shader编程(第二篇:基础夯实篇):https://blog.csdn.net/vrunsoftyanlz/article/details/80372628
++++Unity引擎基础:https://blog.csdn.net/vrunsoftyanlz/article/details/78881685
++++Unity面向组件开发:https://blog.csdn.net/vrunsoftyanlz/article/details/78881752
++++Unity物理系统:https://blog.csdn.net/vrunsoftyanlz/article/details/78881879
++++Unity2D平台开发:https://blog.csdn.net/vrunsoftyanlz/article/details/78882034
++++UGUI基础:https://blog.csdn.net/vrunsoftyanlz/article/details/78884693
++++UGUI进阶:https://blog.csdn.net/vrunsoftyanlz/article/details/78884882
++++UGUI综合:https://blog.csdn.net/vrunsoftyanlz/article/details/78885013
++++Unity动画系统基础:https://blog.csdn.net/vrunsoftyanlz/article/details/78886068
++++Unity动画系统进阶:https://blog.csdn.net/vrunsoftyanlz/article/details/78886198
++++Navigation导航系统:https://blog.csdn.net/vrunsoftyanlz/article/details/78886281
++++Unity特效渲染:https://blog.csdn.net/vrunsoftyanlz/article/details/78886403
++++Unity数据存储:https://blog.csdn.net/vrunsoftyanlz/article/details/79251273
++++Unity中Sqlite数据库:https://blog.csdn.net/vrunsoftyanlz/article/details/79254162
++++WWW类和协程:https://blog.csdn.net/vrunsoftyanlz/article/details/79254559
++++Unity网络:https://blog.csdn.net/vrunsoftyanlz/article/details/79254902
++++Unity资源加密:https://blog.csdn.net/VRunSoftYanlz/article/details/87644514
++++PhotonServer简介:https://blog.csdn.net/VRunSoftYanlz/article/details/86652770
++++编写Photon游戏服务器:https://blog.csdn.net/VRunSoftYanlz/article/details/86682935
++++C#事件:https://blog.csdn.net/vrunsoftyanlz/article/details/78631267
++++C#委托:https://blog.csdn.net/vrunsoftyanlz/article/details/78631183
++++C#集合:https://blog.csdn.net/vrunsoftyanlz/article/details/78631175
++++C#泛型:https://blog.csdn.net/vrunsoftyanlz/article/details/78631141
++++C#接口:https://blog.csdn.net/vrunsoftyanlz/article/details/78631122
++++C#静态类:https://blog.csdn.net/vrunsoftyanlz/article/details/78630979
++++C#中System.String类:https://blog.csdn.net/vrunsoftyanlz/article/details/78630945
++++C#数据类型:https://blog.csdn.net/vrunsoftyanlz/article/details/78630913
++++Unity3D默认的快捷键:https://blog.csdn.net/vrunsoftyanlz/article/details/78630838
++++游戏相关缩写:https://blog.csdn.net/vrunsoftyanlz/article/details/78630687
++++UnityAPI.Rigidbody刚体:https://blog.csdn.net/VRunSoftYanlz/article/details/81784053
++++UnityAPI.Material材质:https://blog.csdn.net/VRunSoftYanlz/article/details/81814303
++++UnityAPI.Android安卓:https://blog.csdn.net/VRunSoftYanlz/article/details/81843193
++++UnityAPI.AndroidJNI安卓JNI:https://blog.csdn.net/VRunSoftYanlz/article/details/81879345
++++UnityAPI.Transform变换:https://blog.csdn.net/VRunSoftYanlz/article/details/81916293
++++UnityAPI.WheelCollider轮碰撞器:https://blog.csdn.net/VRunSoftYanlz/article/details/82356217
++++UnityAPI.Resources资源:https://blog.csdn.net/VRunSoftYanlz/article/details/83155518
++++JSON数据结构:https://blog.csdn.net/VRunSoftYanlz/article/details/82026644
++++CocosStudio快速入门:https://blog.csdn.net/VRunSoftYanlz/article/details/82356839
++++Unity企业内训(目录):https://blog.csdn.net/VRunSoftYanlz/article/details/82634668
++++Unity企业内训(第1讲):https://blog.csdn.net/VRunSoftYanlz/article/details/82634733
++++Unity企业内训(第2讲):https://blog.csdn.net/VRunSoftYanlz/article/details/82861180
++++Unity企业内训(第3讲):https://blog.csdn.net/VRunSoftYanlz/article/details/82927699
++++Unity企业内训(第4讲):https://blog.csdn.net/VRunSoftYanlz/article/details/83479776
++++Unity企业内训(第5讲):https://blog.csdn.net/VRunSoftYanlz/article/details/83963811
++++Unity企业内训(第6讲):https://blog.csdn.net/VRunSoftYanlz/article/details/84207696
++++钻哥带您了解产品原型:https://blog.csdn.net/VRunSoftYanlz/article/details/87303828
++++插件
++++计算机组成原理(教材篇):https://blog.csdn.net/VRunSoftYanlz/article/details/82719129
++++5G接入:云计算和雾计算:https://blog.csdn.net/VRunSoftYanlz/article/details/88372718
++++云计算通俗讲义:https://blog.csdn.net/VRunSoftYanlz/article/details/88652803
++++立钻哥哥Unity 学习空间: http://blog.csdn.net/VRunSoftYanlz
--_--VRunSoft:lovezuanzuan--_--