buildAsset分析(二)——BuildCommon
来源:互联网 发布:大数据营销医药公司 编辑:程序博客网 时间:2024/05/17 08:20
BuildCommon.cs这个文件主要是用于build的工具类,里面放着要用到的工具函数。
using System;using System.IO;using UnityEngine;using UnityEditor;using System.Collections;using System.Collections.Generic;using Object = UnityEngine.Object; public class BuildCommon { //我测试过,实际上这个函数是get了文件的不包含目录的文件名, //而不是folder... //但是我决定还是不修改它 public static string getFolder(string path) { path = path.Replace("\\", "/"); int index = path.LastIndexOf("/"); if (-1 == index) throw new Exception("can not find /!!!"); return path.Substring(index + 1, path.Length - index - 1); } //get文件的文件名(包括目录,不包括后缀) public static string getFileName(string fileName) { int index = fileName.IndexOf("."); if (-1 == index) throw new Exception("can not find .!!!"); return fileName.Substring(0, index); } //suffix值决定返回的文件名是否包括后缀(包括目录) public static string getFileName(string filePath,bool suffix) { if (!suffix) { string path = filePath.Replace("\\", "/"); int index = path.LastIndexOf("/"); if (-1 == index) throw new Exception("can not find .!!!"); int index2 = path.LastIndexOf("."); if (-1 == index2) throw new Exception("can not find /!!!"); return path.Substring(index + 1, index2 - index - 1); } else { //这里代码实际上就和getFolder一模一样 string path = filePath.Replace("\\", "/"); int index = path.LastIndexOf("/"); if (-1 == index) throw new Exception("can not find /!!!"); return path.Substring(index + 1, path.Length - index - 1); } } //获取文件的后缀名 public static string getFileSuffix(string filePath) { int index = filePath.LastIndexOf("."); if (-1 == index) throw new Exception("can not find Suffix!!! the filePath is : " + filePath); return filePath.Substring(index + 1, filePath.Length - index - 1); } //递归目录下的所有文件(除svn,meta,dll文件外),加入到list(里面有AssetUnit)中去 public static void getFiles(string path, ref Dictionary<string, AssetUnit> list) { string[] dirs = Directory.GetDirectories(path); foreach (string dir in dirs) { if (getFolder(dir) == ".svn") continue; getFiles(dir, ref list); } string[] files = Directory.GetFiles(path); foreach (string file in files) { string suffix = getFileSuffix(file); if (suffix == "meta" || suffix == "dll") continue; string realFile = file.Replace("\\", "/"); realFile = "Assets" + realFile.Replace(Application.dataPath,""); list.Add(realFile, new AssetUnit(realFile)); } } //递归目录下的所有文件(除svn,meta,dll文件外),加入到list中去 public static void GetFiles(string path, List<string> list, bool recursion) { if (recursion) { string[] dirs = Directory.GetDirectories(path); foreach (string dir in dirs) { if (getFolder(dir) == ".svn") continue; GetFiles(dir, list, recursion); } } string[] files = Directory.GetFiles(path); foreach (string file in files) { string suffix = getFileSuffix(file); if (suffix == "meta") continue; string realFile = file.Replace("\\", "/"); realFile = realFile.Replace(Application.streamingAssetsPath + "/", ""); list.Add(realFile); } } //检查path下是否有speicalName文件。有的话就加入allPath里面。recursion必须为true才行 public static void getFloder(string path, string specialName, bool recursion, List<string> allPath) { if (recursion) { string[] dirs = Directory.GetDirectories(path); foreach (string dir in dirs) { if (getFolder(dir) == specialName) allPath.Add(dir); getFloder(dir, specialName, recursion, allPath); } } } //这里所谓的AssetLevel其实就是指资源的依赖数量 //有1个依赖,则level为1, //有两个依赖,则level为2. public static int getAssetLevel(string filePath) { string[] depencys = AssetDatabase.GetDependencies(new string[] { filePath }); List<string> deps = new List<string>(); foreach (string file in depencys) { //排除关联脚本 string suffix = BuildCommon.getFileSuffix(file); //if (suffix == "dll" || suffix == "cs") if (suffix == "dll") continue; deps.Add(file); } if (deps.Count == 1) return 1; int maxLevel = 0; foreach (string file in deps) { if (file == filePath) continue; int level = getAssetLevel(file); maxLevel = maxLevel > level + 1 ? maxLevel : level + 1; } return maxLevel; } //检查目录,没有就创建 public static void CheckFolder(string path) { if (!Directory.Exists(path)) Directory.CreateDirectory(path); } //获取文件的path,把文件名剔除掉以后的。 public static string getPath(string filePath) { string path = filePath.Replace("\\", "/"); int index = path.LastIndexOf("/"); if (-1 == index) throw new Exception("can not find /!!!"); return path.Substring(0, index); } //判断asset是否是sourceAsset的依赖 public static bool isDependenced(string asset,string sourceAsset) { string[] deps = AssetDatabase.GetDependencies(new string[] { sourceAsset }); bool isDep = false; foreach (string path in deps) { if (path == sourceAsset) continue; if (path == asset) return true; isDep = isDependenced(asset,path); } return isDep; } //检查asset是否只有一个直接依赖. public static bool isSingleDependenced(AssetUnit asset) { if (asset.mDirectUpperDependences.Count > 1) return false; else if (asset.mDirectUpperDependences.Count == 1) return isSingleDependenced(asset.mDirectUpperDependences[0]); else return true; }
阅读全文
0 0
- buildAsset分析(二)——BuildCommon
- buildAsset分析(三)——BuildAssetBundle
- buildAsset分析(一)——AssetUnit
- BuildAsset-场景测试
- 商业分析——竞争(二)
- Android Contacts源码分析二——(PeopleActivity)分析
- 内核启动分析(二)——do_bootm_linux分析
- jemeter分析(二) — jmeter案例分析
- 编译原理实验二——语法分析(预测分析)
- 产品设计体会(二)——数据分析
- 软件需求——需求分析(二)
- 加密算法(二)——【DES算法实现过程分析】
- Android、JUnit深入浅出(二)——JUnit例子分析
- GCC源码分析(二)——前端
- Android开发——MediaProvider源码分析(二)
- 现有游戏引擎分析——3D(二)
- 一句一句分析goagent 源代码(二)——proxy.py
- glance-0.1.7 分析(二)—— 构建文档
- set_include_path和get_include_path用法详解
- linux下的用户管理详解
- 启动mysql发现.socket错误,一般是mysql启动了两次。
- Linux命令大全
- html计算机
- buildAsset分析(二)——BuildCommon
- Linux Shell脚本攻略1:小试牛刀(2)
- 存储过程 c# 基础封装 学习之用
- Java八大排序算法
- spring boot Rabbitmq集成,延时消息队列实现
- 数据结构概念篇
- web前端与php后台做个简单的前后交互,传递数组,制作jquery版tab切换
- 京东 笔试 编程
- 亲测GO环境搭建,理解go build、go install、go get