BlueGit

blue-star ggj-2020

Files

ggj-2020 / Assets / Oculus / VR / Editor / PathHelper.cs

PathHelper.cs

Project Import
timfa Tim Falken · pushed by timfa · 6 years ago
b77834a1 History
PathHelper.cs 647 B Download Raw
1using System;
2using System.IO;
3
4public static class PathHelper
5{
6 public static string MakeRelativePath(string fromPath, string toPath)
7 {
8 var fromUri = new Uri(Path.GetFullPath(fromPath));
9 var toUri = new Uri(Path.GetFullPath(toPath));
10
11 if (fromUri.Scheme != toUri.Scheme)
12 {
13 return toPath;
14 }
15
16 var relativeUri = fromUri.MakeRelativeUri(toUri);
17 var relativePath = Uri.UnescapeDataString(relativeUri.ToString());
18
19 if (toUri.Scheme.Equals("file", StringComparison.InvariantCultureIgnoreCase))
20 {
21 relativePath = relativePath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
22 }
23
24 return relativePath;
25 }
26}