/// <summary>
/// Add a new child game object.
/// </summary>
static public GameObject AddChild (GameObject parent)
{
GameObject go = new GameObject();
if (parent != null)
{
Transform t = go.transform;
t.parent = parent.transform;
t.localPosition = Vector3.zero;
t.localRotation = Quaternion.identity;
t.localScale = Vector3.one;
go.layer = parent.layer;
}
return go;
}
/// <summary>
/// Add a collider to the game object containing one or more widgets.
/// </summary>
static public BoxCollider AddWidgetCollider (GameObject go)
{
if (go != null)
{
Collider col = go.GetComponent<Collider>();
BoxCollider box = col as BoxCollider;
if (box == null)
{
if (col != null)
{
if (Application.isPlaying) GameObject.Destroy(col);
else GameObject.DestroyImmediate(col);
}
box = go.AddComponent<BoxCollider>();
}
int depth = NGUITools.CalculateNextDepth(go);
Bounds b = NGUIMath.CalculateRelativeWidgetBounds(go.transform);
box.isTrigger = true;
box.center = b.center + Vector3.back * (depth * 0.25f);
box.size = new Vector3(b.size.x, b.size.y, 0f);
return box;
}
return null;
}