Created
October 25, 2017 13:04
-
-
Save 0V/b1ed5b8d323b03daa2a280b44bea02a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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