Skip to content

Instantly share code, notes, and snippets.

@0V
Created October 25, 2017 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0V/b1ed5b8d323b03daa2a280b44bea02a7 to your computer and use it in GitHub Desktop.
Save 0V/b1ed5b8d323b03daa2a280b44bea02a7 to your computer and use it in GitHub Desktop.
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;
public class ToNumbering : EditorWindow
{
private string baseName = "";
// Add menu item named "My Window" to the Window menu
[MenuItem("Tools/ToNumbering")]
public static void ShowWindow()
{
//Show existing window instance. If one doesn't exist, make one.
EditorWindow.GetWindow(typeof(ToNumbering));
}
void OnGUI()
{
GUILayout.Label("What is base name?", EditorStyles.boldLabel);
baseName = EditorGUILayout.TextField("Base Name", baseName);
if (GUILayout.Button("Excute"))
{
Ordering(baseName);
Debug.Log("Renamed.");
}
}
void Ordering(string baseName)
{
Undo.RecordObjects(Selection.objects, "modify name");
int count = Selection.objects.Length;
int d = count.ToString().Length;
for (int i = 0; i < count; i++)
{
string newname = Regex.Replace(baseName, @"_(\d)+$", "");
Selection.objects[i].name = newname + "_" + i.ToString().PadLeft(d, '0');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment