/// <summary>
/// 删除一个Prefab上的空脚本
/// </summary>
/// <param name="path">prefab路径 例Assets/Resources/FriendInfo.prefab</param>
private void DeleteNullScript(string path)
{
bool isNull = false;
string s = File.ReadAllText(path); Regex regBlock = new Regex("MonoBehaviour"); // 以"---"划分组件
string[] strArray = s.Split(new string[] { "---" }, StringSplitOptions.RemoveEmptyEntries); for (int i = ; i < strArray.Length; i++)
{
string blockStr = strArray[i]; if (regBlock.IsMatch(blockStr))
{
// 模块是 MonoBehavior
Match guidMatch = Regex.Match(blockStr, "m_Script: {fileID: (.*), guid: (?<GuidValue>.*?), type:");
if (guidMatch.Success)
{
// 获取 MonoBehavior的guid
string guid = guidMatch.Groups["GuidValue"].Value;
//Debug.Log("Guid:" + guid); if (string.IsNullOrEmpty(GetScriptPath(guid)))
{
// 工程中无此脚本 空脚本!!!
//Debug.Log("空脚本");
isNull = true; // 删除操作 // 删除MonoScript
s = s.Replace("---" + blockStr, ""); Match idMatch = Regex.Match(blockStr, "!u!(.*) &(?<idValue>.*?)\r");
if (idMatch.Success)
{
// 获取 MonoBehavior的guid
string id = idMatch.Groups["idValue"].Value; // 删除MonoScript的引用
Regex quote = new Regex(" - (.*): {fileID: " + id + "}");
s = quote.Replace(s, "");
} } } } } if (isNull)
{
// 有空脚本 写回prefab
File.WriteAllText(path, s); // 打印Log
Debug.Log(path);
}
}

最新文章

  1. Redis简单案例(一) 网站搜索的热搜词
  2. 数据结构作业——Fresh Meat(优先队列)
  3. Nginx的继续深入(日志轮询切割,重写,负载均衡等)
  4. EF测试自动修改数据库结构
  5. win7安装apache或者php 5.7缺少vcruntime140.dll的问题
  6. Java Hour 48 Servlet 简介
  7. 解决HierarchyViewer不能连接真机的问题
  8. TextView使用Spannable设置复合文本
  9. 抓取&ldquo;矢量&rdquo;的实时交通流量数据
  10. MFC调试小技巧
  11. C# 根据IP获取省市
  12. python学习笔记之列表与元组
  13. (@WhiteTaken)设计模式学习——享元模式
  14. D - MUH and Cube Walls
  15. webservice安全性浅谈
  16. VIM_manual
  17. CentOS7系列--1.1CentOS7安装
  18. 在eclipse中配置server和database
  19. PyQt4 QListWidget 使用教程
  20. AcWing 143. 最大异或对

热门文章

  1. 【微信小程序】tabBar的显示问题
  2. Qwe中的数值结算
  3. MySql5.7配置文件my.cnf设置
  4. 无法转换json问题 Error: Model.nodeDataArray value is not an instance of Array or NodeList or HTMLCollection
  5. 实现JTextfield 的右键 复制、剪切、粘贴功能。
  6. Struts2,Spring,Hibernate框架的优缺点
  7. 关于javascrpt if快速判断说明
  8. SSh on Ubuntu
  9. php 从1加到100
  10. 关于Unity3D中鼠标移动指定物体的解决方案