Unity Editor 检查工程Prefab(预设)中的空组件
在我们做项目的过程中 经常会有预设中出现空的脚本
例如:
导致的原因是因为 脚本的丢失
现在我们来做一个检查工程中有空脚本的预设工具
老规矩直接上代码 放到工程就能用
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Collections.Generic; public class PrefabTool : EditorWindow
{
[MenuItem("Prefab Tool/Check Missing Scripts")]
static void CheckMissingScripts()
{
List<string> listString = new List<string>(); CollectFiles(Application.dataPath, listString); for (int i = ; i < listString.Count; i++)
{
string Path = listString[i]; float progressBar = (float)i / listString.Count; EditorUtility.DisplayProgressBar("Check Missing Scripts", "The progress of : " + ((int)(progressBar * )).ToString() + "%", progressBar); if (!Path.EndsWith(".prefab"))//只处理prefab文件
{
continue;
} Path = ChangeFilePath(Path); AssetImporter tmpAssetImport = AssetImporter.GetAtPath(Path); GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject>(tmpAssetImport.assetPath); if (prefab == null)
{
Debug.LogError("空的预设 : " + tmpAssetImport.assetPath); continue;
} Transform[] transforms = prefab.GetComponentsInChildren<Transform>();
//获取所有的子节点; for (int j = ; j < transforms.Length; j++)
{
GameObject obj = transforms[j].gameObject; var components = obj.GetComponents<Component>();
//获取对象所有的Component组件
//所有继承MonoBehaviour的脚本都继承Component for (int k = ; k < components.Length; k++)
{
if (components[k] == null)
{
Debug.LogError("这个预制中有空的脚本 :" + tmpAssetImport.assetPath + " 挂在对象 : " + obj.name + " 上");
}
}
}
}
EditorUtility.ClearProgressBar();
} //改变路径
//这种格式的路径 "C:/Users/XX/Desktop/aaa/New Unity Project/Assets\a.prefab" 改变成 "Assets/a.prefab"
static string ChangeFilePath(string path)
{
path = path.Replace("\\", "/");
path = path.Replace(Application.dataPath + "/", "");
path = "Assets/" + path; return path;
} //迭代获取文件路径;
static void CollectFiles(string directory, List<string> outfiles)
{
string[] files = Directory.GetFiles(directory); outfiles.AddRange(files); string[] childDirectories = Directory.GetDirectories(directory); if (childDirectories != null && childDirectories.Length > )
{
for (int i = ; i < childDirectories.Length; i++)
{
string dir = childDirectories[i];
if (string.IsNullOrEmpty(dir)) continue;
CollectFiles(dir, outfiles);
}
}
}
}
参考 Unity3D研究院编辑器之不实例化Prefab获取删除更新组件(十五) | 雨松MOMO程序研究院
链接:http://www.xuanyusong.com/archives/3727
这篇博客里面那个删除空脚本的方法 我测试 发现有问题 并不能用!
Unity Editor 检查工程Prefab(预设)中的空组件的更多相关文章
- Unity 处理预设中的中文
Unity 处理预设中的中文 需求由来 项目接入越南版本 需要解决的文本问题 获取UI预设Label里面的中文(没被代码控制)提供给越南 Label里面的中文替换成越南文 解决流程 迭代获取Asset ...
- 【Unity】3.2 利用预设(Prefab)制作可复用的组件
分类:Unity.C#.VS2015 创建日期:2016-04-02 一.简介 预制体(Prefab,也叫预设)是"存储在工程视图(Project View)中"的一种特殊的资源, ...
- Unity编程标准导引-2.2Unity中的基本概念
2.2Unity中的基本概念 上述介绍提到了几个概念:游戏对象.场景.资源.相机,这个小节我们来深入了解,同时进行一些实践性操作.不过首先,我们需要大概了解一下Unity的工程文件夹. 2.2.1工程 ...
- 编写 Unity Editor 插件
Editor Style Viewer 在开发过程中,我喜欢编写一些辅助的Editor插件,方便在游戏开发过程进行调试. 下面是摘自Asset Store的一个查看Unity 默认GUI样式的小工具 ...
- 用ECMAScript4 ( ActionScript3) 实现Unity的热更新 -- 在脚本中使用MonoBehaviour
继上次分析了热更新的Demo后,这次来介绍如何在热更新代码中使用MonoBehaviour. MonoBehaviour挂载到GameObject对象上的脚本的基类.平常Unity开发时,简单的做法就 ...
- Unity Editor 下创建Lua和Text文件
预览 在Project视图中,扩展右键菜单,右键 – Create - Text File 创建一个Text文件,或者Lua文件. 关键点 获取当前选择的路径,以Assets路径开头 var sele ...
- 【Unity】6.2 在VS2015中调试 C# 脚本
分类:Unity.C#.VS2015 创建日期:2016-04-16 一.简介 这一节先利用GUI显示一个简单的界面(以后还会专门介绍GUI),并解释如何在VS2015中调试C#脚本. 本节例子的运行 ...
- unity接入安卓sdk (unity调用安卓工程)
1.安装jdk 并且配置环境,这个网上资料很多,这里不说了 2.安卓开发软件eclipse集成环境版 下载地址 http://tools.android-studio.org/index.php/ad ...
- unity怎么把工程打包成unitypackage文件
unity怎么把工程打包成unitypackage文件 想探讨问题的原因 上课的时候,看到老师的磁盘都要爆满了,主要的原因是同学们提交的2DGameKit,工程文件太大了. 文件没有压缩,占用空间是2 ...
随机推荐
- fiddler4手机抓包
- Kafka 源代码分析之log框架介绍
这里主要介绍log管理,读写相关的类的调用关系的介绍. 在围绕log的实际处理上.有很多层的封装和调用.这里主要介绍一下调用结构和顺序. 首先从LogManager开始. 调用关系简单如下:LogMa ...
- [leetcode-582-Kill Process]
Given n processes, each process has a unique PID (process id) and its PPID (parent process id). Each ...
- USACO-palsquare 遇到的一个坑
/** ID: njuwz151 TASK: palsquare LANG: C++ */ #include <iostream> #include <cstdio> #inc ...
- Python读入CIFAR-10数据库
CIFAR-10可以去http://www.cs.toronto.edu/~kriz/cifar.html下载(记得下载python格式) CIFAR-10数据组成: 训练集和测试集分别有50000和 ...
- java对mysql的增删改查
-----连接数据库 package connectdb;import java.sql.*;class Dbcon { // 此处连接数据库,独立开一个类,以后操作数据库的每次连接就不用写这么多 p ...
- eclipse 导入git库 Android工程
1. 导入git库 1.1 从git库 clone 代码 在file->import中选中Git 目录下的Projects from Git 点击Next 选择 URL 点击Next 输入URL ...
- app 选项卡代码
<div id="segmented" class="mui-segmented-control"> <a class="mui-c ...
- 使用docker-compose搭建AspNetCore开发环境
1 使用docker-compose搭建开发环境 我们的目标很简单:使用docker-compose把若干个docker容器组合起来就成了. 首先使用Nginx代理所有的Web程序,这样只需要在主机上 ...
- Ubuntu source insight3稳定性
Ubuntu 14.04 中安装了source insight3,用wine打开.导入工程,开始查看代码. 原来是直接导入了Android所有的源码,SI同步文件很慢.而且容易出现窗口变灰色的情况.经 ...