Skip to content

Commit 64420eb

Browse files
committed
feat: more path util
1 parent 28ef310 commit 64420eb

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

Assets/JCSUnity/Scripts/Util/JCS_Path.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* $Notice: See LICENSE.txt for modification and distribution information
77
* Copyright © 2021 by Shen, Jen-Chieh $
88
*/
9+
using System.IO;
10+
using UnityEngine;
911

1012
namespace JCSUnity
1113
{
@@ -20,6 +22,16 @@ public static class JCS_Path
2022

2123
/* Functions */
2224

25+
/// <summary>
26+
/// Return the normalized path.
27+
/// </summary>
28+
public static string Normalize(string path)
29+
{
30+
return path.Replace(
31+
Path.DirectorySeparatorChar,
32+
Path.AltDirectorySeparatorChar);
33+
}
34+
2335
/// <summary>
2436
/// Safe way to combine multiple path to one path with slash.
2537
/// </summary>
@@ -28,14 +40,27 @@ public static class JCS_Path
2840
public static string Combine(params string[] list)
2941
{
3042
string result = list[0];
43+
3144
for (int index = 1; index < list.Length; ++index)
3245
{
3346
string path = list[index];
3447
result += "/" + path;
3548
}
36-
result = result.Replace("\\", "/");
49+
50+
result = Normalize(result);
3751
result = result.Replace("//", "/");
52+
3853
return result;
3954
}
55+
56+
/// <summary>
57+
/// Convert a path to asset compatible path.
58+
///
59+
/// The returned string should start with `Assets/`.
60+
/// </summary>
61+
public static string ToAsset(string path)
62+
{
63+
return path.Replace(Application.dataPath, "Assets");
64+
}
4065
}
4166
}

0 commit comments

Comments
 (0)