File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
Assets/Scripts/Editor/BatchTools Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ // Renames child gameobjects in hierarchy (by replacting strings)
2+ // open wizard from GameObject/MassRenameChildren menu item
3+
4+ using UnityEditor ;
5+ using UnityEngine ;
6+
7+ namespace UnityLibrary
8+ {
9+ public class MassRenameChildren : ScriptableWizard
10+ {
11+ public string findString = "" ;
12+ public string replaceWith = "" ;
13+
14+ [ MenuItem ( "GameObject/Mass Rename Children" ) ]
15+ static void CreateWizard ( )
16+ {
17+ DisplayWizard < MassRenameChildren > ( "MassRenamer" , "Apply" ) ;
18+ }
19+
20+ // user clicked create button
21+ void OnWizardCreate ( )
22+ {
23+ if ( Selection . activeTransform == null || findString == "" )
24+ {
25+ Debug . Log ( name + " Select Root Transform and set FindString first.." ) ;
26+ return ;
27+ }
28+
29+ // get all children for the selection, NOTE: includeInactive is true, so disabled objects will get selected also
30+ Transform [ ] allChildren = Selection . activeTransform . GetComponentsInChildren < Transform > ( includeInactive : true ) ;
31+ foreach ( Transform child in allChildren )
32+ {
33+ // skip self (selection root)
34+ if ( child != Selection . activeTransform )
35+ {
36+ var newName = child . name . Replace ( findString , replaceWith ) ;
37+ Debug . LogFormat ( "Before: {0} | After: {1}" , child . name , newName ) ;
38+ child . name = newName ;
39+ }
40+ }
41+ }
42+
43+ }
44+ }
You can’t perform that action at this time.
0 commit comments