Unity 脚本接口值Path
来源:互联网 发布:中小学网络答题活动 编辑:程序博客网 时间:2024/06/01 10:17
前言
在做游戏或者应用的时候,我们往往会考虑到本地存储数据。但是本地存储数据的时候我们需要考虑到路径的正确性。我们通常会使用Path类中封装的方法来实现。
Path
Path类位于 System.IO;程序集中,主要用于处理与路径相关的字符串。
Path中的方法和字段:
namespace System.IO{ [ComVisible(true)] public static class Path { public static readonly char AltDirectorySeparatorChar; public static readonly char DirectorySeparatorChar; public static readonly char PathSeparator; public static readonly char VolumeSeparatorChar; public static string ChangeExtension(string path, string extension); public static string Combine(string path1, string path2); public static string GetDirectoryName(string path); public static string GetExtension(string path); public static string GetFileName(string path); public static string GetFileNameWithoutExtension(string path); public static string GetFullPath(string path); public static char[] GetInvalidFileNameChars(); public static char[] GetInvalidPathChars(); public static string GetPathRoot(string path); public static string GetRandomFileName(); public static string GetTempFileName(); public static string GetTempPath(); public static bool HasExtension(string path); public static bool IsPathRooted(string path); }}
一些常用的方法
void Start () { string path = "D:/Test/A/B/C.jpg"; Debug.Log(Path.GetDirectoryName(path)); Debug.Log(Path.GetFullPath(path)); Debug.Log(Path.GetExtension(path)); Debug.Log(Path.GetFileNameWithoutExtension(path)); Debug.Log(Path.GetFileName(path)); }
输出:
D:/Test/A/BD:\Test\A\B\C.jpg.jpgCC.jpg
通过名字对于后面三个方法比较好理解,对于前两个函数进行仔细分析。
Path.GetDirectoryName(path)
获取到路径除了文件名和文件扩展名的其他内容,也就是获得文件夹的路径。
Path.GetFullPath(path)
获得完整路径,包括文件名和文件扩展名,但是按照了运行系统的习惯进行了修改。
阅读全文
0 0
- Unity 脚本接口值Path
- Unity学习基本脚本之接口
- [Unity&接口]建立管理时间速度tiemSpeed的控制脚本
- Unity脚本
- unity 脚本
- Unity-脚本
- unity---接口
- Unity Render Path
- Unity 设置Android SDK path
- Unity脚本编绎
- Unity脚本周期关系
- unity脚本小总结
- unity脚本生命周期
- Unity脚本的属性
- unity 脚本生命周期
- unity脚本技术框架
- unity C#脚本规则
- Unity 脚本生命周期流程图
- 树莓派引脚相对位置示意图
- 瞎写点什么
- 【WebGL】茶壶和光照
- uva10142
- android的动画
- Unity 脚本接口值Path
- struts2框架搭建
- Scikit-learn——Naive Bayes
- Eclipse 设置新建jsp文件的默认模板
- Vocabulary
- VS编译报错 error MSB6006: “cmd.exe” exited with code 1.
- 7.5
- 。。。
- Docker介绍