Skip to content

Instantly share code, notes, and snippets.

@baba-s
Created March 23, 2020 01:28
Show Gist options
  • Save baba-s/1e60664c6de275d8dc2232af6803d61b to your computer and use it in GitHub Desktop.
Save baba-s/1e60664c6de275d8dc2232af6803d61b to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
public static class AssetDatabaseUtils
{
public static T FindAsset<T>() where T : UnityEngine.Object
{
return FindAssets<T>().FirstOrDefault();
}
public static IEnumerable<T> FindAssets<T>() where T : UnityEngine.Object
{
return AssetDatabase
.FindAssets( $"t:{typeof( T ).Name}" )
.Select( c => AssetDatabase.GUIDToAssetPath( c ) )
.Select( c => AssetDatabase.LoadAssetAtPath<T>( c ) )
;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment