30 lines
887 B
C#
Raw Normal View History

2025-06-07 17:43:34 +08:00
using UnityEngine;
public static class LayerUtils
{
public static void SetAllChildsLayer(GameObject go, int layer, bool includeInactive = false)
{
var list = go.GetComponentsInChildren<Transform>(includeInactive);
for (int i = 0; i < list.Length; i++)
{
list[i].gameObject.layer = layer;
}
}
/// <summary>
/// 只修改Default层级
/// </summary>
/// <param name="go"></param>
/// <param name="layer"></param>
/// <param name="includeInactive"></param>
public static void SetAllChildDefLayer(GameObject go, int layer, bool includeInactive = false)
{
var list = go.GetComponentsInChildren<Transform>(includeInactive);
for (int i = 0; i < list.Length; i++)
{
if (list[i].gameObject.layer == 0)
list[i].gameObject.layer = layer;
}
}
}