SelectAllOfType

From Unify Community Wiki
Jump to: navigation, search

Author: Jonathan Czeck (aarku)

Description

This editor script sets the current selection in the Unity editor to be the specified class name, e.g. Transform or MyScript.

Usage

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

C# - SelectAllOfType.cs

using UnityEngine;
using UnityEditor;
using System.Collections;
 
public class SelectAllOfType : ScriptableWizard
{   
    public string className = "ExampleScript";
 
    [MenuItem ("Custom/Select/Select All of Type...")]
    public static void SelectAllOfTypeMenuIem()
    {
        ScriptableWizard.DisplayWizard("Select All of Type...", typeof(SelectAllOfType), "Select", "");
    }
 
    void OnWizardCreate()
    {
        Object[] objs = FindObjectsOfType(typeof(GameObject));
        ArrayList newSelectionBuilder = new ArrayList();
 
        foreach (GameObject go in objs)
        {
            Component comp = go.GetComponent(className);
            if (comp)
                newSelectionBuilder.Add(go);
        }
 
        GameObject[] newSelection = new GameObject[newSelectionBuilder.Count];
 
        for (int i=0; i < newSelectionBuilder.Count; i++)
            newSelection[i] = newSelectionBuilder[i] as GameObject;
 
        Selection.objects = newSelection;
    }
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Tools