-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rename_Editor.cs
98 lines (64 loc) · 2.36 KB
/
Rename_Editor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System.Linq;
using UnityEngine;
using UnityEditor;
using UnityEngine.UI;
public class Rename_Editor : EditorWindow
{
static string location = "";
static string localPath;
private static string guide = "Select GameObjects";
public static Transform[] objectArray;
private static Vector2 _windowsMinSize = Vector2.one * 500f;
private static Rect _helpRect = new Rect(0f, 0f, 400f, 100f);
private static Rect _listRect = new Rect(Vector2.zero, _windowsMinSize);
// Creates a new menu item 'Multiple Prefab/Multiple Prefab Creator Window' in the main menu and create a shortcut.
[MenuItem("Rename/Rename_Editor Window")]
static void Init()
{
// Get existing open window or if none, make a new one:
Rename_Editor window = (Rename_Editor)EditorWindow.GetWindow(typeof(Rename_Editor), true, "Rename_Editor");
window.Show();
}
void OnGUI()
{
location = EditorGUILayout.TextField("Name:", location);
if (Selection.activeGameObject != null)
{
GUI.backgroundColor = Color.green;
}
else
{
GUI.backgroundColor = Color.red;
}
if (GUI.Button(new Rect(50, 120, 200, 50), "Rename Button"))
{
if (Selection.activeGameObject != null)
{
Rename();
}
else
{
Debug.Log(("No selection in hierarchy !!!"));
guide = "No selection in hierarchy !!!";
}
}
EditorGUILayout.Space();
EditorGUILayout.LabelField("Guide", EditorStyles.boldLabel);
EditorGUILayout.LabelField(guide, GUILayout.Height(30));
}
[MenuItem("Rename/Rename Fast")]
public static void Rename()
{
// Keep track of the currently selected GameObject(s)
objectArray = Selection.transforms;
objectArray = objectArray.OrderBy(go => go.transform.GetSiblingIndex()).ToArray();
int n = 0;
// Loop through every GameObject in the array above
foreach (Transform GameObject in objectArray)
{
GameObject.transform.name = location +"_"+ n;
n++;
Debug.Log(GameObject.name);
}
}
}