PackageResources.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System.IO;
  2. using System.Linq;
  3. using UnityEngine;
  4. using UnityEditor;
  5. namespace SoftMasking.Editor {
  6. public static class PackageResources {
  7. static string _packagePath = string.Empty;
  8. static string _resourcesPath = string.Empty;
  9. public static string packagePath {
  10. get {
  11. if (string.IsNullOrEmpty(_packagePath)) {
  12. _packagePath = SearchForPackageRootPath();
  13. if (string.IsNullOrEmpty(_packagePath))
  14. Debug.LogError(
  15. "Unable to locate Soft Mask root folder. " +
  16. "Make sure the package has been installed correctly.");
  17. }
  18. return _packagePath;
  19. }
  20. }
  21. public static string generatedShaderResourcesPath {
  22. get {
  23. if (string.IsNullOrEmpty(_resourcesPath))
  24. _resourcesPath = CombinePath(packagePath, "Shaders", "Generated", "Resources");
  25. return _resourcesPath;
  26. }
  27. }
  28. public const string SoftMaskCsGUID = "0bac33ade27cf4542bd53b1b13d90941";
  29. static string SearchForPackageRootPath() {
  30. var softMaskCsPath = AssetDatabase.GUIDToAssetPath(SoftMaskCsGUID);
  31. if (string.IsNullOrEmpty(softMaskCsPath))
  32. return "";
  33. var scriptsDir = Path.GetDirectoryName(softMaskCsPath);
  34. var packageDir = Path.GetDirectoryName(scriptsDir);
  35. return packageDir;
  36. }
  37. static string CombinePath(params string[] paths) {
  38. return (paths == null || paths.Length == 0) ? "" : paths.Aggregate(Path.Combine);
  39. }
  40. }
  41. }