InvertSelection

From Unify Community Wiki
Jump to: navigation, search

Author: Mift (mift)

Description

This script inverts the editors hierarchy selection.

Usage

You must place the script in a folder named Editor in your project's Assets folder for it to work properly.

Unity main menu->Selection->Invert

C# - InvertSelection.cs

using System;
using UnityEngine;
using UnityEditor;
 
using System.Collections.Generic;
 
public class InvertSelection : ScriptableWizard {
 
 
    [MenuItem ("Selection/Invert")]
    static void static_InvertSelection() { 
 
		List< GameObject > oldSelection = new List< GameObject >();
		List< GameObject > newSelection = new List< GameObject >();
 
 
		foreach( GameObject obj in Selection.GetFiltered( typeof( GameObject ), SelectionMode.ExcludePrefab ) )
			oldSelection.Add( obj );
 
		foreach( GameObject obj in FindObjectsOfType( typeof( GameObject ) ) )
		{
			if ( !oldSelection.Contains( obj ) )
				newSelection.Add( obj );
		}
 
		Selection.objects = newSelection.ToArray();
 
    }
 
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox