Deselect

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m (Reverted edits by Joseph05408 (Talk); changed back to last version by Andrewp)
m (Text replace - "</javascript>" to "</syntaxhighlight>")
 
(4 intermediate revisions by 2 users not shown)
Line 11: Line 11:
  
 
==C# - DeselectAll.cs==
 
==C# - DeselectAll.cs==
<csharp>using UnityEngine;
+
<syntaxhighlight lang="csharp">using UnityEngine;
 
using UnityEditor;
 
using UnityEditor;
  
Line 22: Line 22:
 
     }
 
     }
 
}
 
}
</csharp>
+
</syntaxhighlight>
 +
 
 +
==Unity Javascript - DeselectAll.js==
 +
<syntaxhighlight lang="javascript">
 +
// 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];
 +
    }
 +
}
 +
</syntaxhighlight>

Latest revision as of 20:52, 10 January 2012

Author: Jonathan Czeck (aarku)

Contents

[edit] Description

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

[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# - DeselectAll.cs

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

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