本文整理汇总了C#中UnityEngine.Transform.TransformVector方法的典型用法代码示例。如果您正苦于以下问题:C# Transform.TransformVector方法的具体用法?C# Transform.TransformVector怎么用?C# Transform.TransformVector使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Transform
的用法示例。
在下文中一共展示了Transform.TransformVector方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SplitAndGetObject
public void SplitAndGetObject(Transform firstGraberTrans, Transform secondGraberTrans, Transform objectInHandTrans, out Rigidbody firstFirstObject, out Rigidbody secondFirstObject)
{
firstFirstObject = null;
secondFirstObject = null;
GameObject obj;
switch (SplitType)
{
case SplitTypes.PreSpawnedSplitObject:
Splited = true;
secondFirstObject = PreSpawnedObject.AddComponent<Rigidbody>();
break;
case SplitTypes.SpawnOnSplit:
obj = Instantiate(SplitObjectPrefab);
secondFirstObject = obj.GetComponent<Rigidbody>();
secondFirstObject.isKinematic = true;
obj.transform.localRotation = secondGraberTrans.localRotation;
obj.transform.position = objectInHandTrans.position - objectInHandTrans.TransformVector(SpawnOffset);
break;
case SplitTypes.SpawnNewOnSplit:
Splited = true;
obj = Instantiate(FirstSplitObject);
firstFirstObject = obj.GetComponent<Rigidbody>();
firstFirstObject.isKinematic = true;
obj.transform.localRotation = Quaternion.identity;
obj.transform.position = objectInHandTrans.position - objectInHandTrans.TransformVector(FirstSpawnOffset);
obj = Instantiate(SecondSplitObject);
secondFirstObject = obj.GetComponent<Rigidbody>();
secondFirstObject.isKinematic = true;
obj.transform.localRotation = Quaternion.identity;
obj.transform.position = objectInHandTrans.position - objectInHandTrans.TransformVector(SecondSpawnOffset);
break;
}
}
示例2: CovertToWorldSpace
static void CovertToWorldSpace (ref Mesh originalMesh, Transform meshTransform)
{
Vector3[] newVertices = new Vector3[originalMesh.vertexCount];
Vector3[] newNormals = new Vector3[originalMesh.vertexCount];
Vector4[] newTangents = new Vector4[originalMesh.vertexCount];
for (int i = 0; i < originalMesh.vertexCount; i++)
{
newVertices[i] = meshTransform.TransformPoint(originalMesh.vertices[i]);
newNormals[i] = meshTransform.TransformVector(originalMesh.normals[i]);
newTangents[i] = meshTransform.TransformVector(originalMesh.tangents[i]);
}
originalMesh.vertices = newVertices;
originalMesh.normals = newNormals;
originalMesh.tangents = newTangents;
}
示例3: FixObj
public void FixObj(Transform obj)
{
try {
// rotate to (0,0,0) without changing how it looks
MeshFilter mf = obj.GetComponent<MeshFilter>();
Mesh m = (mf?mf.mesh:null);
if (m) {
// convert vertices to Quaternion.Identity
Transform parent = obj.parent;
obj.parent = null;
Vector3[] verts = m.vertices;
for (int i=0; i<verts.Length; ++i)
verts[i] = Vector3.Scale(
obj.TransformVector(verts[i]),
new Vector3(1/obj.localScale.x, 1/obj.localScale.y, 1/obj.localScale.z));
// convert vertices to the final rotation
Vector3 v1 = obj.TransformDirection(Vector3.right);
Vector3 v2 = obj.lossyScale;
float angle = Mathf.Atan2(v1.y, v1.x);
for (int i=0; i<verts.Length; ++i)
verts[i] = new Vector3(
Mathf.Cos(-angle)*verts[i].x*v2.x/v2.x - Mathf.Sin(-angle)*verts[i].y*v2.y/v2.x,
Mathf.Sin(-angle)*verts[i].x*v2.x/v2.y + Mathf.Cos(-angle)*verts[i].y*v2.y/v2.y,
verts[i].z);
// finalize rotation
obj.eulerAngles = new Vector3(0, 0, angle*180/Mathf.PI);
//obj.rotation = Quaternion.identity;
obj.parent = parent;
m.vertices = verts;
m.RecalculateNormals();
m.RecalculateBounds();
// update collider
BoxCollider boxColl3d = obj.GetComponent<BoxCollider>();
if (boxColl3d)
throw new Exception("Rotator2D Doesn't Work with 3D Colliders");
BoxCollider2D boxColl = obj.GetComponent<BoxCollider2D>();
if (boxColl) {
boxColl.size = m.bounds.size;
boxColl.offset = m.bounds.center;
}
} else {
Transform parent = obj.parent;
obj.parent = null;
Vector3 v = obj.TransformDirection(Vector3.right);
float angle = Mathf.Atan2(v.y, v.x);
obj.eulerAngles = new Vector3(0, 0, angle*180/Mathf.PI);
obj.parent = parent;
}
} catch (Exception e) {
Debug.LogWarning("Error processing an object:\n\n"+e.Message);
}
}
示例4: IsClothParticleFacingCamera
/**
* Return whether all physical vertices at the particle should are culled or not. If at least one is not culled, the particle is visible.
*/
private bool IsClothParticleFacingCamera(Transform clothTransform,Camera cam, Vector3[] meshNormals, int particleIndex, Vector3 particleWorldPosition)
{
if (cam == null || clothTransform == null) return false;
if (particleIndex < cloth.edgeStructure.heVertices.Count){
HalfEdge.HEVertex vertex = cloth.edgeStructure.heVertices[particleIndex];
foreach(int index in vertex.physicalIDs){
if (Vector3.Dot(clothTransform.TransformVector(meshNormals[index]),cam.transform.position - particleWorldPosition) > 0)
return true;
}
}
return false;
}
示例5: TTVector
/*
* Transform to Transform Vector
*/
public static Vector3 TTVector(Vector3 vector, Transform fromParent, Transform toParent)
{
return toParent.InverseTransformVector(fromParent.TransformVector(vector));
}
示例6: DrawBox
public static void DrawBox(Bounds bounds, Transform transform = null)
{
Vector3 center = bounds.center;
// Calculate each of the transformed axis with their corresponding length
Vector3 up = Vector3.up * bounds.extents.y;
Vector3 right = Vector3.right * bounds.extents.x;
Vector3 forward = Vector3.forward * bounds.extents.z;
if(transform != null)
{
center = transform.TransformPoint(bounds.center);
// Calculate each of the transformed axis with their corresponding length
up = transform.TransformVector(Vector3.up) * bounds.extents.y;
right = transform.TransformVector(Vector3.right) * bounds.extents.x;
forward = transform.TransformVector(Vector3.forward) * bounds.extents.z;
}
// Verticals
GL.Vertex(center - right - forward + up);
GL.Vertex(center - right - forward - up);
GL.Vertex(center - right + forward + up);
GL.Vertex(center - right + forward - up);
GL.Vertex(center + right - forward + up);
GL.Vertex(center + right - forward - up);
GL.Vertex(center + right + forward + up);
GL.Vertex(center + right + forward - up);
// Horizontal - forward/back
GL.Vertex(center - right + forward - up);
GL.Vertex(center - right - forward - up);
GL.Vertex(center + right + forward - up);
GL.Vertex(center + right - forward - up);
GL.Vertex(center - right + forward + up);
GL.Vertex(center - right - forward + up);
GL.Vertex(center + right + forward + up);
GL.Vertex(center + right - forward + up);
// Horizontal - right/left
GL.Vertex(center + right - forward - up);
GL.Vertex(center - right - forward - up);
GL.Vertex(center + right + forward - up);
GL.Vertex(center - right + forward - up);
GL.Vertex(center + right - forward + up);
GL.Vertex(center - right - forward + up);
GL.Vertex(center + right + forward + up);
GL.Vertex(center - right + forward + up);
}
示例7: RelativeMovePosition
/// <summary>
/// 相对位移后position
/// </summary>
/// <returns>The move.</returns>
/// <param name="movement">Movement.</param>
/// <param name="trans">Trans.</param>
public static Vector3 RelativeMovePosition(Vector3 movement, Transform trans)
{
Vector3 origin = new Vector3 (trans.localPosition.x, trans.localPosition.y, trans.localPosition.z);
//目标受击点
Vector3 targetLocal = new Vector3 (origin.x + movement.x, origin.y + movement.y, origin.z + movement.z);
Vector3 targetScreen = trans.TransformVector (targetLocal);
return targetScreen;
}
示例8: TransformVectorFromTo
/// <summary>
/// Takes a vectpr in the coordinate space specified by the "from" transform and transforms it to be the correct direction in the coordinate space specified by the "to" transform
/// applies rotation and scale, no translation
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
/// <param name="vecInFrom"></param>
/// <returns></returns>
public static Vector3 TransformVectorFromTo(Transform from, Transform to, Vector3 vecInFrom)
{
Vector3 vecInWorld = (from == null) ? vecInFrom : from.TransformVector(vecInFrom);
Vector3 vecInTo = (to == null) ? vecInWorld : to.InverseTransformVector(vecInWorld);
return vecInTo;
}
示例9: Mirror
public static Vector3 Mirror(Vector3 v, Transform root)
{
Vector3 local = root.InverseTransformVector(v);
return root.TransformVector(-local.x, local.y, local.z);
}