Skip to content

Commit 16c4cbb

Browse files
Created an editor window to quickly find SOs
1 parent 72e45ba commit 16c4cbb

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using UnityEditor;
5+
6+
class SOsQuickAccessToolWindow : EditorWindow
7+
{
8+
[Header("Editor Window Related")]
9+
Vector2 scroll;
10+
int selected;
11+
12+
[Header("SOs related")]
13+
string[] assetSearchFolders;
14+
15+
List<string> SOTypes;
16+
string[] objectsGUIDs;
17+
string[] objectsPaths;
18+
ScriptableObject[] objects;
19+
20+
string[] displayObjectsGUIDs;
21+
List<string> displayObjectsPaths;
22+
List<ScriptableObject> displayObjects;
23+
24+
private void OnEnable()
25+
{
26+
assetSearchFolders = new string[1];
27+
assetSearchFolders[0] = "Assets/ScriptableObjects";
28+
}
29+
30+
[MenuItem("Tools/Quick Access Tool")]
31+
private static void ShowWindow()
32+
{
33+
GetWindow<SOsQuickAccessToolWindow>("Quick Access Tool");
34+
}
35+
36+
void OnGUI()
37+
{
38+
// All finding work #1
39+
objectsGUIDs = AssetDatabase.FindAssets("t:ScriptableObject", assetSearchFolders) as string[];
40+
41+
objectsPaths = new string[objectsGUIDs.Length];
42+
objects = new ScriptableObject[objectsGUIDs.Length];
43+
44+
SOTypes = new List<string>();
45+
46+
for (int i=0; i< objectsGUIDs.Length; i++)
47+
{
48+
objectsPaths[i] = AssetDatabase.GUIDToAssetPath(objectsGUIDs[i]);
49+
objects[i] = (ScriptableObject) AssetDatabase.LoadAssetAtPath(objectsPaths[i], typeof(ScriptableObject));
50+
//Debug.Log(objectsGUIDs[i] + ": " + objectsPaths[i] + " - " + i);
51+
}
52+
53+
for (int i=0; i<objects.Length; i++)
54+
{
55+
if (SOTypes.IndexOf(objects[i].GetType().ToString()) == -1)
56+
{
57+
SOTypes.Add(objects[i].GetType().ToString());
58+
}
59+
}
60+
// End #1
61+
62+
GUILayout.Space(EditorGUIUtility.singleLineHeight * 2f);
63+
64+
GUILayout.Label("Please select a Scriptable Object Type To Search For...");
65+
66+
GUILayout.Space(EditorGUIUtility.singleLineHeight);
67+
DrawSOsPicker();
68+
69+
GUILayout.Space(EditorGUIUtility.singleLineHeight * 3f);
70+
DrawSOsList();
71+
}
72+
73+
void DrawSOsPicker()
74+
{
75+
EditorGUI.BeginChangeCheck();
76+
selected = EditorGUILayout.Popup("Scriptable Object Types", selected, SOTypes.ToArray());
77+
if (EditorGUI.EndChangeCheck())
78+
{
79+
DrawSOsList();
80+
}
81+
}
82+
83+
void DrawSOsList()
84+
{
85+
if (displayObjects != null)
86+
{
87+
displayObjects.Clear();
88+
}
89+
if (displayObjectsPaths != null)
90+
{
91+
displayObjectsPaths.Clear();
92+
}
93+
94+
string type = SOTypes[selected];
95+
string queryString = "t:"+ type;
96+
97+
displayObjectsGUIDs = AssetDatabase.FindAssets(queryString);
98+
99+
displayObjectsPaths = new List<string>(displayObjectsGUIDs.Length);
100+
displayObjects = new List<ScriptableObject>(displayObjectsGUIDs.Length);
101+
102+
for (int i=0; i < displayObjectsGUIDs.Length; i++)
103+
{
104+
displayObjectsPaths.Add(AssetDatabase.GUIDToAssetPath(displayObjectsGUIDs[i]));
105+
displayObjects.Add(AssetDatabase.LoadAssetAtPath(displayObjectsPaths[i], typeof(ScriptableObject)) as ScriptableObject);
106+
}
107+
108+
scroll = GUILayout.BeginScrollView(scroll);
109+
110+
for (int i=0; i< displayObjectsGUIDs.Length; i++)
111+
{
112+
GUILayout.Label(i+1 + ". " + displayObjects[i].name);
113+
114+
if (GUILayout.Button("Locate"))
115+
{
116+
EditorUtility.FocusProjectWindow();
117+
EditorGUIUtility.PingObject(displayObjects[i]);
118+
}
119+
120+
GUILayout.Space(EditorGUIUtility.singleLineHeight);
121+
}
122+
123+
GUILayout.EndScrollView();
124+
}
125+
}

UOP1_Project/Assets/Scripts/Editor/SOsQuickAccessToolWindow.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)