Skip to content

Instantly share code, notes, and snippets.

@CapitanLiteral
Created November 2, 2019 23:15
Show Gist options
  • Save CapitanLiteral/f2cf9166e07e99f4114709da2a46ccf4 to your computer and use it in GitHub Desktop.
Save CapitanLiteral/f2cf9166e07e99f4114709da2a46ccf4 to your computer and use it in GitHub Desktop.
public static List<T> FindAssetsByType<T>() where T : Object
{
List<T> assets = new List<T>();
string[] guids = AssetDatabase.FindAssets(string.Format("t:{0}", typeof(T)));
for( int i = 0; i < guids.Length; i++ )
{
string assetPath = AssetDatabase.GUIDToAssetPath( guids[i] );
T asset = AssetDatabase.LoadAssetAtPath<T>( assetPath );
if( asset != null )
{
assets.Add(asset);
}
}
return assets;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment