Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

AssetsPath.cs 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. if (!fullPath.StartsWith("/"))
  41. fullPath = fullPath.Substring(0, 1).ToLowerInvariant() + fullPath.Substring(1);
  42. return fullPath.TrimEnd('/', '\\');
  43. }
  44. internal static string ForGuid(
  45. string wkPath,
  46. string guid)
  47. {
  48. return ForAsset(wkPath, GetAssetPath(guid));
  49. }
  50. }
  51. internal static string GetLayoutsFolderRelativePath()
  52. {
  53. return string.Concat(mAssetsFolderLocation, "/Layouts");
  54. }
  55. internal static string GetStylesFolderRelativePath()
  56. {
  57. return string.Concat(mAssetsFolderLocation, "/Styles");
  58. }
  59. internal static string GetImagesFolderRelativePath()
  60. {
  61. return string.Concat(mAssetsFolderLocation, "/Images");
  62. }
  63. internal static string GetRelativePath(string fullPath)
  64. {
  65. return PathHelper.GetRelativePath(
  66. mProjectFullPath, fullPath).Substring(1);
  67. }
  68. internal static bool IsRunningAsUPMPackage()
  69. {
  70. string unityPlasticDllPath = Path.GetFullPath(
  71. AssemblyLocation.GetAssemblyDirectory(
  72. Assembly.GetAssembly(typeof(PlasticLocalization))));
  73. return Directory.Exists(
  74. Path.GetFullPath(Path.Combine(
  75. unityPlasticDllPath,
  76. // assets relative path when running as a UPM package
  77. "../../../Editor/PlasticSCM/Assets")));
  78. }
  79. static string GetAssetPath(string guid)
  80. {
  81. if (string.IsNullOrEmpty(guid))
  82. return null;
  83. return AssetDatabase.GUIDToAssetPath(guid);
  84. }
  85. static AssetsPath()
  86. {
  87. mAssetsFolderLocation = (IsRunningAsUPMPackage()) ?
  88. "Packages/com.unity.collab-proxy/Editor/PlasticSCM/Assets" :
  89. "Assets/Plugins/PlasticSCM/Editor/Assets";
  90. }
  91. static string mProjectFullPath = ProjectPath.
  92. FromApplicationDataPath(ApplicationDataPath.Get());
  93. static string mAssetsFolderLocation;
  94. }
  95. }