/// 删除指定节点的所有子
/// </summary>
/// <param name="go"></param>
public static void ClearChildren(GameObject go, bool saveInactiveChild = false)
{
for (int i = 0; i < go.transform.childCount; i++)
{
GameObject child = go.transform.GetChild(i).gameObject;
if (saveInactiveChild && (!child.activeSelf))
{
continue;
}
GameObject.Destroy(child);
}
}
//创建子节点
public static GameObject AddChild(GameObject parent, GameObject prefab)
{
GameObject go = GameObject.Instantiate(prefab) as GameObject;
if (go != null && parent != null)
{
Transform t = go.transform;
t.transform.SetParent(parent.transform);
t.localPosition = Vector3.zero;
t.localRotation = Quaternion.identity;
t.localScale = Vector3.one;
go.layer = parent.layer;
}
return go;
}