本文整理汇总了C#中UnityEngine.Transform.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# Transform.Contains方法的具体用法?C# Transform.Contains怎么用?C# Transform.Contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Transform
的用法示例。
在下文中一共展示了Transform.Contains方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChooseNearbyModelTransforms
public static Transform[] ChooseNearbyModelTransforms(Part p, List<AttachNode> attachNodeGroup, Vector2 bounds, Transform[] PartModelTransforms, Transform[] AllVesselModelTransforms)
{
Vector3 nodeUpVector = Vector3.zero;
Vector3 nodeCenter = Vector3.zero;
float avgNodeDistFromCenter = 0;
foreach (AttachNode attach in attachNodeGroup)
{
nodeUpVector += attach.orientation;
nodeCenter += attach.position;
}
nodeUpVector.Normalize();
nodeCenter /= attachNodeGroup.Count;
foreach (AttachNode attach in attachNodeGroup)
{
avgNodeDistFromCenter += (attach.position - nodeCenter).magnitude;
}
avgNodeDistFromCenter /= attachNodeGroup.Count;
Quaternion partToNode = Quaternion.FromToRotation(Vector3.up, nodeUpVector); //This is the angle between part up and the node
Quaternion rot = Quaternion.Inverse(partToNode);
Matrix4x4 partToNodeMatrix = Matrix4x4.TRS(Vector3.zero, rot, Vector3.one);
Matrix4x4 upMatrix = partToNodeMatrix * p.transform.worldToLocalMatrix;
nodeCenter = partToNodeMatrix.MultiplyPoint(nodeCenter);
Vector3 worldNodeVector = nodeUpVector;
if (Vector3.Dot(nodeUpVector, nodeCenter) < 0) //Make sure the direction is correct
worldNodeVector = -worldNodeVector;
worldNodeVector = (p.transform.localToWorldMatrix * Matrix4x4.TRS(Vector3.zero, partToNode, Vector3.one)).MultiplyVector(worldNodeVector);
List<Transform> FinalModelTransforms = new List<Transform>();
foreach(Transform t in AllVesselModelTransforms)
{
if (PartModelTransforms.Contains(t) || Vector3.Dot(t.position, worldNodeVector) < -0.2f) //Can't be part of this part, nor can it be really far behind us
continue;
MeshFilter mf = t.GetComponent<MeshFilter>();
if (mf == null)
continue;
Mesh m = mf.mesh;
if (m == null)
continue;
Matrix4x4 orientMatrix = upMatrix * t.localToWorldMatrix;
Vector3 locMaxBounds = orientMatrix.MultiplyPoint(m.bounds.max) - nodeCenter;
Vector3 locMinBounds = orientMatrix.MultiplyPoint(m.bounds.min) - nodeCenter;
if (locMaxBounds.x < locMinBounds.x)
{
float tmp = locMinBounds.x;
locMinBounds.x = locMaxBounds.x;
locMaxBounds.x = tmp;
}
if (locMaxBounds.y < locMinBounds.y)
{
float tmp = locMinBounds.y;
locMinBounds.y = locMaxBounds.y;
locMaxBounds.y = tmp;
}
if (locMaxBounds.z < locMinBounds.z)
{
float tmp = locMinBounds.z;
locMinBounds.z = locMaxBounds.z;
locMaxBounds.z = tmp;
}
/*foreach (Vector3 vertex in m.vertices)
{
Vector3 v = orientMatrix.MultiplyPoint(vertex) - nodeCenter;
locMaxBounds.x = Mathf.Max(locMaxBounds.x, v.x);
locMinBounds.x = Mathf.Min(locMinBounds.x, v.x);
locMaxBounds.y = Mathf.Max(locMaxBounds.y, v.y);
locMinBounds.y = Mathf.Min(locMinBounds.y, v.y);
locMaxBounds.z = Mathf.Max(locMaxBounds.z, v.z);
locMinBounds.z = Mathf.Min(locMinBounds.z, v.z);
}*/
if (locMaxBounds.x > -avgNodeDistFromCenter && locMaxBounds.y > -0.5f && locMaxBounds.z > -avgNodeDistFromCenter && locMinBounds.x < avgNodeDistFromCenter && locMinBounds.y < 0.5f && locMinBounds.z < avgNodeDistFromCenter)
FinalModelTransforms.Add(t);
}
return FinalModelTransforms.ToArray();
}