浏览代码

Created an editor window to quickly find SOs

/main
HarshNarayanJha 4 年前
当前提交
1034d637
共有 2 个文件被更改,包括 136 次插入0 次删除
  1. 125
      UOP1_Project/Assets/Scripts/Editor/SOsQuickAccessToolWindow.cs
  2. 11
      UOP1_Project/Assets/Scripts/Editor/SOsQuickAccessToolWindow.cs.meta

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


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
class SOsQuickAccessToolWindow : EditorWindow
{
[Header("Editor Window Related")]
Vector2 scroll;
int selected;
[Header("SOs related")]
string[] assetSearchFolders;
List<string> SOTypes;
string[] objectsGUIDs;
string[] objectsPaths;
ScriptableObject[] objects;
string[] displayObjectsGUIDs;
List<string> displayObjectsPaths;
List<ScriptableObject> displayObjects;
private void OnEnable()
{
assetSearchFolders = new string[1];
assetSearchFolders[0] = "Assets/ScriptableObjects";
}
[MenuItem("Tools/Quick Access Tool")]
private static void ShowWindow()
{
GetWindow<SOsQuickAccessToolWindow>("Quick Access Tool");
}
void OnGUI()
{
// All finding work #1
objectsGUIDs = AssetDatabase.FindAssets("t:ScriptableObject", assetSearchFolders) as string[];
objectsPaths = new string[objectsGUIDs.Length];
objects = new ScriptableObject[objectsGUIDs.Length];
SOTypes = new List<string>();
for (int i=0; i< objectsGUIDs.Length; i++)
{
objectsPaths[i] = AssetDatabase.GUIDToAssetPath(objectsGUIDs[i]);
objects[i] = (ScriptableObject) AssetDatabase.LoadAssetAtPath(objectsPaths[i], typeof(ScriptableObject));
//Debug.Log(objectsGUIDs[i] + ": " + objectsPaths[i] + " - " + i);
}
for (int i=0; i<objects.Length; i++)
{
if (SOTypes.IndexOf(objects[i].GetType().ToString()) == -1)
{
SOTypes.Add(objects[i].GetType().ToString());
}
}
// End #1
GUILayout.Space(EditorGUIUtility.singleLineHeight * 2f);
GUILayout.Label("Please select a Scriptable Object Type To Search For...");
GUILayout.Space(EditorGUIUtility.singleLineHeight);
DrawSOsPicker();
GUILayout.Space(EditorGUIUtility.singleLineHeight * 3f);
DrawSOsList();
}
void DrawSOsPicker()
{
EditorGUI.BeginChangeCheck();
selected = EditorGUILayout.Popup("Scriptable Object Types", selected, SOTypes.ToArray());
if (EditorGUI.EndChangeCheck())
{
DrawSOsList();
}
}
void DrawSOsList()
{
if (displayObjects != null)
{
displayObjects.Clear();
}
if (displayObjectsPaths != null)
{
displayObjectsPaths.Clear();
}
string type = SOTypes[selected];
string queryString = "t:"+ type;
displayObjectsGUIDs = AssetDatabase.FindAssets(queryString);
displayObjectsPaths = new List<string>(displayObjectsGUIDs.Length);
displayObjects = new List<ScriptableObject>(displayObjectsGUIDs.Length);
for (int i=0; i < displayObjectsGUIDs.Length; i++)
{
displayObjectsPaths.Add(AssetDatabase.GUIDToAssetPath(displayObjectsGUIDs[i]));
displayObjects.Add(AssetDatabase.LoadAssetAtPath(displayObjectsPaths[i], typeof(ScriptableObject)) as ScriptableObject);
}
scroll = GUILayout.BeginScrollView(scroll);
for (int i=0; i< displayObjectsGUIDs.Length; i++)
{
GUILayout.Label(i+1 + ". " + displayObjects[i].name);
if (GUILayout.Button("Locate"))
{
EditorUtility.FocusProjectWindow();
EditorGUIUtility.PingObject(displayObjects[i]);
}
GUILayout.Space(EditorGUIUtility.singleLineHeight);
}
GUILayout.EndScrollView();
}
}

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


fileFormatVersion: 2
guid: ec8c662b7f1823b4799529408de198f3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存