-
Notifications
You must be signed in to change notification settings - Fork 450
/
Copy pathCopyGameObjectNames.cs
59 lines (48 loc) · 1.78 KB
/
CopyGameObjectNames.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
// editor tool to copy names of selected GameObjects to clipboard as a list (so you can paste them in Excel or others..)
using UnityEngine;
using UnityEditor;
using System.Text;
using System.Linq;
namespace UnityLibrary.Tools
{
public class CopyGameObjectNames : EditorWindow
{
private string gameObjectNames = string.Empty;
[MenuItem("Tools/Copy GameObject Names")]
public static void ShowWindow()
{
GetWindow<CopyGameObjectNames>("Copy GameObject Names");
}
private void OnGUI()
{
GUILayout.Label("Copy Names of Selected GameObjects", EditorStyles.boldLabel);
if (GUILayout.Button("Fetch Names"))
{
FetchNames();
}
GUILayout.Label("GameObject Names:", EditorStyles.label);
gameObjectNames = EditorGUILayout.TextArea(gameObjectNames, GUILayout.Height(200));
if (GUILayout.Button("Copy to Clipboard"))
{
CopyToClipboard();
}
}
private void FetchNames()
{
StringBuilder sb = new StringBuilder();
GameObject[] selectedObjects = Selection.gameObjects;
// Sort the selected objects by their sibling index
var sortedObjects = selectedObjects.OrderBy(go => go.transform.GetSiblingIndex()).ToArray();
foreach (GameObject obj in sortedObjects)
{
sb.AppendLine(obj.name);
}
gameObjectNames = sb.ToString();
}
private void CopyToClipboard()
{
EditorGUIUtility.systemCopyBuffer = gameObjectNames;
Debug.Log("GameObject names copied to clipboard.");
}
}
}