subscribe via rss
9 Feb 2010

[Unify Wiki] MultipleObjectsToLayer

Author: Unity3D News Pipe | Filed under: Technology

Summary:


By: Sommer.

== Description ==
Editor Utility that lets you move multiple selected objects into a layer at once.

Put this script into your project in the Editor folder. You will get the menu option Tools->Move selection to layer. Alternatively you can press CMD+ALT+L (CTRL+ALT+L on Windows) to open the window.

== Code ==
<csharp>
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;
}
}
}

</csharp>

2 Responses to “[Unify Wiki] MultipleObjectsToLayer”

  1. [...] site Bydesigngames a mis en ligne un script dédié à l’éditeur d’Unity qui va vous donner la [...]

  2. [...] post: [Unify Wiki] MultipleObjectsToLayer | ByDesign Games Share and [...]

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>