ToggleActiveRecursively

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
 
(Added javascript version)
Line 2: Line 2:
 
[[Category: ScriptableObject]]
 
[[Category: ScriptableObject]]
 
[[Category: C Sharp]]
 
[[Category: C Sharp]]
 +
[[Category: Javascript]]
 
[[Category: Camera]]
 
[[Category: Camera]]
 
[[Category: Selection]]
 
[[Category: Selection]]
Author: Jonathan Czeck (aarku)
+
Original Author: Jonathan Czeck (aarku)
 +
Javascript version: Daniel Brauer
 
==Description==
 
==Description==
 
This editor script takes the current object selected in your hierarchy and toggles whether or not it is active.  Then it sets the activeness of all its children to this.
 
This editor script takes the current object selected in your hierarchy and toggles whether or not it is active.  Then it sets the activeness of all its children to this.
Line 27: Line 29:
  
 
</csharp>
 
</csharp>
 +
 +
==Javascript - ToggleActiveRecursively.js==
 +
<javascript>
 +
// Add menu item named "Toggle Active Recursively" to GameObject menu
 +
@MenuItem ("GameObject/Toggle Active Recursively %g")
 +
static function ToggleActiveRecursively() {
 +
var selectedTransforms : Transform[] = Selection.transforms;
 +
for (var currentTransform : Transform in selectedTransforms)
 +
currentTransform.gameObject.SetActiveRecursively(!currentTransform.gameObject.active);
 +
}
 +
 +
// The menu item will be disabled if no transform is selected.
 +
@MenuItem ("GameObject/Toggle Active Recursively %g", true)
 +
static function ValidateToggleActiveRecursively() : boolean {
 +
return Selection.transforms.length > 0;
 +
}
 +
</javascript>

Revision as of 22:14, 12 May 2007

Original Author: Jonathan Czeck (aarku) Javascript version: Daniel Brauer

Contents

Description

This editor script takes the current object selected in your hierarchy and toggles whether or not it is active. Then it sets the activeness of all its children to this.

Usage

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

C# - ToggleActiveRecursively.cs

<csharp>using UnityEngine; using UnityEditor;

public class ToggleActiveRecursively : ScriptableObject {

   [MenuItem ("Custom/Toggle Active And Send Recursively %i")]
   static void DoToggle()
   {
       GameObject activeGO = Selection.activeGameObject;
       
       activeGO.SetActiveRecursively(!activeGO.active);
   }

}

</csharp>

Javascript - ToggleActiveRecursively.js

<javascript> // Add menu item named "Toggle Active Recursively" to GameObject menu @MenuItem ("GameObject/Toggle Active Recursively %g") static function ToggleActiveRecursively() { var selectedTransforms : Transform[] = Selection.transforms; for (var currentTransform : Transform in selectedTransforms) currentTransform.gameObject.SetActiveRecursively(!currentTransform.gameObject.active); }

// The menu item will be disabled if no transform is selected. @MenuItem ("GameObject/Toggle Active Recursively %g", true) static function ValidateToggleActiveRecursively() : boolean { return Selection.transforms.length > 0; } </javascript>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox