using UnityEngine; using UnityEditor; public class MultipleObjectsToLayer : EditorWindow { static int selection = 0; static bool includeChildren = true; [MenuItem ("Tools/Move selection to layer %&l")] public static void Run () { if (Selection.gameObjects.Length > 0) { GetWindow (typeof (MultipleObjectsToLayer)).Show (); } } void OnGUI () { GUILayout.Label ("Move selection to layer", EditorStyles.boldLabel); includeChildren = GUILayout.Toggle(includeChildren, "Include children"); selection = EditorGUILayout.LayerField(selection); if (GUILayout.Button("Move to layer")) { MoveSelectionToLayer(); } } static void MoveSelectionToLayer() { Object[] selectedObjects; if (includeChildren) { selectedObjects = Selection.GetFiltered(typeof(GameObject), SelectionMode.Deep); } else { selectedObjects = Selection.GetFiltered(typeof(GameObject), SelectionMode.TopLevel); } foreach (GameObject go in selectedObjects) { go.layer = selection; } } }