SelectAllOfType

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Description)
m (Text replace - "</csharp>" to "</syntaxhighlight>")
 
(2 intermediate revisions by 2 users not shown)
Line 10: Line 10:
 
Place this script in ''YourProject/Assets/Editor'' and a menu item will automatically appear in the Custom menu after it is compiled.
 
Place this script in ''YourProject/Assets/Editor'' and a menu item will automatically appear in the Custom menu after it is compiled.
  
==C# - SelectAllLights.cs==
+
==C# - SelectAllOfType.cs==
<csharp>using UnityEngine;
+
<syntaxhighlight lang="csharp">using UnityEngine;
 
using UnityEditor;
 
using UnityEditor;
 
using System.Collections;
 
using System.Collections;
Line 44: Line 44:
 
         Selection.objects = newSelection;
 
         Selection.objects = newSelection;
 
     }
 
     }
}</csharp>
+
}</syntaxhighlight>

Latest revision as of 20:45, 10 January 2012

Author: Jonathan Czeck (aarku)

[edit] Description

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

[edit] Usage

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

[edit] 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
Toolbox