You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.6 KiB

  1. using UnityEngine;
  2. namespace UnityEditor.PostProcessing
  3. {
  4. using UnityObject = Object;
  5. static class EditorResources
  6. {
  7. static string m_EditorResourcesPath = string.Empty;
  8. internal static string editorResourcesPath
  9. {
  10. get
  11. {
  12. if (string.IsNullOrEmpty(m_EditorResourcesPath))
  13. {
  14. string path;
  15. if (SearchForEditorResourcesPath(out path))
  16. m_EditorResourcesPath = path;
  17. else
  18. Debug.LogError("Unable to locate editor resources. Make sure the PostProcessing package has been installed correctly.");
  19. }
  20. return m_EditorResourcesPath;
  21. }
  22. }
  23. internal static T Load<T>(string name)
  24. where T : UnityObject
  25. {
  26. return AssetDatabase.LoadAssetAtPath<T>(editorResourcesPath + name);
  27. }
  28. static bool SearchForEditorResourcesPath(out string path)
  29. {
  30. path = string.Empty;
  31. string searchStr = "/PostProcessing/Editor Resources/";
  32. string str = null;
  33. foreach (var assetPath in AssetDatabase.GetAllAssetPaths())
  34. {
  35. if (assetPath.Contains(searchStr))
  36. {
  37. str = assetPath;
  38. break;
  39. }
  40. }
  41. if (str == null)
  42. return false;
  43. path = str.Substring(0, str.LastIndexOf(searchStr) + searchStr.Length);
  44. return true;
  45. }
  46. }
  47. }