30 lines
887 B
C#
30 lines
887 B
C#
|
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;
|
||
|
}
|
||
|
}
|
||
|
}
|