A game about forced loneliness, made by TACStudios
1using System.IO;
2using System.Reflection;
3
4using UnityEditor;
5using UnityEngine;
6
7using Codice.Client.Common;
8using Codice.Utils;
9using PlasticGui;
10
11namespace Unity.PlasticSCM.Editor.AssetUtils
12{
13 internal static class AssetsPath
14 {
15 internal static class GetFullPath
16 {
17 internal static string ForObject(Object obj)
18 {
19 string relativePath = AssetDatabase.GetAssetPath(obj);
20
21 if (string.IsNullOrEmpty(relativePath))
22 return null;
23
24 return Path.GetFullPath(relativePath);
25 }
26
27 internal static string ForGuid(string guid)
28 {
29 string relativePath = GetAssetPath(guid);
30
31 if (string.IsNullOrEmpty(relativePath))
32 return null;
33
34 return Path.GetFullPath(relativePath);
35 }
36 }
37
38 internal static class GetFullPathUnderWorkspace
39 {
40 internal static string ForAsset(
41 string wkPath,
42 string assetPath)
43 {
44 if (string.IsNullOrEmpty(assetPath))
45 return null;
46
47 string fullPath = Path.GetFullPath(assetPath);
48
49 if (!PathHelper.IsContainedOn(fullPath, wkPath))
50 return null;
51
52 if (!fullPath.StartsWith("/"))
53 fullPath = fullPath.Substring(0, 1).ToLowerInvariant() + fullPath.Substring(1);
54 return fullPath.TrimEnd('/', '\\');
55 }
56
57 internal static string ForGuid(
58 string wkPath,
59 string guid)
60 {
61 return ForAsset(wkPath, GetAssetPath(guid));
62 }
63 }
64
65 internal static string GetLayoutsFolderRelativePath()
66 {
67 return string.Concat(mAssetsFolderLocation, "/Layouts");
68 }
69
70 internal static string GetStylesFolderRelativePath()
71 {
72 return string.Concat(mAssetsFolderLocation, "/Styles");
73 }
74
75 internal static string GetImagesFolderRelativePath()
76 {
77 return string.Concat(mAssetsFolderLocation, "/Images");
78 }
79
80 internal static string GetRelativePath(string fullPath)
81 {
82 return PathHelper.GetRelativePath(
83 mProjectFullPath, fullPath).Substring(1);
84 }
85
86 internal static bool IsRunningAsUPMPackage()
87 {
88 string unityPlasticDllPath = Path.GetFullPath(
89 AssemblyLocation.GetAssemblyDirectory(
90 Assembly.GetAssembly(typeof(PlasticLocalization))));
91
92 // The Plastic Dll path when running as a UPM package is either
93 // "Packages/com.unity.collab-proxy@xxx/Lib/Editor/unityplastic.dll" when running as an UPM package
94 // "Assets/Plugins/PlasticSCM/Lib/Editor/unityplastic.dll" in the development environment
95 return unityPlasticDllPath.Contains("com.unity.collab-proxy");
96 }
97
98 static string GetAssetPath(string guid)
99 {
100 if (string.IsNullOrEmpty(guid))
101 return null;
102
103 return AssetDatabase.GUIDToAssetPath(guid);
104 }
105
106 internal static bool IsPackagesRootElement(string path)
107 {
108 return PathHelper.IsSamePath(mProjectPackagesFullPath, PathHelper.GetParentPath(path));
109 }
110
111 internal static bool IsScript(string path)
112 {
113 return Path.GetExtension(path).Equals(".cs");
114 }
115
116 static AssetsPath()
117 {
118 mAssetsFolderLocation = (IsRunningAsUPMPackage()) ?
119 "Packages/com.unity.collab-proxy/Editor/Assets" :
120 "Assets/Plugins/PlasticSCM/Editor/Assets";
121 }
122
123 static readonly string mProjectFullPath = ProjectPath.Get();
124 static readonly string mProjectPackagesFullPath = Path.Combine(mProjectFullPath, "Packages");
125
126 static string mAssetsFolderLocation;
127 }
128}