PathUtility¶
Namespace:
SideXP.Core
Miscellaneous functions for working with path strings.
Fields¶
DefaultDirectorySeparator¶
The character used by default as path directory separator.
AssetsDirectory¶
Name of the /Assets directory.
ResourcesDirectory¶
Name of the /Resources directory.
BaseResourcesPath¶
The base relative path to the /Resources directory at the root of the /Assets directory.
ProjectPath¶
The absolute path to this project. In the editor, this is the path to the project's folder (the root folder, not /Assets). In build, it's the path to the persistent data path directory (same as PersistentDataPath). This value is meant to be used by custom editors or in-game features that require to store persistent data.
DataPath¶
The absolute path to the game content directory. In the editor, this is the path to the project's /Assets folder. In build, it's the path to the folder that contains the game executable. Note that in build, that directory is readonly, so you must use PersistentDataPath to store persistent data.
See also
-
PersistentDataPath¶
The absolute path to the persistent data directory. This path varies from plaforms, but is guaranteed to be writable, so you can use it to store persistent data.
See also
-
TemporaryDataPath¶
The absolute path to the temporary data directory.
See also
-
Methods¶
ToPath(string, bool, char)¶
Converts the given string into a path, by removing forbidden characters and using a single character as directory separator.
Parameters
str: The string to convert.normalize: If enabled, the path is resolved to its full path (in the editor, this also resolvesPackages/...virtual paths to their actual folder).separator: The character to use as directory separator.
Returns
Returns the converted string.
Example
PathUtility.ToPath("Assets\\Foo\\Bar"); // "Assets/Foo/Bar"
PathUtility.ToPath("Assets/Foo/Bar", separator: '\\'); // "Assets\Foo\Bar"
ToPath(string, bool, char)¶
Converts the given string into a path, by removing forbidden characters and using a single character as directory separator.
Parameters
str: The string to convert.normalize: If enabled, the path is resolved to its full path (in the editor, this also resolvesPackages/...virtual paths to their actual folder).separator: The character to use as directory separator.
Returns
Returns the converted string.
Example
PathUtility.ToPath("Assets\\Foo\\Bar"); // "Assets/Foo/Bar"
PathUtility.ToPath("Assets/Foo/Bar", separator: '\\'); // "Assets\Foo\Bar"
ToPaths(IEnumerable<string>, bool, char)¶
public static string[] ToPaths(IEnumerable<string> strs, bool normalize = false, char separator = '/')
Converts the given strings into paths, by removing forbidden characters and use the same character as directory separator.
Parameters
strs: The collection of strings to convert.
ToAbsolutePath(string)¶
If the given string represents a relative path, it's combined with ProjectPath to make it absolute.
Parameters
path: The path string to convert. If that path is already absolute, this function returns it as is. If it's null or empty, this function returns the value of ProjectPath.
Returns
Returns the absolute path string.
Example
// Assuming the project is at "C:/dev/MyProject":
PathUtility.ToAbsolutePath("Assets/Foo"); // "C:/dev/MyProject/Assets/Foo"
PathUtility.ToAbsolutePath(""); // the project path
ToAbsolutePath(string)¶
If the given string represents a relative path, it's combined with ProjectPath to make it absolute.
Parameters
path: The path string to convert. If that path is already absolute, this function returns it as is. If it's null or empty, this function returns the value of ProjectPath.
Returns
Returns the absolute path string.
Example
// Assuming the project is at "C:/dev/MyProject":
PathUtility.ToAbsolutePath("Assets/Foo"); // "C:/dev/MyProject/Assets/Foo"
PathUtility.ToAbsolutePath(""); // the project path
ToRelativePath(string, bool)¶
If the given string represents an absolute path leading to this project, this function makes it relative to ProjectPath.
Parameters
path: The path string to convert. If that path is already relative, this function returns it as is. If it's null or empty, this function returns an empty string.
Returns
Returns the relative path string.
Example
// Assuming the project is at "C:/dev/MyProject":
PathUtility.ToRelativePath("C:/dev/MyProject/Assets/Foo"); // "Assets/Foo"
PathUtility.ToRelativePath("Assets/Foo"); // "Assets/Foo" (already relative)
ToRelativePath(string, bool)¶
If the given string represents an absolute path leading to this project, this function makes it relative to ProjectPath.
Parameters
path: The path string to convert. If that path is already relative, this function returns it as is. If it's null or empty, this function returns an empty string.
Returns
Returns the relative path string.
Example
// Assuming the project is at "C:/dev/MyProject":
PathUtility.ToRelativePath("C:/dev/MyProject/Assets/Foo"); // "Assets/Foo"
PathUtility.ToRelativePath("Assets/Foo"); // "Assets/Foo" (already relative)
IsProjectPath(string)¶
Checks if the given path leads to this project.
Parameters
path: The path string to check. If that path is relative this function returns true.
Returns
Returns true if the given path leads to this project.
Example
PathUtility.IsProjectPath("Assets/Foo"); // true (relative paths are project paths)
PathUtility.IsProjectPath("C:/dev/MyProject/Assets/Foo"); // true
PathUtility.IsProjectPath("C:/Windows/System32"); // false
IsProjectPath(string)¶
Checks if the given path leads to this project.
Parameters
path: The path string to check. If that path is relative this function returns true.
Returns
Returns true if the given path leads to this project.
Example