Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

AssetDatabaseHelper.cs 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. namespace UnityEditor.Rendering
  4. {
  5. /// <summary> Set of helpers for AssetDatabase operations. </summary>
  6. public static class AssetDatabaseHelper
  7. {
  8. /// <summary>
  9. /// Finds all assets of type T in the project.
  10. /// </summary>
  11. /// <param name="extension">Asset type extension i.e ".mat" for materials. Specifying extension make this faster.</param>
  12. /// <typeparam name="T">The type of asset you are looking for</typeparam>
  13. /// <returns>An IEnumerable off all assets found.</returns>
  14. public static IEnumerable<T> FindAssets<T>(string extension = null)
  15. where T : Object
  16. {
  17. string query = BuildQueryToFindAssets<T>(extension);
  18. foreach (var guid in AssetDatabase.FindAssets(query))
  19. {
  20. var asset = AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GUIDToAssetPath(guid));
  21. if (asset is T castAsset)
  22. yield return castAsset;
  23. }
  24. }
  25. /// <summary>
  26. /// Finds all assets paths of type T in the project.
  27. /// </summary>
  28. /// <param name="extension">Asset type extension i.e ".mat" for materials. Specifying extension make this faster.</param>
  29. /// <typeparam name="T">The type of asset you are looking for</typeparam>
  30. /// <returns>An IEnumerable off all assets paths found.</returns>
  31. public static IEnumerable<string> FindAssetPaths<T>(string extension = null)
  32. where T : Object
  33. {
  34. string query = BuildQueryToFindAssets<T>(extension);
  35. foreach (var guid in AssetDatabase.FindAssets(query))
  36. yield return AssetDatabase.GUIDToAssetPath(guid);
  37. }
  38. static string BuildQueryToFindAssets<T>(string extension = null)
  39. where T : Object
  40. {
  41. string typeName = typeof(T).ToString();
  42. int i = typeName.LastIndexOf('.');
  43. if (i != -1)
  44. {
  45. typeName = typeName.Substring(i+1, typeName.Length - i-1);
  46. }
  47. return string.IsNullOrEmpty(extension) ? $"t:{typeName}" : $"t:{typeName} glob:\"**/*{extension}\"";
  48. }
  49. }
  50. }