DeleteComponentsInChildren

From Unify Community Wiki
Revision as of 19:17, 19 October 2009 by NCarter (Talk | contribs)

Jump to: navigation, search

Author: Timo (T)

Description

This Editor script 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.

Open the script with Unitron and change the string "GrassOnMeshGenerator" to a string of the type you want to delete...

C# - DeleteComponentsInChildren.cs

<csharp>using UnityEngine; using UnityEditor; using System.Collections;


public class DeleteComponentsInChildren : ScriptableObject {

   [MenuItem ( "GameObject/Delete Components in Children" )]
   static void MenuDeleteComponentsInChildren()
   {
       	Transform[] allTransforms = Selection.GetTransforms( SelectionMode.Deep ); //Get all Children
 		
      	foreach( Transform eachTransform in allTransforms )
      	{
      		//Change GrassOnMeshGenerator string to delete other Types
      		if ( eachTransform.GetComponent ( "GrassOnMeshGenerator" ) != null )
      		{
      			//Change GrassOnMeshGenerator string to delete other Types
      			Object.DestroyImmediate ( eachTransform.GetComponent (  "GrassOnMeshGenerator" ) );
      		}
      	}
   }

}</csharp>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox