Skip to content

Commit 540b31a

Browse files
authored
Create MassRenameChildren.cs
1 parent a016c2b commit 540b31a

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
}

0 commit comments

Comments
 (0)