Class UnityPath
Dealing the path in Unity can be very painful.
This class provides a set of extensions to make it easier to work with file paths in Unity.
(It's still painful, but at least it's easier.)
Assembly: Glitch9.dll
Syntax
public static class UnityPath
Properties
|
Edit this page
View Source
consoleLogPath
Declaration
public static string consoleLogPath { get; }
Property Value
|
Edit this page
View Source
dataPath
Declaration
public static string dataPath { get; }
Property Value
|
Edit this page
View Source
persistentDataPath
Declaration
public static string persistentDataPath { get; }
Property Value
|
Edit this page
View Source
resourcesPath
Declaration
public static string resourcesPath { get; }
Property Value
|
Edit this page
View Source
streamingAssetsPath
Declaration
public static string streamingAssetsPath { get; }
Property Value
|
Edit this page
View Source
temporaryCachePath
Declaration
public static string temporaryCachePath { get; }
Property Value
Methods
|
Edit this page
View Source
Combine(string, string)
Declaration
public static string Combine(string basePath, string relativePath)
Parameters
Returns
|
Edit this page
View Source
CombineDataPath(string)
Declaration
public static string CombineDataPath(string relativePath)
Parameters
| Type |
Name |
Description |
| string |
relativePath |
|
Returns
|
Edit this page
View Source
Convert(string, UnityPathType)
Converts a path from one UnityPathType to another.
Declaration
public static string Convert(string path, UnityPathType to)
Parameters
Returns
|
Edit this page
View Source
DetectPathType(string)
Resolves the path type based on the given file path.
Declaration
public static UnityPathType DetectPathType(string unknownTypePath)
Parameters
| Type |
Name |
Description |
| string |
unknownTypePath |
The file path as a string
|
Returns
|
Edit this page
View Source
Extracts the path relative to the Resources folder from a full path.
Declaration
public static string ExtractResourcesPath(string fullPath)
Parameters
| Type |
Name |
Description |
| string |
fullPath |
|
Returns
|
Edit this page
View Source
Declaration
public static string FormatRelativePath(string fileName, string basePath)
Parameters
Returns
|
Edit this page
View Source
GetFileName(Object, string)
Declaration
public static string GetFileName(Object obj, string path = null)
Parameters
| Type |
Name |
Description |
| Object |
obj |
|
| string |
path |
|
Returns
|
Edit this page
View Source
GetFileUri(string)
Converts a relative path to a file URI (file://).
Declaration
public static string GetFileUri(string filePath)
Parameters
| Type |
Name |
Description |
| string |
filePath |
|
Returns
|
Edit this page
View Source
GetFullDirectoryPath(string)
Declaration
public static string GetFullDirectoryPath(string filePath)
Parameters
| Type |
Name |
Description |
| string |
filePath |
|
Returns
|
Edit this page
View Source
GetFullPath(string)
Gets the full local path (starting with C:/ or D:/) for a UnityFilePath object.
Declaration
public static string GetFullPath(string path)
Parameters
| Type |
Name |
Description |
| string |
path |
The UnityFilePath object
|
Returns
| Type |
Description |
| string |
The resolved local path as a string
|
|
Edit this page
View Source
GetRelativePath(string)
Converts a relative path to an absolute path.
Declaration
public static string GetRelativePath(string path)
Parameters
| Type |
Name |
Description |
| string |
path |
|
Returns
|
Edit this page
View Source
GetStreamingAssetsPath(string)
Declaration
public static string GetStreamingAssetsPath(string subPath)
Parameters
| Type |
Name |
Description |
| string |
subPath |
|
Returns
|
Edit this page
View Source
GetUnityObjectDefaultExtension(Object)
Declaration
public static string GetUnityObjectDefaultExtension(Object obj)
Parameters
| Type |
Name |
Description |
| Object |
obj |
|
Returns
|
Edit this page
View Source
IsProjectPath(UnityPathType)
Returns true if the path is inside the build on the device.
This includes Assets, Resources, and StreamingAssets.
Declaration
public static bool IsProjectPath(this UnityPathType pathType)
Parameters
Returns
|
Edit this page
View Source
IsProjectPath(string)
Returns true if the path is a project-relative path (starts with "Assets/" or is under Application.dataPath).
Declaration
public static bool IsProjectPath(this string path)
Parameters
| Type |
Name |
Description |
| string |
path |
|
Returns
|
Edit this page
View Source
IsValidAssetPath(string)
Checks if a given asset path is valid and safe (no traversal, within Assets folder).
Declaration
public static bool IsValidAssetPath(string path)
Parameters
| Type |
Name |
Description |
| string |
path |
|
Returns
|
Edit this page
View Source
ResolvePath(UnityPathType)
Declaration
public static string ResolvePath(UnityPathType pathType)
Parameters
Returns
|
Edit this page
View Source
SanitizeAssetPath(string)
Normalizes a Unity asset path by ensuring forward slashes are used and that it is rooted under "Assets/".
Also protects against path traversal attacks using "../" sequences.
Declaration
public static string SanitizeAssetPath(string path)
Parameters
| Type |
Name |
Description |
| string |
path |
|
Returns