A game about forced loneliness, made by TACStudios
1using System;
2using System.IO;
3
4using UnityEditor;
5
6using Codice.Client.BaseCommands;
7
8namespace Unity.PlasticSCM.Editor.AssetUtils
9{
10 internal static class LoadAsset
11 {
12 internal static UnityEngine.Object FromChangeInfo(ChangeInfo changeInfo)
13 {
14 string changeFullPath = changeInfo.GetFullPath();
15
16 if (MetaPath.IsMetaPath(changeFullPath))
17 changeFullPath = MetaPath.GetPathFromMetaPath(changeFullPath);
18
19 return FromFullPath(changeFullPath);
20 }
21
22 static UnityEngine.Object FromFullPath(string fullPath)
23 {
24 if (!IsPathUnderProject(fullPath))
25 return null;
26
27 return AssetDatabase.LoadMainAssetAtPath(
28 AssetsPath.GetRelativePath(fullPath));
29 }
30
31 static bool IsPathUnderProject(string path)
32 {
33 if (string.IsNullOrEmpty(path))
34 return false;
35
36 var fullPath = Path.GetFullPath(path).Replace('\\', '/');
37
38 return fullPath.StartsWith(
39 mProjectRelativePath,
40 StringComparison.OrdinalIgnoreCase);
41 }
42
43 static string mProjectRelativePath =
44 Directory.GetCurrentDirectory().Replace('\\', '/') + '/';
45 }
46}