Unity3D开发之查找面板上某个脚本(包括Missing)
开发 脚本 查找 某个 Unity3D 包括 missing 面板
2023-09-14 08:57:08 时间
原地址:http://blog.csdn.net/lihandsome/article/details/24265411
有时候我们需要知道某个脚本在场景上面哪里用到,或者那个脚本被删除了但又没有把相关游戏场景的关联东西删掉,那样我们就要一个脚本来查找一下了:
PS:下面两个脚本都要放到assets/Editor下面哦。。
查找missing的脚本:
- using UnityEngine;
- using UnityEditor;
- public class FindMissingScriptsRecursively : EditorWindow
- {
- static int go_count = 0, components_count = 0, missing_count = 0;
- [MenuItem("Window/FindMissingScriptsRecursively")]
- public static void ShowWindow()
- {
- EditorWindow.GetWindow(typeof(FindMissingScriptsRecursively));
- }
- public void OnGUI()
- {
- if (GUILayout.Button("Find Missing Scripts in selected GameObjects"))
- {
- FindInSelected();
- }
- }
- private static void FindInSelected()
- {
- GameObject[] go = Selection.gameObjects;
- go_count = 0;
- components_count = 0;
- missing_count = 0;
- foreach (GameObject g in go)
- {
- FindInGO(g);
- }
- Debug.Log(string.Format("Searched {0} GameObjects, {1} components, found {2} missing", go_count, components_count, missing_count));
- }
- private static void FindInGO(GameObject g)
- {
- go_count++;
- Component[] components = g.GetComponents<Component>();
- for (int i = 0; i < components.Length; i++)
- {
- components_count++;
- if (components[i] == null)
- {
- missing_count++;
- string s = g.name;
- Transform t = g.transform;
- while (t.parent != null)
- {
- s = t.parent.name +"/"+s;
- t = t.parent;
- }
- Debug.Log (s + " has an empty script attached in position: " + i, g);
- }
- }
- // Now recurse through each child GO (if there are any):
- foreach (Transform childT in g.transform)
- {
- //Debug.Log("Searching " + childT.name + " " );
- FindInGO(childT.gameObject);
- }
- }
- }
查找某个脚本的脚本:
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEditor;
- /////////////////////////////////////////////////////////////////////////////
- //查找节点及所有子节点中,是否有指定的脚本组件
- /////////////////////////////////////////////////////////////////////////////
- public class MonoFinder : EditorWindow {
- Transform root = null;
- MonoScript scriptObj = null;
- int loopCount = 0;
- List<Transform> results = new List<Transform>();
- [MenuItem("Level4/Finder/MonoFinder")]
- static void Init(){
- EditorWindow.GetWindow(typeof(MonoFinder));
- }
- void OnGUI(){
- GUILayout.Label("节点:");
- root = (Transform)EditorGUILayout.ObjectField(root,typeof(Transform),true);
- GUILayout.Label("脚本类型:");
- scriptObj = (MonoScript)EditorGUILayout.ObjectField(scriptObj,typeof(MonoScript),true);
- if(GUILayout.Button("Find")){
- results.Clear();
- loopCount = 0;
- Debug.Log("开始查找.");
- FindScript(root);
- }
- if(results.Count > 0){
- foreach(Transform t in results){
- EditorGUILayout.ObjectField(t,typeof(Transform),false);
- }
- }else{
- GUILayout.Label("无数据");
- }
- }
- void FindScript(Transform root){
- if(root != null && scriptObj != null){
- loopCount ++;
- Debug.Log(".."+loopCount+":"+root.gameObject.name);
- if( root.GetComponent(scriptObj.GetClass()) != null){
- results.Add(root);
- }
- foreach(Transform t in root){
- FindScript(t);
- }
- }
- }
- }
相关的链接:
http://wiki.unity3d.com/index.php?title=FindMissingScripts
http://superherosk123.iteye.com/blog/1632627
相关文章
- 《安富莱嵌入式周报》第280期:支持在线仿真编程的网页版电子开发,CAN总线防攻击实现,BigFAT 规范打破了 FAT 每个文件 4GB 的限制
- 驱动开发:摘链DKOM进程隐藏
- java大数据开发需要掌握什么_大数据要学java吗
- 【架构师(第四十篇)】 服务端开发之连接 Mongodb 数据库
- 常用IDA脚本开发API
- 助力工业物联网,工业大数据之脚本开发【五】
- 【Android 应用开发】Android 上实现非root的 Traceroute -- 非Root权限下移植可执行二进制文件 脚本文件
- 【Android FFMPEG 开发】Android Studio 工程配置 FFMPEG ( 动态库打包 | 头文件与函数库拷贝 | CMake 脚本配置 )
- 【Android APT】编译时技术 ( 开发编译时注解 )
- 【错误记录】Flutter 混合开发获取 BinaryMessenger 报错 ( FlutterActivityAndFragmentDelegate.getFlutterEngine() )
- iOS开发–JSON详解手机开发
- 开发Linux命令脚本开发实战(linux命令脚本)
- 开发Linux脚本服务进行快速开发(linux脚本服务)
- Linux图形界面API:开启简单而强大的开发之旅(linux图形界面api)
- 拟机Linux字体虚拟机:开发全新视界(linux字体虚)
- MongoDB自动化脚本开发实战(mongodb脚本)
- Linux下的Bin/Sh脚本实现快速开发(linuxbinsh)
- 开发SD Linux驱动开发:开启新时代之门(SDLinux驱动)
- shell脚本中调用redis减少开发时间(shell调用redis)
- 解决JSP开发中Web程序显示中文三种方法