原地址:http://blog.csdn.net/lihandsome/article/details/24265411

有时候我们需要知道某个脚本在场景上面哪里用到,或者那个脚本被删除了但又没有把相关游戏场景的关联东西删掉,那样我们就要一个脚本来查找一下了:

PS:下面两个脚本都要放到assets/Editor下面哦。。

查找missing的脚本:

  1. using UnityEngine;
  2. using UnityEditor;
  3. public class FindMissingScriptsRecursively : EditorWindow
  4. {
  5. static int go_count = 0, components_count = 0, missing_count = 0;
  6. [MenuItem("Window/FindMissingScriptsRecursively")]
  7. public static void ShowWindow()
  8. {
  9. EditorWindow.GetWindow(typeof(FindMissingScriptsRecursively));
  10. }
  11. public void OnGUI()
  12. {
  13. if (GUILayout.Button("Find Missing Scripts in selected GameObjects"))
  14. {
  15. FindInSelected();
  16. }
  17. }
  18. private static void FindInSelected()
  19. {
  20. GameObject[] go = Selection.gameObjects;
  21. go_count = 0;
  22. components_count = 0;
  23. missing_count = 0;
  24. foreach (GameObject g in go)
  25. {
  26. FindInGO(g);
  27. }
  28. Debug.Log(string.Format("Searched {0} GameObjects, {1} components, found {2} missing", go_count, components_count, missing_count));
  29. }
  30. private static void FindInGO(GameObject g)
  31. {
  32. go_count++;
  33. Component[] components = g.GetComponents<Component>();
  34. for (int i = 0; i < components.Length; i++)
  35. {
  36. components_count++;
  37. if (components[i] == null)
  38. {
  39. missing_count++;
  40. string s = g.name;
  41. Transform t = g.transform;
  42. while (t.parent != null)
  43. {
  44. s = t.parent.name +"/"+s;
  45. t = t.parent;
  46. }
  47. Debug.Log (s + " has an empty script attached in position: " + i, g);
  48. }
  49. }
  50. // Now recurse through each child GO (if there are any):
  51. foreach (Transform childT in g.transform)
  52. {
  53. //Debug.Log("Searching " + childT.name  + " " );
  54. FindInGO(childT.gameObject);
  55. }
  56. }
  57. }

查找某个脚本的脚本:

  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEditor;
  5. /////////////////////////////////////////////////////////////////////////////
  6. //查找节点及所有子节点中,是否有指定的脚本组件
  7. /////////////////////////////////////////////////////////////////////////////
  8. public class MonoFinder : EditorWindow {
  9. Transform root = null;
  10. MonoScript scriptObj = null;
  11. int loopCount = 0;
  12. List<Transform> results = new List<Transform>();
  13. [MenuItem("Level4/Finder/MonoFinder")]
  14. static void Init(){
  15. EditorWindow.GetWindow(typeof(MonoFinder));
  16. }
  17. void OnGUI(){
  18. GUILayout.Label("节点:");
  19. root = (Transform)EditorGUILayout.ObjectField(root,typeof(Transform),true);
  20. GUILayout.Label("脚本类型:");
  21. scriptObj = (MonoScript)EditorGUILayout.ObjectField(scriptObj,typeof(MonoScript),true);
  22. if(GUILayout.Button("Find")){
  23. results.Clear();
  24. loopCount = 0;
  25. Debug.Log("开始查找.");
  26. FindScript(root);
  27. }
  28. if(results.Count > 0){
  29. foreach(Transform t in results){
  30. EditorGUILayout.ObjectField(t,typeof(Transform),false);
  31. }
  32. }else{
  33. GUILayout.Label("无数据");
  34. }
  35. }
  36. void FindScript(Transform root){
  37. if(root != null && scriptObj != null){
  38. loopCount ++;
  39. Debug.Log(".."+loopCount+":"+root.gameObject.name);
  40. if( root.GetComponent(scriptObj.GetClass()) != null){
  41. results.Add(root);
  42. }
  43. foreach(Transform t in root){
  44. FindScript(t);
  45. }
  46. }
  47. }
  48. }

相关的链接:

http://wiki.unity3d.com/index.php?title=FindMissingScripts

http://superherosk123.iteye.com/blog/1632627

