DeleteComponentsInChildren

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Removing all content from page)
m (Reverted edits by Joseph05408 (Talk); changed back to last version by T)
Line 1: Line 1:
 +
Author: Timo ([[:User:T|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>
 +
 +
[[Category:Editor Scripts]]
 +
[[Category:ScriptableObject]]
 +
[[Category:C Sharp]]

Revision as of 19:17, 19 October 2009

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