AssetsPath.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System.IO;
  2. using System.Reflection;
  3. using UnityEditor;
  4. using UnityEngine;
  5. using Codice.Client.Common;
  6. using Codice.Utils;
  7. using PlasticGui;
  8. namespace Unity.PlasticSCM.Editor.AssetUtils
  9. {
  10. internal static class AssetsPath
  11. {
  12. internal static string GetLayoutsFolderRelativePath()
  13. {
  14. return string.Concat(mAssetsFolderLocation, "/Layouts");
  15. }
  16. internal static string GetStylesFolderRelativePath()
  17. {
  18. return string.Concat(mAssetsFolderLocation, "/Styles");
  19. }
  20. internal static string GetImagesFolderRelativePath()
  21. {
  22. return string.Concat(mAssetsFolderLocation, "/Images");
  23. }
  24. internal static string GetRelativePath(string fullPath)
  25. {
  26. return PathHelper.GetRelativePath(
  27. mProjectFullPath, fullPath).Substring(1);
  28. }
  29. internal static string GetFullPath(Object obj)
  30. {
  31. string relativePath = AssetDatabase.GetAssetPath(obj);
  32. if (string.IsNullOrEmpty(relativePath))
  33. return null;
  34. return Path.GetFullPath(relativePath);
  35. }
  36. static AssetsPath()
  37. {
  38. mAssetsFolderLocation = (IsRunningAsUPMPackage()) ?
  39. "Packages/com.unity.collab-proxy/Editor/PlasticSCM/Assets" :
  40. "Assets/Plugins/PlasticSCM/Editor/Assets";
  41. }
  42. internal static bool IsRunningAsUPMPackage()
  43. {
  44. string unityPlasticDllPath = Path.GetFullPath(
  45. AssemblyLocation.GetAssemblyDirectory(
  46. Assembly.GetAssembly(typeof(PlasticLocalization))));
  47. return Directory.Exists(
  48. Path.GetFullPath(Path.Combine(
  49. unityPlasticDllPath,
  50. // assets relative path when running as a UPM package
  51. "../../../Editor/PlasticSCM/Assets")));
  52. }
  53. static string mProjectFullPath = ProjectPath.
  54. FromApplicationDataPath(Application.dataPath);
  55. static string mAssetsFolderLocation;
  56. }
  57. }