1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
using System.IO;
using System.Text.RegularExpressions;
using UnityEngine;
namespace UniGLTF
{
public static class StringExtensions
{
public static string ToLowerCamelCase(this string lower)
{
return lower.Substring(0, 1).ToLower() + lower.Substring(1);
}
public static string ToUpperCamelCase(this string lower)
{
return lower.Substring(0, 1).ToUpper() + lower.Substring(1);
}
static string m_unityBasePath;
public static string UnityBasePath
{
get
{
if (m_unityBasePath == null)
{
m_unityBasePath = Path.GetFullPath(Application.dataPath + "/..").Replace("\\", "/");
}
return m_unityBasePath;
}
}
public static string AssetPathToFullPath(this string path)
{
return UnityBasePath + "/" + path;
}
public static bool StartsWithUnityAssetPath(this string path)
{
return path.Replace("\\", "/").StartsWith(UnityBasePath + "/Assets");
}
public static string ToUnityRelativePath(this string path)
{
path = path.Replace("\\", "/");
if (path.StartsWith(UnityBasePath))
{
return path.Substring(UnityBasePath.Length + 1);
}
//Debug.LogWarningFormat("{0} is starts with {1}", path, basePath);
return path;
}
static readonly char[] EscapeChars = new char[]
{
'\\',
'/',
':',
'*',
'?',
'"',
'<',
'>',
'|',
};
public static string EscapeFilePath(this string path)
{
path = Regex.Replace(path, @"[\u0000-\u001F\u007F]", "+");
foreach(var x in EscapeChars)
{
path = path.Replace(x, '+');
}
return path;
}
}
}
|