I would like to somehow query the asset database to find all assets of a specific class (similar to what happens in EditorGUI.ObjectField). I would like an array of all assets that inherit the class SpecialScriptableObject.
Having spent a little time searching it seems that this data is stored in a Sqlite database that is stored in the “Library” folder. Is there an API that can be used to perform such a query efficiently?
foreach (string guid in AssetDatabase.FindAssets("t:SpecialScriptableObject")) {
string assetPath = AssetDatabase.GUIDToAssetPath(guid);
var asset = AssetDatabase.LoadAssetAtPath(assetPath, typeof(SpecialScriptableObject)) as SpecialScriptableObject;
// Do whatever you want with the asset!
}
I get out of memory exceptions when this gets run on a ~15gig project (and being 15 gigs is probably the problem), but I’ve never had issues dealing with a regular project. Should be a good starting point. For prefabs, the string extensions would be “prefab”; for images it might be “bmp”,“png”, and “tga”.
string[] files = AssetDatabase.GetAllAssetPaths().Where(
x=>extensions.ContainsElement(System.IO.Path.GetExtension(x).Replace(".",""))
).ToArray();
...
UnityEngine.Object thing = UnityEditor.AssetDatabase.LoadAssetAtPath(checkFile, typeof(T));
T o = (T)thing;
if ( null != o ) {
// hooray, O is an object of type T