No Description
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.

AssetsPath.cs 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Reflection;
  5. using UnityEditor;
  6. using UnityEngine;
  7. using Codice.Client.BaseCommands;
  8. using Codice.Client.Common;
  9. using Codice.CM.Common;
  10. using Codice.Utils;
  11. using PlasticGui;
  12. namespace Unity.PlasticSCM.Editor.AssetUtils
  13. {
  14. internal static class AssetsPath
  15. {
  16. internal static class GetFullPath
  17. {
  18. internal static string ForObject(Object obj)
  19. {
  20. string relativePath = AssetDatabase.GetAssetPath(obj);
  21. if (string.IsNullOrEmpty(relativePath))
  22. return null;
  23. return Path.GetFullPath(relativePath);
  24. }
  25. internal static string ForGuid(string guid)
  26. {
  27. string relativePath = GetAssetPath(guid);
  28. if (string.IsNullOrEmpty(relativePath))
  29. return null;
  30. return Path.GetFullPath(relativePath);
  31. }
  32. }
  33. internal static class GetFullPathUnderWorkspace
  34. {
  35. internal static string ForAsset(
  36. string wkPath,
  37. string assetPath)
  38. {
  39. if (string.IsNullOrEmpty(assetPath))
  40. return null;
  41. string fullPath = Path.GetFullPath(assetPath);
  42. if (!PathHelper.IsContainedOn(fullPath, wkPath))
  43. return null;
  44. if (!fullPath.StartsWith("/"))
  45. fullPath = fullPath.Substring(0, 1).ToLowerInvariant() + fullPath.Substring(1);
  46. return fullPath.TrimEnd('/', '\\');
  47. }
  48. internal static string ForGuid(
  49. string wkPath,
  50. string guid)
  51. {
  52. return ForAsset(wkPath, GetAssetPath(guid));
  53. }
  54. }
  55. internal static string GetLayoutsFolderRelativePath()
  56. {
  57. return string.Concat(mAssetsFolderLocation, "/Layouts");
  58. }
  59. internal static string GetStylesFolderRelativePath()
  60. {
  61. return string.Concat(mAssetsFolderLocation, "/Styles");
  62. }
  63. internal static string GetImagesFolderRelativePath()
  64. {
  65. return string.Concat(mAssetsFolderLocation, "/Images");
  66. }
  67. internal static string GetRelativePath(string fullPath)
  68. {
  69. return PathHelper.GetRelativePath(
  70. mProjectFullPath, fullPath).Substring(1);
  71. }
  72. internal static bool IsRunningAsUPMPackage()
  73. {
  74. string unityPlasticDllPath = Path.GetFullPath(
  75. AssemblyLocation.GetAssemblyDirectory(
  76. Assembly.GetAssembly(typeof(PlasticLocalization))));
  77. return Directory.Exists(
  78. Path.GetFullPath(Path.Combine(
  79. unityPlasticDllPath,
  80. // assets relative path when running as a UPM package
  81. "../../../Editor/PlasticSCM/Assets")));
  82. }
  83. static string GetAssetPath(string guid)
  84. {
  85. if (string.IsNullOrEmpty(guid))
  86. return null;
  87. return AssetDatabase.GUIDToAssetPath(guid);
  88. }
  89. internal static bool IsPackagesRootElement(string path)
  90. {
  91. return PathHelper.IsSamePath(mProjectPackagesFullPath, PathHelper.GetParentPath(path));
  92. }
  93. static AssetsPath()
  94. {
  95. mAssetsFolderLocation = (IsRunningAsUPMPackage()) ?
  96. "Packages/com.unity.collab-proxy/Editor/PlasticSCM/Assets" :
  97. "Assets/Plugins/PlasticSCM/Editor/Assets";
  98. }
  99. static readonly string mProjectFullPath = ProjectPath.FromApplicationDataPath(ApplicationDataPath.Get());
  100. static readonly string mProjectPackagesFullPath = Path.Combine(mProjectFullPath, "Packages");
  101. static string mAssetsFolderLocation;
  102. }
  103. }