文件流方式 删除prefab空脚本
2024-08-26 12:51:35
/// <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);
}
}
最新文章
- Redis简单案例(一) 网站搜索的热搜词
- 数据结构作业——Fresh Meat(优先队列)
- Nginx的继续深入(日志轮询切割,重写,负载均衡等)
- EF测试自动修改数据库结构
- win7安装apache或者php 5.7缺少vcruntime140.dll的问题
- Java Hour 48 Servlet 简介
- 解决HierarchyViewer不能连接真机的问题
- TextView使用Spannable设置复合文本
- 抓取&ldquo;矢量&rdquo;的实时交通流量数据
- MFC调试小技巧
- C# 根据IP获取省市
- python学习笔记之列表与元组
- (@WhiteTaken)设计模式学习——享元模式
- D - MUH and Cube Walls
- webservice安全性浅谈
- VIM_manual
- CentOS7系列--1.1CentOS7安装
- 在eclipse中配置server和database
- PyQt4 QListWidget 使用教程
- AcWing 143. 最大异或对
热门文章
- 【微信小程序】tabBar的显示问题
- Qwe中的数值结算
- MySql5.7配置文件my.cnf设置
- 无法转换json问题 Error: Model.nodeDataArray value is not an instance of Array or NodeList or HTMLCollection
- 实现JTextfield 的右键 复制、剪切、粘贴功能。
- Struts2,Spring,Hibernate框架的优缺点
- 关于javascrpt if快速判断说明
- SSh on Ubuntu
- php 从1加到100
- 关于Unity3D中鼠标移动指定物体的解决方案