Tools(一)——BuildMethod
来源:互联网 发布:女生相机软件 编辑:程序博客网 时间:2024/06/05 02:50
Tools这几篇都是写的都是这个目录下的文件BuildMethod.cs文件目录为Assets/Scripts/Tools/Editor/BuildMethod.cs
因为都写好注释了,下面是所有代码:
using UnityEngine;using UnityEditor;using System.IO;using System.Collections; public class BuildMethod { //public static string getNameByPath(string path) //{ // String[] words = path.Split(new char[] { '/','\\' }); // if (words != null && words.Length != 0) // { // String[] splitstr = words[words.Length - 1].Split(new char[] { '.' }); // if (splitstr != null && splitstr.Length != 0) // { // String name = splitstr[0]; // return name; // } // } // return ""; //} //这函数很有问题,下面完全是越界了。 //path指的是在磁盘上的地址:Application.dataPath + /Resources/Version.bytes这样子的 //这个函数实际上是要返回资源相对于Resources文件夹的路径 //例如:传入的path为Resources/prefab/test.prefab, //这个时候下面循环中的count + 3完全越界了, //所以这函数有问题 //但是也有可能在用的地方有特殊情况 //所以我在下面重新写了一个函数,这个函数不修改 public static string getUnityPathInResourceFolder(string path) { //根据正斜杠和反斜杠把字符串分开成多个字符串 string[] rootwords = Application.dataPath.Split(new char[] { '/', '\\' }); int count = rootwords.Length; string[] words = path.Split(new char[] { '/', '\\' }); if (words != null) { //我测试过,这里count + 2 很有可能会越界了,编译都通不过的 string rtvalue = words[count + 2]; for (int i = count + 3; i < words.Length; ++i) { rtvalue += ("/" + words[i]); } return rtvalue; } return ""; } /* public static string getUnityPathInResourceFolder(string path) { string[] rootwords = Application.dataPath.Split(new char[] { '/', '\\' }); int count = rootwords.Length; string[] words = path.Split(new char[] { '/', '\\' }); if (words != null) { string rtvalue = words[count + 1]; if ((count + 2) < words.Length) { for (int i = count + 2; i < words.Length; i++) { rtvalue += ("/" + words[i]); } } return rtvalue; } return ""; } */ //看嘛,这下面这函数就完全正常了 //例如:path = Applicaition.dataPath + "/Resources/Version.bytes" //返回的就会是 Assets/Resources/Version.bytes //不过感觉也可以用另一种方法来拼接这个的返回值 public static string getUnityPath(string path) { string[] rootwords = Application.dataPath.Split(new char[] { '/', '\\' }); int count = rootwords.Length; string[] words = path.Split(new char[] { '/', '\\' }); if (words != null) { string rtvalue = words[count - 1]; for (int i = count; i < words.Length; ++i) { rtvalue += ("/" + words[i]); } return rtvalue; } return ""; } //这函数把路径中的正斜杠反斜杠都换成下划线了,也去掉了空格. //但是暂时还不知道该怎么样 public static string getShaderName(string sName) { //for (int i = 0; i < sName.Length; ++i) //{ // if (sName[i] == '/' && sName[i] == '\\') // { // sName. = '_'; // } //} string[] words = sName.Split(new char[] {' ','/', '\\' }); string retstr = words[0]; for (int i = 1; i < words.Length; ++i) { retstr += ('_' + words[i]); } return retstr; } }
阅读全文
0 0
- Tools(一)——BuildMethod
- CPN Tools 入门(一)
- jQuery Tools——不可错过的jQuery UI库(一)
- Siebel Tools 开发学习笔记(一)
- panel 中的tools使用(一)
- Siebel Tools 开发学习笔记(一)
- Tools(二)——BytesAdd
- Tools(三)——CollsionDetection
- Tools(四)——FileU3DBuild
- Tools——PVRTrace
- IOS Developer Tools(一)
- Tools——Snapdragon Profiler
- Jquery Tools介绍—Tooltips
- WebIDE—Firefox Developer Tools
- Delphi Open Tools Api实例研究(一)
- Delphi Open Tools Api实例研究(一)
- Delphi Open Tools Api实例研究(一)
- Delphi Open Tools Api实例研究(一)
- 微信公众号文章关键字
- springMVC中多数据源切换的两种主流实现方法(一)
- EL
- mysql替换Oracle中的ROWNUM
- 关于BigDecimal截取小数位数
- Tools(一)——BuildMethod
- SpringMVC注解开发方式二
- 创建maven多模块项目及ssm整合
- Git for windows 修改Home路径(版本号:2.14)
- JS内置对象4:Date
- java Restful框架,jersey入门例子
- Android Camera2 拍照(四)——对焦模式
- Android获取通讯录联系人的正确姿势
- Window系统cmd黑窗口查看端口占用、相应进程、杀死进程的命令