Позволяет получить Bounds для дерева объектов.
Синтаксис:
Используется csharp
public static Bounds GetBoundsOfHierarchy(GameObject go)
{
Vector3 center = Vector3.zero;
Vector3 min = Vector3.zero, max = Vector3.zero;
int count = 0;
Bounds currB;
Vector3 currPos;
foreach (MeshFilter mf in go.GetComponentsInChildren<MeshFilter>())
{
currB = mf.sharedMesh.bounds;
currPos = mf.transform.position;
center += currB.center + mf.transform.position;
min.x = Mathf.Min(min.x, currB.min.x + currPos.x);
min.y = Mathf.Min(min.y, currB.min.y + currPos.y);
min.z = Mathf.Min(min.z, currB.min.z + currPos.z);
//
max.x = Mathf.Max(max.x, currB.max.x + currPos.x);
max.y = Mathf.Max(max.y, currB.max.y + currPos.y);
max.z = Mathf.Max(max.z, currB.max.z + currPos.z);
++count;
}
center /= count;
return new Bounds(center, max - min);
}
{
Vector3 center = Vector3.zero;
Vector3 min = Vector3.zero, max = Vector3.zero;
int count = 0;
Bounds currB;
Vector3 currPos;
foreach (MeshFilter mf in go.GetComponentsInChildren<MeshFilter>())
{
currB = mf.sharedMesh.bounds;
currPos = mf.transform.position;
center += currB.center + mf.transform.position;
min.x = Mathf.Min(min.x, currB.min.x + currPos.x);
min.y = Mathf.Min(min.y, currB.min.y + currPos.y);
min.z = Mathf.Min(min.z, currB.min.z + currPos.z);
//
max.x = Mathf.Max(max.x, currB.max.x + currPos.x);
max.y = Mathf.Max(max.y, currB.max.y + currPos.y);
max.z = Mathf.Max(max.z, currB.max.z + currPos.z);
++count;
}
center /= count;
return new Bounds(center, max - min);
}