- Home /
name changer component
hey just a simple question, is there an asset on the store to change the name of all selected objects in the hierarchy. so instead of just changing them all to the same name it will add 1,2,3,4,5 and so on.
if not i''ll make my own,
Answer by reptilebeats · Aug 09, 2013 at 12:19 AM
hey i added a couple things to it append and prepend, oh and if you type NONE it will only give you the numbers. if i have time i may make a proper little asset as i find this really useful, but maybe its just what im working on. enjoy
using UnityEngine;
using UnityEditor;
public class NameChanger : EditorWindow{
string newObjName; // input for the new name of object if required
bool changeName = false; // change all selected names
bool resetObjName = true; // reset the input name after use
bool prependAppend = true; // put the sequence before or after the name false = prepend true = append
private int counter = 0;
[MenuItem("MMGstudios/Window/NameChanger")]
static void Init()
{
EditorWindow.GetWindow(typeof(NameChanger));
}
void OnGUI()
{
newObjName = EditorGUILayout.TextField("New Name",newObjName);
changeName = EditorGUILayout.Toggle("Apply Change",changeName);
resetObjName = EditorGUILayout.Toggle("Reset Name",resetObjName);
prependAppend = EditorGUILayout.Toggle("Prepend/Append",prependAppend);
if(changeName == true)
{
GUIUtility.keyboardControl = 0;
changeName = false;
if(Selection.activeGameObject)
{
Undo.RegisterSceneUndo("Undo Name Change");
foreach(Transform ObjTransform in Selection.transforms)
{
counter++;
if(newObjName == "NONE") // will only put the sequence in and no name must be caps
ObjTransform.gameObject.name = "" + counter;
else
if(newObjName != "" && newObjName != "NONE")
{
if(prependAppend == true)
ObjTransform.gameObject.name = newObjName + counter;
else
ObjTransform.gameObject.name = counter + newObjName;
}
else
if(prependAppend == true)
ObjTransform.gameObject.name = ObjTransform.gameObject.name + counter;
else
ObjTransform.gameObject.name = counter + ObjTransform.gameObject.name;
}
counter = 0;
if(resetObjName == true)
{
newObjName = "";
}
}
}
if(GUI.Button(new Rect(1, 90, 110, 18), "MMGstudios Link"))
Application.OpenURL("http://mmgstudios.com");
}
}
Answer by Jamora · Aug 01, 2013 at 12:26 AM
In case you've not written it by now... I searched the Unify Wiki and the Asset Store. Didn't find anything. You'll probly write it faster than it takes to find one on the internet.
dunno it took me a while to scan the reference for it as i haven't looked at csharp much.