123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- using System.IO;
- using System.Reflection;
-
- using UnityEditor;
- using UnityEngine;
-
- using Codice.Client.Common;
- using Codice.Utils;
- using PlasticGui;
-
- namespace Unity.PlasticSCM.Editor.AssetUtils
- {
- internal static class AssetsPath
- {
- internal static class GetFullPath
- {
- internal static string ForObject(Object obj)
- {
- string relativePath = AssetDatabase.GetAssetPath(obj);
-
- if (string.IsNullOrEmpty(relativePath))
- return null;
-
- return Path.GetFullPath(relativePath);
- }
-
- internal static string ForGuid(string guid)
- {
- string relativePath = GetAssetPath(guid);
-
- if (string.IsNullOrEmpty(relativePath))
- return null;
-
- return Path.GetFullPath(relativePath);
- }
- }
-
- internal static class GetFullPathUnderWorkspace
- {
- internal static string ForAsset(
- string wkPath,
- string assetPath)
- {
- if (string.IsNullOrEmpty(assetPath))
- return null;
-
- string fullPath = Path.GetFullPath(assetPath);
-
- if (!PathHelper.IsContainedOn(fullPath, wkPath))
- return null;
-
- if (!fullPath.StartsWith("/"))
- fullPath = fullPath.Substring(0, 1).ToLowerInvariant() + fullPath.Substring(1);
- return fullPath.TrimEnd('/', '\\');
- }
-
- internal static string ForGuid(
- string wkPath,
- string guid)
- {
- return ForAsset(wkPath, GetAssetPath(guid));
- }
- }
-
- internal static string GetLayoutsFolderRelativePath()
- {
- return string.Concat(mAssetsFolderLocation, "/Layouts");
- }
-
- internal static string GetStylesFolderRelativePath()
- {
- return string.Concat(mAssetsFolderLocation, "/Styles");
- }
-
- internal static string GetImagesFolderRelativePath()
- {
- return string.Concat(mAssetsFolderLocation, "/Images");
- }
-
- internal static string GetRelativePath(string fullPath)
- {
- return PathHelper.GetRelativePath(
- mProjectFullPath, fullPath).Substring(1);
- }
-
- internal static bool IsRunningAsUPMPackage()
- {
- string unityPlasticDllPath = Path.GetFullPath(
- AssemblyLocation.GetAssemblyDirectory(
- Assembly.GetAssembly(typeof(PlasticLocalization))));
-
- return Directory.Exists(
- Path.GetFullPath(Path.Combine(
- unityPlasticDllPath,
- // assets relative path when running as a UPM package
- "../../../Editor/PlasticSCM/Assets")));
- }
-
- static string GetAssetPath(string guid)
- {
- if (string.IsNullOrEmpty(guid))
- return null;
-
- return AssetDatabase.GUIDToAssetPath(guid);
- }
-
- static AssetsPath()
- {
- mAssetsFolderLocation = (IsRunningAsUPMPackage()) ?
- "Packages/com.unity.collab-proxy/Editor/PlasticSCM/Assets" :
- "Assets/Plugins/PlasticSCM/Editor/Assets";
- }
-
- static string mProjectFullPath = ProjectPath.
- FromApplicationDataPath(ApplicationDataPath.Get());
-
- static string mAssetsFolderLocation;
- }
- }
|