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>
== 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>
[...] site Bydesigngames a mis en ligne un script dédié à l’éditeur d’Unity qui va vous donner la [...]
[...] post: [Unify Wiki] MultipleObjectsToLayer | ByDesign Games Share and [...]