Skip to content

Commit

Permalink
UnityPath.FromUnityPath
Browse files Browse the repository at this point in the history
* "" => Application.dataPath / ..
* "." => Application.dataPath / ..
* null => invalid
  • Loading branch information
ousttrue committed Nov 9, 2022
1 parent 82574f5 commit a278ea8
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions Assets/UniGLTF/Runtime/UniGLTF/IO/UnityPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public struct UnityPath
{
#if UNITY_EDITOR
#region UnityPath

public string Value
{
get;
Expand Down Expand Up @@ -60,7 +60,7 @@ public bool IsUnderWritableFolder

var packageInfo = GetPackageInfo(packageDirectory);
if (packageInfo == null) return false;

// Local and Embedded packages are editable
if (packageInfo.source == PackageSource.Local
|| packageInfo.source == PackageSource.Embedded) return true;
Expand All @@ -87,7 +87,7 @@ private static PackageInfo GetPackageInfo(string path)

return GetPackageInfo(Path.GetDirectoryName(path));
}

/// <summary>
/// List of packages loaded in unity
/// </summary>
Expand Down Expand Up @@ -147,18 +147,18 @@ public bool HasParent
return !string.IsNullOrEmpty(Value);
}
}

public PathType PathType
{
get
{
if (string.IsNullOrEmpty(Value)) return PathType.Unsuported;

var directory = Path.GetDirectoryName(Value);
if (string.IsNullOrEmpty(directory)) return PathType.Unsuported;

var rootDirectoryName = directory.Split(Path.DirectorySeparatorChar);

switch (rootDirectoryName[0])
{
case "Assets":
Expand Down Expand Up @@ -279,7 +279,14 @@ public UnityPath GetAssetFolder(string suffix)
/// <returns></returns>
public static UnityPath FromUnityPath(string unityPath)
{
if (String.IsNullOrEmpty(unityPath) || unityPath == ".")
if (unityPath == null)
{
return new UnityPath
{
Value = null
};
}
if (unityPath == "" || unityPath == ".")
{
return new UnityPath
{
Expand Down Expand Up @@ -312,7 +319,7 @@ public string FullPath
{
throw new NotImplementedException();
}
return Path.GetFullPath(Value).Replace("\\", "/");
return Path.GetFullPath(Value == "" ? "." : Value).Replace("\\", "/");
}
}

Expand Down Expand Up @@ -343,7 +350,7 @@ public static UnityPath FromFullpath(string fullPath)
{
return new UnityPath("");
}

if (fullPath.FastStartsWith($"{BaseFullPath}/Assets"))
{
return new UnityPath(fullPath.Substring(BaseFullPath.Length + 1));
Expand Down Expand Up @@ -434,7 +441,7 @@ public void EnsureFolder()
{
if (IsNull)
{
throw new NotImplementedException();
return;
}

if (HasParent)
Expand Down Expand Up @@ -519,7 +526,7 @@ public UnityPath GenerateUniqueAssetPath()
}
#endif
}

public enum PathType
{
Assets,
Expand Down

0 comments on commit a278ea8

Please sign in to comment.