using System.Collections.Generic;
using UnityEngine;
namespace UnityEditor.Rendering
{
/// Set of helpers for AssetDatabase operations.
public static class AssetDatabaseHelper
{
///
/// Finds all assets of type T in the project.
///
/// Asset type extension i.e ".mat" for materials
/// The type of material you are looking for
/// A IEnumerable object
public static IEnumerable FindAssets(string extension = null)
{
string typeName = typeof(T).ToString();
int i = typeName.LastIndexOf('.');
if (i != -1)
{
typeName = typeName.Substring(i+1, typeName.Length - i-1);
}
string query = !string.IsNullOrEmpty(extension) ? $"t:{typeName} glob:\"**/*{extension}\"" : $"t:{typeName}";
foreach (var guid in AssetDatabase.FindAssets(query))
{
var asset = AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GUIDToAssetPath(guid));
if (asset is T castAsset)
yield return castAsset;
}
}
}
}