Renamer

// Editor window that tracks selection order and then based on configuration // will rename the selection based on the format choosen // IE: Spawner_01 - Spawner_02 - Spawner_03 using System; using System.Collections.Generic; using UnityEditor; using UnityEngine; using Sirenix.OdinInspector; using Sirenix.OdinInspector.Editor; using Sirenix.Utilities; using Sirenix.Utilities.Editor; public class Renamer  : OrderedSelectionEditor {   [InfoBox("Key = {0} && Start Count == {1}")] public string Format = "{0}_{1}"; public string Key; public int StartCount = 1; private static Renamer m_Window; private List _listOrderedSelection = new List ; public void OnSelectionChange {       var listIdObjectsCurrentSelection = new List ; foreach (var iObject in Selection.instanceIDs) {           listIdObjectsCurrentSelection.Add(iObject); }       var listIdIndexesToDelete = new List ; var count = -1; foreach (var iObject in _listOrderedSelection) {           count += 1; if (!listIdObjectsCurrentSelection.Contains(iObject)) {               listIdIndexesToDelete.Add(count); }        }        int indexPenalty = 0; foreach (var indexToDelete in listIdIndexesToDelete) {           _listOrderedSelection.RemoveAt(indexToDelete - indexPenalty); indexPenalty++; }       foreach (var iObject in Selection.instanceIDs) {           if (!_listOrderedSelection.Contains(iObject)) {               _listOrderedSelection.Add(iObject); }        }     }    public List OrderedSelection {       var ret = new List; foreach (var iObject in _listOrderedSelection) {           var obj = EditorUtility.InstanceIDToObject(iObject); var gameObj = GameObject.Find(obj.name); if (gameObj) {               ret.Add(gameObj); }        }        return ret; }   [MenuItem("Tools/RGL/Editor/Renamer")] static void Init {       m_Window = GetWindow; m_Window.position = GUIHelper.GetEditorWindowRect.AlignCenter(700, 700); m_Window.titleContent = new GUIContent("Renamer"); m_Window.Repaint; }   [Button(ButtonSizes.Large)] public void Rename {       int count = StartCount; List selection = OrderedSelection; for (int i = 0; i < selection.Count; i++) { selection[i].name = string.Format(Format, Key, count); count += 1; }    } }
 * 1) if UNITY_EDITOR
 * 1) endif