Unity 3D
来源:互联网 发布:淘宝店铺导航栏代码 编辑:程序博客网 时间:2024/06/07 21:54
Unity 3D - 编辑器扩展之删除Miss脚本 :
C#代码 :
1.显示工具面板 :
[MenuItem("Tools/资源/删除所有Prefab上的Miss脚本")] static public void DeleteMissScript() { EditorWindow.GetWindow<DeleteMissScript>("删除所有Prefab上的Miss脚本").Show(); }
2.检索所有丢失脚本的Prefab :
using System.Collections.Generic;using UnityEngine;using UnityEditor;using System.IO;using System.Linq;namespace CZGame{ public class DeleteMissScript : EditorWindow { Vector2 scrollPos = Vector2.zero; List<string> pathList = new List<string>(); List<GameObject> missObj = new List<GameObject>(); private void CleanupMissingScripts() { foreach (GameObject obj in missObj) { var components = obj.GetComponents<Component>(); var serializedObject = new SerializedObject(obj); var prop = serializedObject.FindProperty("m_Component"); int r = 0; for (int j = 0; j < components.Length; j++) { if (components[j] == null) { prop.DeleteArrayElementAtIndex(j - r); r++; } } serializedObject.ApplyModifiedProperties(); EditorUtility.SetDirty(obj); } } private void CheckMissingScripts() { List<string> withoutExtensions = new List<string>() { ".prefab" }; string[] files = Directory.GetFiles(Application.dataPath + "/GameRes/UIPrefab", "*.*", SearchOption.AllDirectories) .Where(s => withoutExtensions.Contains(Path.GetExtension(s).ToLower())).ToArray(); int count = 0; foreach (string fileName in files) { count++; EditorUtility.DisplayProgressBar("Processing...", "搜寻所有Prefab....", count / files.Length); string fixedFileName = fileName.Replace("\\","/"); int index = fixedFileName.IndexOf("Assets"); fixedFileName = fixedFileName.Substring(index); pathList.Add(fixedFileName); } EditorUtility.ClearProgressBar(); int count2 = 0; foreach (string path in pathList) { count2++; EditorUtility.DisplayProgressBar("Processing...", "遍历丢失脚本Prefab中....", count / pathList.Count); GameObject obj = (GameObject)AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)); getAllChild(obj); GameObject[] child = obj.GetChildren(); } EditorUtility.ClearProgressBar(); } void getAllChild(GameObject obj) { GameObject[] childArr = obj.GetChildren(); foreach (GameObject child in childArr) { var components = child.GetComponents<Component>(); var serializedObject = new SerializedObject(child); var prop = serializedObject.FindProperty("m_Component"); for (int j = 0; j < components.Length; j++) { if (components[j] == null) { missObj.Add(child); } } getAllChild(child); } } void OnGUI() { scrollPos = EditorGUILayout.BeginScrollView(scrollPos); if (GUILayout.Button("[删除所有Prefab上的Miss脚本]", GUILayout.Width(300))) { CleanupMissingScripts(); } if (GUILayout.Button("[检查Prefab脚本Miss情况]", GUILayout.Width(300))) { pathList = new List<string>(); missObj = new List<GameObject>(); CheckMissingScripts(); } EditorGUILayout.Space(); EditorGUILayout.Space(); foreach (GameObject obj in missObj) { EditorGUILayout.ObjectField(obj, typeof(GameObject), false); } EditorGUILayout.EndScrollView(); } }}
阅读全文
0 0
- Unity 3D
- unity 3d 注意事项
- Unity 3d 摄像头
- Unity 3D 使用
- Unity 3D--PlayerPrefs
- Unity 3d
- Unity 3D俄罗斯方块
- unity 3d 多开
- UNITY 3D笔记
- Unity 3D接触
- unity 3d
- Unity 3D简介
- Unity 3D 琐记
- unity 3d 视频
- Unity 3D 光源
- Unity 3D FingerID
- 再议Unity 3D
- unity 3d 网址
- 二叉树中的排序树,Java版
- (POJ
- 走心安利: 工作中简单易用的开发工具
- Mac版IDEA入门
- SpringMVC统一异常处理 返回JSON解决方案
- Unity 3D
- angularjs 做一个笔记本
- deep learning 调试
- 记录一下spring的设置注入 构造器注入
- sklearn 数据加载,数据归一,特征选择,逻辑回归,贝叶斯,k近邻,决策树,SVM
- python中字符编码问题详解
- intellij 配置jrebel
- hdu 6208 The Dominator of Strings
- eclipse中tomcat能正常启动,但是浏览器访问不了tomcat首页 问题解决