检测prefab身上关联的shader
2015-12-12 16:13
363 查看
public static void GetShaderInfo() { UnityEngine.Object[] arr = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.TopLevel); if (arr.Length <= 0) { Logger.Instance.LogError("请选择Project->右部分的目录!"); return; } Dictionary<string, List<string>> shaderDic = new Dictionary<string, List<string>>(); string pathChoosen = Application.dataPath.Substring(0, Application.dataPath.LastIndexOf("Assets")) + AssetDatabase.GetAssetPath(arr[0]); Logger.Instance.Log(pathChoosen); //string[] relativePaths = MyDirectory.GetWholeFilesPathFromDirectory(pathChoosen); UnityEngine.Object[] selection = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets); string[] relativePaths = (from s in selection let relativePath = AssetDatabase.GetAssetPath(s) where File.Exists(relativePath) select relativePath).ToArray(); foreach (UnityEngine.Object obj in selection) { string path = obj.name; //string[] list = AssetDatabase.GetDependencies(new string[] { path });//获取指定路径预设的依赖所有资源列表 UnityEngine.Object[] list = EditorUtility.CollectDependencies(new UnityEngine.Object[] { obj }); if (list == null || list.Length == 0) continue; for (int index = 0; index < list.Length; index++) { UnityEngine.Object target = list[index]; if (target == null) { continue; } string pathName = target.name; //string fileName = pathName.Substring(pathName.LastIndexOf('/')+1); //string extensionName = fileName.Substring(fileName.LastIndexOf('.')); if (list[index] is Shader) { if (pathName.StartsWith("Particles/")) { if (shaderDic.ContainsKey(pathName)) { shaderDic[pathName].Add(path); } else { List<string> tempist = new List<string>(); shaderDic.Add(pathName, tempist); shaderDic[pathName].Add(path); } } } } } foreach (string key in shaderDic.Keys) { List<string> list = shaderDic[key]; if (list.Count >= 1) { string url = Application.persistentDataPath + "/shader.txt"; FileIO.SaveTextFile(url, "shader =" + key + "<----------------------------"); foreach (string value in list) { FileIO.SaveTextFile(url,key +"----------"+ value); } } } }
项目中做热更的时候,发现有一些特效身上用的shader是Particle/开头的,而不是 Mobie/Particle开头的,要检测出具体哪些属于这种情况,做了个检测的方法。
相关文章推荐
- unity实现多点触控代码
- 在Unity中实现动画的正反播放代码
- unity实现摄像头跟随
- Unity3D上路_01-2D太空射击游戏
- Unity3D上路_02-第一视角射击游戏
- Unity3D上路_03-塔防游戏
- Unity3D上路_04-基础资源介绍
- Unity3D上路_05-网络相关
- [软件资讯]Unity已支持将3D游戏导出成Flash
- Unity 武器拖尾效果
- unity常见问题之20题
- Unity3D动画存储插件
- unity 赛车相机跟随物体移动
- Unity 预编译宏
- Unity AssetDatabase类
- VS2013中 命名空间“UnityEngine”中不存在类型或命名空间名称“UI”。是否缺少程序集引用?
- unity 实现炸弹人放炸弹后只进不出的一种方法
- Unity3D占用内存太大的解决方法
- 【Unity】安卓项目使用带有资源Jar包SDK的打包方法
- Unity2d 5.1 弱联网游戏制作 (一)场景创建、添加组件、精灵移动、主摄像机跟随