Unity3D开发之查找面板上某个脚本(包括Missing)的更多相关文章

  1. Unity3D开发之查找面板上某个脚本(包含Missing)

    有时候我们须要知道某个脚本在场景上面哪里用到,或者那个脚本被删除了但又没有把相关游戏场景的关联东西删掉,那样我们就要一个脚本来查找一下了: PS:以下两个脚本都要放到assets/Editor以下哦. ...

  2. 出售Illustrator脚本插件面板(包含面板源码,以及面板上所有的功能源码)

    出售Illustrator脚本插件面板(包含面板源码,以及面板上所有的功能源码) 购买后可提供相应的小修改,以及教你使用往这个多列面里再加上按钮功能! 这套源码可作为工作使用,也可用为新手学习AI脚面 ...

  3. 跟我从零基础学习Unity3D开发--NGUI入门基础

    英雄联盟(撸啊撸) QQ飞车 魔兽世界等等相信大家都玩过游戏吧,玩过那UI知道是什么吧?UI可能说得有点专业的话那么游戏中那些属性面板例如: 现在对UI有一定认识了吧!回想一下您玩过的游戏就一定知道什 ...

  4. ADO面板上的控件简介

    ADO面板上的控件简介 一. TADOConnection组件该组件用于建立数据库的连接.ADO的数据源组件和命令组件可以通过该组件运行命令及数据库中提取数据等.该组件用于建立数据库的连接,该连接可被 ...

  5. Delphi7 ADO面板上的控件简介

    ? ADO Connection的主要方法:1) Begin Trans    开始启动一个新的事务,必须保证数据连接处于激活状态.2) Cancel    关闭于数据库的连接.3) Commit T ...

  6. 添加启动游戏过渡场景Default Splash Scene(Unity3D开发之十三)

    添加启动游戏过渡场景Default Splash Scene(Unity3D开发之十三) 猴子原创,欢迎转载.转载请注明: 转载自Cocos2Der-CSDN,谢谢! 原文地址: http://blo ...

  7. IE8“开发人员工具”(上)

    认识“开发人员工具” 开发人员工具在IE8的工具菜单下,或者直接点击F12快捷键也可以呼叫出来. 提供一系列的小工具,让你可以方便的查找页面的bug,包括html代码.css代码和JavaScript ...

  8. unity3d开发实战《啪啪三国》技术详解!

     去年11月,上海火溶网络CEO王伟峰以其第一款3d手游产品<啪啪三国>为例,着重讲解了unity3D手机网游开发的经验,其中涉及了团队组成.人员要求.常见的unity3d开发遇到的坑及解 ...

  9. 菜鸟在线教你用Unity3D开发VR版的Hello World

    大家好,我是菜鸟在线的小编.这篇短文将告诉大家如何用Unity3D开发VR版的Hello World. 1开启SteamVR并连接Vive设备 (a)登录Steam客户端,并点击右上角的VR按钮,这时 ...

随机推荐

  1. Office升级到2013版后无法登录微软账号问题

    自打office从2010版升级到2013版,就再也无法登录微软账号了.每次点击登录,弹出来的框就显示:this feature has been disabled by your administr ...

  2. oracle instantclient basic +pl/sql 安装和配置

    oracle instantclient basic +pl/sql 安装和配置 大家都知道,用PL/SQL连接Oracle,是需要安装Oracle客户端软件的,oracle客户端有点大,比较耗资源. ...

  3. 【译】 Node.js v0.12的新特性 -- Cluster模式采用Round-Robin负载均衡

    原文:https://strongloop.com/strongblog/whats-new-in-node-js-v0-12-cluster-round-robin-load-balancing 本 ...

  4. UML建模文章总结

    一.为什么要学习UML UML是Unified Modeling Language(统一建模语言)的简称.UML是对软件密集型系统中的制品进行可视化.详述.构造和文档化的语言.制品{Artifact} ...

  5. linux 运维知识体系

    这里将会介绍一下,LINUX运维工程师的知识体系. 只能说是个人理解吧.并不是必要或者充分的,仅供网友参考. 大部分本博客都有涉及,并不完整. 1.LINUX运维基础 1.1.LINUX系统的简介,分 ...

  6. SMB/CIFS协议解析二

    一.拷贝文件(远程-->本地) 1.SMB_COM_NT_CREATE_ANDX (0xa2)       打开文件,获取文件名,获得读取文件的  总长度. 2.SMB_COM_READ     ...

  7. ASP.Net MVC中JSON处理。

    实体数据Model [Serializable] public class UserModel { //public UserModel(string name, string classname, ...

  8. 《PHP与MySQL WEB开发》读书笔记

    <PHP与MySQL WEB开发>读书笔记 作者:[美]Luke Welling PHP输出的HereDoc语法: echo <<<theEnd line 1 line ...

  9. 没有文件扩展".js"的脚本引擎 解决办法

    在命令行运行JScript脚本时,遇到如下的错误提示: “输入错误: 没有文件扩展“.js”的脚本引擎.” 这样的错误,原因是因为JS扩展名的文件被其他软件关联了,需要取消关联. 如系统中安装了ULT ...

  10. [翻译]15个最常见的WCF面试问题

    WCF和ASMX WebService的区别是什么? 最基本的区别在于,ASMX或者ASP.NET WebService是用来通过基于HTTP的SOAP来实现通讯.但WCF可以使用任意协议(HTTP, ...