SetLayerOfSelection

From Unify Community Wiki
Jump to: navigation, search

Author: Jonathan Czeck (aarku)

Contents

Description

This editor pops up a wizard window that will allow you to enter what number you would like to set your selection's layer to.

Usage

Place this script in YourProject/Assets/Editor and a menu item will automatically appear in the Custom menu after it is compiled.

Known Limitations

Unity does not provide a way currently to get a useful string from a layer name. Therefore, you will have to enter the number in manually rather than select from a popup of choices.

C# - SetLayerOfSelection.cs

using UnityEngine;
using UnityEditor;
 
public class SetLayerOfSelection : ScriptableWizard
{
    public int layer;
 
    [MenuItem ("Custom/Set Layer of Selection %l")]
    static void DoSet()
    {
        ScriptableWizard.DisplayWizard("Set Layer of Selection", typeof(SetLayerOfSelection), "Set");
 
    }
 
    void OnWizardUpdate()
    {
        helpString = "Set the layer of the objects in the selection to...";
    }
 
    void OnWizardCreate()
    {
        Object[] objs = Selection.GetFiltered(typeof(GameObject), SelectionMode.ExcludePrefab | SelectionMode.Editable);
 
        foreach (GameObject go in objs)
        {
            go.layer = layer;
        }
    }   
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Tools