LoginSignup
10
8

More than 5 years have passed since last update.

オブジェクトの名前を連番にする

Last updated at Posted at 2014-04-25

オブジェクトを選択して名前を変えるエディタスクリプト。
オブジェクトをコピーしたら同じ名前のがたくさんできてどれがどれだか分かんない状態になった時に使う。

using UnityEngine;
using UnityEditor;
using System;
using System.Text.RegularExpressions;

public class OrderingName : Editor
{
    [MenuItem("Editor/オブジェクト名を連番にする")]
    static void Ordering()
    {
        Undo.RecordObjects(Selection.objects, "modify name");

        int count = Selection.objects.Length;
        int d = count.ToString().Length;

        for (int i = 0; i < count; i++)
        {
            string name = Selection.objects[i].name;
            name = Regex.Replace(name, @"_(\d)+$", "");
            Selection.objects[i].name = name + "_" + i.ToString().PadLeft(d, '0');
        }
    }
}
10
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
8