暫無描述
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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 class GetFullPath
  13. {
  14. internal static string ForObject(Object obj)
  15. {
  16. string relativePath = AssetDatabase.GetAssetPath(obj);
  17. if (string.IsNullOrEmpty(relativePath))
  18. return null;
  19. return Path.GetFullPath(relativePath);
  20. }
  21. internal static string ForGuid(string guid)
  22. {
  23. string relativePath = GetAssetPath(guid);
  24. if (string.IsNullOrEmpty(relativePath))
  25. return null;
  26. return Path.GetFullPath(relativePath);
  27. }
  28. }
  29. internal static class GetFullPathUnderWorkspace
  30. {
  31. internal static string ForAsset(
  32. string wkPath,
  33. string assetPath)
  34. {
  35. if (string.IsNullOrEmpty(assetPath))
  36. return null;
  37. string fullPath = Path.GetFullPath(assetPath);
  38. if (!PathHelper.IsContainedOn(fullPath, wkPath))
  39. return null;
  40. return fullPath;
  41. }
  42. internal static string ForGuid(
  43. string wkPath,
  44. string guid)
  45. {
  46. return ForAsset(wkPath, GetAssetPath(guid));
  47. }
  48. }
  49. internal static string GetLayoutsFolderRelativePath()
  50. {
  51. return string.Concat(mAssetsFolderLocation, "/Layouts");
  52. }
  53. internal static string GetStylesFolderRelativePath()
  54. {
  55. return string.Concat(mAssetsFolderLocation, "/Styles");
  56. }
  57. internal static string GetImagesFolderRelativePath()
  58. {
  59. return string.Concat(mAssetsFolderLocation, "/Images");
  60. }
  61. internal static string GetRelativePath(string fullPath)
  62. {
  63. return PathHelper.GetRelativePath(
  64. mProjectFullPath, fullPath).Substring(1);
  65. }
  66. internal static bool IsRunningAsUPMPackage()
  67. {
  68. string unityPlasticDllPath = Path.GetFullPath(
  69. AssemblyLocation.GetAssemblyDirectory(
  70. Assembly.GetAssembly(typeof(PlasticLocalization))));
  71. return Directory.Exists(
  72. Path.GetFullPath(Path.Combine(
  73. unityPlasticDllPath,
  74. // assets relative path when running as a UPM package
  75. "../../../Editor/PlasticSCM/Assets")));
  76. }
  77. static string GetAssetPath(string guid)
  78. {
  79. if (string.IsNullOrEmpty(guid))
  80. return null;
  81. return AssetDatabase.GUIDToAssetPath(guid);
  82. }
  83. static AssetsPath()
  84. {
  85. mAssetsFolderLocation = (IsRunningAsUPMPackage()) ?
  86. "Packages/com.unity.collab-proxy/Editor/PlasticSCM/Assets" :
  87. "Assets/Plugins/PlasticSCM/Editor/Assets";
  88. }
  89. static string mProjectFullPath = ProjectPath.
  90. FromApplicationDataPath(ApplicationDataPath.Get());
  91. static string mAssetsFolderLocation;
  92. }
  93. }