Deselect

From Unify Community Wiki
Jump to: navigation, search

Author: Jonathan Czeck (aarku)

Contents

Description

This editor script sets the current selection to nothing. It deselects.

Usage

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

C# - DeselectAll.cs

using UnityEngine;
using UnityEditor;
 
public class DeselectAll : ScriptableObject
{
    [MenuItem ("Custom/Deselect All _a")]
    static void DoDeselect()
    {
        Selection.objects = new UnityEngine.Object[0];
    }
}

Unity Javascript - DeselectAll.js

// using UnityEngine; and using UnityEditor are ommited because
// in Unity Javascript (from now js) they are set by default. 
 
//public class DeselectAll : ScriptableObject
// public is set by default in js, the colon : in c# corresponds to extends keyword in js
 class DeselectAll extends ScriptableObject
{
// [MenuItem ("Custom/Deselect All _a")] instead of [] js uses the @
// "Custom/Deselect All defines the structure in the Menu, while _a defines the hotkey (a)
// we changed the hotkey in #d which means Shift+d
    @MenuItem ("Custom/Deselect All #d")
 
// static void DoDeselect() changes in static function DoDeselect 
// keyword void is not supported in js. To declare a method in a class 
// we must use the function keyword.
    static  function DoDeselect()
    {
        Selection.objects = new UnityEngine.Object[0];
    }
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Tools