DeleteComponentsInChildrenWizard

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Removing all content from page)
m (Text replace - "</csharp>" to "</syntaxhighlight>")
 
(2 intermediate revisions by one user not shown)
Line 1: Line 1:
 +
Author: Timo ([[:User:T|T]])
  
 +
== Description ==
 +
 +
This Wizard helps to delete a special type of components which are attached to the children of the selected Gameobject.
 +
 +
== Usage ==
 +
 +
You must place the script in a folder named '''Editor''' in your projects Assets folder for it to work properly.
 +
 +
Launch the Wizard and fill in the string of the type you want to delete.
 +
 +
== C# - DeleteComponentsInChildrenWizard.cs ==
 +
 +
<syntaxhighlight lang="csharp">using UnityEngine;
 +
using UnityEditor;
 +
using System.Collections;
 +
 +
 +
public class DeleteComponentsInChildrenWizard : ScriptableWizard
 +
{
 +
    public string typeString;
 +
   
 +
    [MenuItem ( "GameObject/Delete Components in Children Wizard" )]
 +
    static void DoSet()
 +
    {
 +
        ScriptableWizard.DisplayWizard("Set the string of type", typeof(DeleteComponentsInChildrenWizard), "Set");
 +
    }
 +
   
 +
    void OnWizardUpdate()
 +
    {
 +
        helpString = "Set the string of the Component type you want to delete:";
 +
    }
 +
   
 +
    void OnWizardCreate()
 +
    {
 +
    DeleteChildren();
 +
    }
 +
   
 +
    void DeleteChildren()
 +
    {
 +
        Transform[] allTransforms = Selection.GetTransforms( SelectionMode.Deep ); //Get all Children
 +
     
 +
      foreach( Transform eachTransform in allTransforms )
 +
      {
 +
      if ( eachTransform.GetComponent ( typeString ) != null )
 +
      {
 +
      Object.DestroyImmediate ( eachTransform.GetComponent (  typeString ) );
 +
      }
 +
      }
 +
    }
 +
}</syntaxhighlight>
 +
 +
[[Category: Wizard]]
 +
[[Category: ScriptableObject]]
 +
[[Category: C Sharp]]
 +
[[Category: Lights]]
 +
[[Category: Selection]]

Latest revision as of 20:45, 10 January 2012

Author: Timo (T)

[edit] Description

This Wizard helps to delete a special type of components which are attached to the children of the selected Gameobject.

[edit] Usage

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

Launch the Wizard and fill in the string of the type you want to delete.

[edit] C# - DeleteComponentsInChildrenWizard.cs

using UnityEngine;
using UnityEditor;
using System.Collections;
 
 
public class DeleteComponentsInChildrenWizard : ScriptableWizard
{
    public string typeString;
 
    [MenuItem ( "GameObject/Delete Components in Children Wizard" )]
    static void DoSet()
    {
        ScriptableWizard.DisplayWizard("Set the string of type", typeof(DeleteComponentsInChildrenWizard), "Set");
    }
 
    void OnWizardUpdate()
    {
        helpString = "Set the string of the Component type you want to delete:";
    }
 
    void OnWizardCreate()
    {
    	DeleteChildren();
    }
 
    void DeleteChildren()
    {
        	Transform[] allTransforms = Selection.GetTransforms( SelectionMode.Deep ); //Get all Children
 
       	foreach( Transform eachTransform in allTransforms )
       	{
       		if ( eachTransform.GetComponent ( typeString ) != null )
       		{
       			Object.DestroyImmediate ( eachTransform.GetComponent (  typeString ) );
       		}
       	}
    }
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox