/// <summary>
/// Calculate the combined bounds of all widgets attached to the specified game object or its children (in relative-to-object space).
/// </summary>
static public Bounds CalculateRelativeWidgetBounds (Transform relativeTo, Transform content, bool considerInactive)
{
Bounds b
= new Bounds
(Vector3
.zero, Vector3
.zero);
if (content != null)
{
bool isSet = false;
Matrix4x4 toLocal = relativeTo.worldToLocalMatrix;
CalculateRelativeWidgetBounds(content, considerInactive, ref toLocal, ref b, ref isSet);
if (isSet) return b;
}
return b;
}
/// <summary>
/// Recursive function used to calculate the widget bounds.
/// </summary>
[System.Diagnostics.DebuggerHidden]
[System.Diagnostics.DebuggerStepThrough]
static void CalculateRelativeWidgetBounds (Transform content, bool considerInactive, ref Matrix4x4 toLocal, ref Bounds b, ref bool isSet)
{
if (content == null) return;
if (!considerInactive && !NGUITools.GetActive(content.gameObject)) return;
UIWidget w = content.GetComponent<UIWidget>();
if (w != null && w.enabled)
{
Vector3[] corners = w.worldCorners;
for (int j = 0; j < 4; ++j)
{
Vector3 v = toLocal.MultiplyPoint3x4(corners[j]);
if (isSet)
{
b.Encapsulate(v);
}
else
{
b
= new Bounds
(v, Vector3
.zero); isSet = true;
}
}
}
for (int i = 0, imax = content.childCount; i < imax; ++i)
{
Transform child = content.GetChild(i);
UIPanel p = child.GetComponent<UIPanel>();
if (p != null && p.clipping != UIDrawCall.Clipping.None)
{
Vector3[] corners = p.worldCorners;
for (int j = 0; j < 4; ++j)
{
Vector3 v = toLocal.MultiplyPoint3x4(corners[j]);
if (isSet)
{
b.Encapsulate(v);
}
else
{
b
= new Bounds
(v, Vector3
.zero); isSet = true;
}
}
}
else CalculateRelativeWidgetBounds(child, considerInactive, ref toLocal, ref b, ref isSet);
}
}