- 最后登录
- 2019-12-25
- 注册时间
- 2012-8-24
- 阅读权限
- 90
- 积分
- 71088
 
- 纳金币
- 52352
- 精华
- 343
|
有时候我们需要知道某个脚本在场景上面哪里用到,或者那个脚本被删除了但又没有把相关游戏场景的关联东西删掉,那样我们就要一个脚本来查找一下了:
ps:下面两个脚本都要放到assets/Editor下面哦。。
查找missing的脚本:查找某个脚本的代码- 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);
-
- }
-
- }
-
- }
-
- }
复制代码 :
|
|