Deselect

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m (Text replace - "</csharp>" to "</syntaxhighlight>")
m (Text replace - "<javascript>" to "<syntaxhighlight lang="javascript">")
Line 25: Line 25:
  
 
==Unity Javascript - DeselectAll.js==
 
==Unity Javascript - DeselectAll.js==
<javascript>
+
<syntaxhighlight lang="javascript">
 
// using UnityEngine; and using UnityEditor are ommited because
 
// using UnityEngine; and using UnityEditor are ommited because
 
// in Unity Javascript (from now js) they are set by default.  
 
// in Unity Javascript (from now js) they are set by default.  

Revision as of 20:48, 10 January 2012

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];
    }
}
</javascript>
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox