1. 程式人生 > >Unity查詢指令碼被哪些Perfab或場景引用

Unity查詢指令碼被哪些Perfab或場景引用

Unity中查詢指令碼被哪些Prefab或場景引用

Unity中有個Find References In Scene的功能,但是隻能查詢在當前場景中的引用。
如果發現某個指令碼不知道被掛在哪個Prefab上了,下面這個指令碼你可能用得到
實現在查詢指令碼在哪些Prefab或者場景中被引用,查詢指令碼引用了哪些物件(指令碼,Texture,字型等)
先看截圖:
這裡寫圖片描述
這裡寫圖片描述
這裡寫圖片描述

原始碼在這裡

using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;

public
class FindReference : EditorWindow{ static public FindReference instance; Vector2 mScroll = Vector2.zero; public Dictionary<string,BetterList<string>> dict; void OnEnable() { instance = this; } void OnDisable() { instance = null; } void OnGUI() { if
(dict == null) { return; } mScroll = GUILayout.BeginScrollView(mScroll); BetterList<string> list = dict["prefab"]; if (list != null && list.size>0) { if(NGUIEditorTools.DrawHeader("Prefab")) { foreach
(string item in list) { GameObject go = AssetDatabase.LoadAssetAtPath(item, typeof(GameObject)) as GameObject; EditorGUILayout.ObjectField("Prefab", go, typeof(GameObject), false); } } list = null; } list = dict["fbx"]; if (list != null && list.size > 0) { if(NGUIEditorTools.DrawHeader("FBX")){ foreach (string item in list) { GameObject go = AssetDatabase.LoadAssetAtPath(item, typeof(GameObject)) as GameObject; EditorGUILayout.ObjectField("FBX", go, typeof(GameObject), false); } } list = null; } list = dict["cs"]; if (list != null && list.size > 0) { if(NGUIEditorTools.DrawHeader("Script")){ foreach (string item in list) { MonoScript go = AssetDatabase.LoadAssetAtPath(item, typeof(MonoScript)) as MonoScript; EditorGUILayout.ObjectField("Script", go, typeof(MonoScript), false); } } list = null; } list = dict["texture"]; if (list != null && list.size > 0) { if (NGUIEditorTools.DrawHeader("Texture")) { foreach (string item in list) { Texture2D go = AssetDatabase.LoadAssetAtPath(item, typeof(Texture2D)) as Texture2D; EditorGUILayout.ObjectField("Texture:" + go.name, go, typeof(Texture2D), false); } } list = null; } list = dict["mat"]; if (list != null && list.size > 0) { if (NGUIEditorTools.DrawHeader("Material")) { foreach (string item in list) { Material go = AssetDatabase.LoadAssetAtPath(item, typeof(Material)) as Material; EditorGUILayout.ObjectField("Material", go, typeof(Material), false); } } list = null; } list = dict["shader"]; if (list != null && list.size > 0) { if (NGUIEditorTools.DrawHeader("Shader")) { foreach (string item in list) { Shader go = AssetDatabase.LoadAssetAtPath(item, typeof(Shader)) as Shader; EditorGUILayout.ObjectField("Shader", go, typeof(Shader), false); } } list = null; } list = dict["font"]; if (list != null && list.size > 0) { if (NGUIEditorTools.DrawHeader("Font")) { foreach (string item in list) { Font go = AssetDatabase.LoadAssetAtPath(item, typeof(Font)) as Font; EditorGUILayout.ObjectField("Font", go, typeof(Font), false); } } list = null; } list = dict["anim"]; if (list != null && list.size > 0) { if (NGUIEditorTools.DrawHeader("Animation")) { foreach (string item in list) { AnimationClip go = AssetDatabase.LoadAssetAtPath(item, typeof(AnimationClip)) as AnimationClip; EditorGUILayout.ObjectField("Animation:", go, typeof(AnimationClip), false); } } list = null; } list = dict["animTor"]; if (list != null && list.size > 0) { if (NGUIEditorTools.DrawHeader("Animator")) { foreach (string item in list) { //Animator go = AssetDatabase.LoadAssetAtPath(item, typeof(Animator)) as Animator; //EditorGUILayout.ObjectField("Animator:", go, typeof(Animator), true); EditorGUILayout.LabelField(item); } } list = null; } list = dict["level"]; if (list != null && list.size > 0) { if (NGUIEditorTools.DrawHeader("Level")) { foreach (string item in list) { //SceneView go = AssetDatabase.LoadAssetAtPath(item, typeof(SceneView)) as SceneView; EditorGUILayout.LabelField(item); //SceneView go = AssetDatabase.LoadAssetAtPath(item, typeof(SceneView)) as SceneView; //EditorGUILayout.ObjectField("Animation:" , go, typeof(SceneView), true); } } list = null; } GUILayout.EndScrollView(); //NGUIEditorTools.DrawList("Objects", list.ToArray(), ""); } /// <summary> /// 根據指令碼查詢引用的物件 /// </summary> [MenuItem("Assets/Wiker/Find Script Reference", false, 0)] static public void FindScriptReference() { //EditorWindow.GetWindow<UIAtlasMaker>(false, "Atlas Maker", true).Show(); //Debug.Log("Selected Transform is on " + Selection.activeObject.name + "."); //foreach(string guid in Selection.assetGUIDs){ // Debug.Log("GUID " + guid); //} ShowProgress(0,0,0); string curPathName = AssetDatabase.GetAssetPath(Selection.activeObject.GetInstanceID()); Dictionary<string, BetterList<string>> dic = new Dictionary<string, BetterList<string>>(); BetterList<string> prefabList = new BetterList<string>(); BetterList<string> fbxList = new BetterList<string>(); BetterList<string> scriptList = new BetterList<string>(); BetterList<string> textureList = new BetterList<string>(); BetterList<string> matList = new BetterList<string>(); BetterList<string> shaderList = new BetterList<string>(); BetterList<string> fontList = new BetterList<string>(); BetterList<string> levelList = new BetterList<string>(); string[] allGuids = AssetDatabase.FindAssets("t:Prefab t:Scene", new string[]{"Assets"}); int i = 0; foreach (string guid in allGuids) { string assetPath = AssetDatabase.GUIDToAssetPath(guid); string[] names = AssetDatabase.GetDependencies(new string[]{assetPath}); //依賴的東東 foreach (string name in names) { if (name.Equals(curPathName)) { //Debug.Log("Refer:" + assetPath); if (assetPath.EndsWith(".prefab")) { prefabList.Add(assetPath); break; } else if (assetPath.ToLower().EndsWith(".fbx")) { fbxList.Add(assetPath); break; } else if (assetPath.ToLower().EndsWith(".unity")) { levelList.Add(assetPath); break; } else if (assetPath.EndsWith(".cs")) { scriptList.Add(assetPath); break; } else if (assetPath.EndsWith(".png")) { textureList.Add(assetPath); break; } else if (assetPath.EndsWith(".mat")) { matList.Add(assetPath); break; } else if (assetPath.EndsWith(".shader")) { shaderList.Add(assetPath); break; } else if (assetPath.EndsWith(".ttf")) { fontList.Add(assetPath); break; } } } ShowProgress((float)i / (float)allGuids.Length, allGuids.Length,i); i++; } dic.Add("prefab", prefabList); dic.Add("fbx", fbxList); dic.Add("cs", scriptList); dic.Add("texture", textureList); dic.Add("mat", matList); dic.Add("shader", shaderList); dic.Add("font", fontList); dic.Add("level", levelList); dic.Add("anim", null); dic.Add("animTor", null); EditorUtility.ClearProgressBar(); EditorWindow.GetWindow<FindReference>(false, "Object Reference", true).Show(); //foreach (KeyValuePair<string, BetterList<string>> d in dic) //{ // foreach (string s in d.Value) // { // Debug.Log(d.Key + "=" + s); // } //} if (FindReference.instance.dict != null) FindReference.instance.dict.Clear(); FindReference.instance.dict = dic; //string[] path = new string[1]; //path[0] = AssetDatabase.GetAssetPath(Selection.activeObject.GetInstanceID()); //string[] names = AssetDatabase.GetDependencies(path); //依賴的東東 //foreach (string name in names) //{ // Debug.Log("Name:"+name); //} } public static void ShowProgress(float val,int total,int cur) { EditorUtility.DisplayProgressBar("Searching", string.Format("Finding ({0}/{1}), please wait...",cur,total), val); } /// <summary> /// 查詢物件引用的型別 /// </summary> [MenuItem("Assets/Wiker/Find Object Dependencies", false, 0)] public static void FindObjectDependencies() { ShowProgress(0,0,0); Dictionary<string, BetterList<string>> dic = new Dictionary<string, BetterList<string>>(); BetterList<string> prefabList = new BetterList<string>(); BetterList<string> fbxList = new BetterList<string>(); BetterList<string> scriptList = new BetterList<string>(); BetterList<string> textureList = new BetterList<string>(); BetterList<string> matList = new BetterList<string>(); BetterList<string> shaderList = new BetterList<string>(); BetterList<string> fontList = new BetterList<string>(); BetterList<string> animList = new BetterList<string>(); BetterList<string> animTorList = new BetterList<string>(); string curPathName = AssetDatabase.GetAssetPath(Selection.activeObject.GetInstanceID()); string[] names = AssetDatabase.GetDependencies(new string[] { curPathName }); //依賴的東東 int i = 0; foreach (string name in names) { if (name.EndsWith(".prefab")) { prefabList.Add(name); } else if (name.ToLower().EndsWith(".fbx")) { fbxList.Add(name); } else if (name.EndsWith(".cs")) { scriptList.Add(name); } else if (name.EndsWith(".png")) { textureList.Add(name); } else if (name.EndsWith(".mat")) { matList.Add(name); } else if (name.EndsWith(".shader")) { shaderList.Add(name); } else if (name.EndsWith(".ttf")) { fontList.Add(name); } else if (name.EndsWith(".anim")) { animList.Add(name); } else if (name.EndsWith(".controller")) { animTorList.Add(name); } Debug.Log("Dependence:"+name); ShowProgress((float)i / (float)names.Length,names.Length,i); i++; } dic.Add("prefab", prefabList); dic.Add("fbx", fbxList); dic.Add("cs", scriptList); dic.Add("texture", textureList); dic.Add("mat", matList); dic.Add("shader", shaderList); dic.Add("font", fontList); dic.Add("level", null); dic.Add("animTor", animTorList); dic.Add("anim", animList); //deps.Sort(Compare); EditorWindow.GetWindow<FindReference>(false, "Object Dependencies", true).Show(); if (FindReference.instance.dict != null) FindReference.instance.dict.Clear(); FindReference.instance.dict = dic; EditorUtility.ClearProgressBar(); } }

相關推薦

Unity查詢指令碼哪些Perfab場景引用

Unity中查詢指令碼被哪些Prefab或場景引用 Unity中有個Find References In Scene的功能,但是隻能查詢在當前場景中的引用。 如果發現某個指令碼不知道被掛在哪個Prefab上了,下面這個指令碼你可能用得到 實現在查詢指令碼在

Unity查找腳本哪些Perfab場景引用

true label 得到 one ive sort ptr ans -c Unity中查找腳本被哪些Prefab或場景引用 Unity中有個Find References In Scene的功能,可是僅僅能查找在當前場景中的引用。 假設發現某個腳本

unity 查詢資源哪裡引用

方法大量借鑑雨鬆大神的文章, 附上鍊接表示敬意 好處是自己添加了可以多選操作 不好的是沒有“”設定某些資料夾忽略“”的功能,那樣可以節省不少時間 而且不能“”選中資料夾查詢“,那樣有些時候更方便 程式碼如下: using UnityEngine; using

Linux下查詢80埠哪些IP訪問連線,以及查詢異常連線IP地址可以封掉異常IP

netstat -tun 列出的是所有連線 netstat -tun | grep ":80" Linux下查詢80埠被哪些IP訪問連線。 應該就能達到你的要求查詢IP連線訪問彙總,如發現異常IP則可以封掉異常的IP訪問地址。netstat -tn 2>/dev/n

Unity NGUI UIPanel下對粒子自定義Mesh的剪裁

ngui unity uipanel 裁切 剪裁 粒子 寫在開篇: 越來越煩那些無腦轉發自己不做驗證的博主論壇樓主,網上好不容易找到一些資料,結果代碼搞下來卻是錯的,有些確實是因為版本問題太老不兼容,但是有些明顯是有問題的,轉發前自己試試就知道肯定是不能用的。結果。。。哎。。。真

在 LINQ to Entities 查詢中無法構造實體復雜類型

對象 AS new col linq use date user 匿名 錯誤代碼: var orders = db.Orders.Where(o => o.UserId == userid).Select(c => ne

實驗12-05 查詢借過1次的圖書的圖書名稱、作者和出版社

medium family nbsp count style mil 出版社 highlight tinc 在數據庫Exam中查詢只被借過1次的圖書的圖書名稱、作者和出版社。 select distinct book.bno,b

在 LINQ to Entities 查詢中無法構造實體復雜類型“Cits.Data.LineImg”。

lis 錯誤 code num list 構造 enum title == 錯誤代碼: adlist = _sImg.Where(o => o.AdType == 11).OrderBy(o => o.Desc).OrderByDescending(o =&g

Mysql資料庫如何檢視某張表table哪些儲存過程procedure使用過

一、摘要 由於程式碼重構,修改了表結構,開發人員修改完java後臺程式碼並內測沒問題後提交業務部門測試時發現,新客戶取不到產品價格,原因是儲存過程呼叫的還是舊資料表。為此,需要先找出哪些儲存過程使用了這些表,然後修改。那麼問題來了,mysql資料庫如何檢視哪些儲存過程使用了這些資料表呢?

解構Unity指令碼物件模型

Unity 是一個以 Mono 為基礎的遊戲開發環境,能同時支援三種指令碼語言,包括 C#、Javascript 和 Boo (類似 Python)。 由於 Unity 的開發工具暫時只有 Mac 的版本 (2010年2月25日更新: 現時已有Windows版本,而且有免費授權版,另外因為Unity iPho

泛微系統裡未執行完流程查詢指令碼

查詢系統中未執行完的流程目前停留在誰哪裡,停留多長時間。 select hr.lastname approver,wn.nodename ,wb.workflowname--,wc.isremark,wr.requestname ,hr.email,wr.lastoperatedate,DATEDIFF(d

IP運營商和歸屬地查詢指令碼

#!/bin/bash FILE=ip_apnic rm -rf $FILE isp province cn.net mkdir isp province wget http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest -O $FIL

Unity AVProVideo指令碼方法呼叫

1.搭建場景 2.指令碼 專案地址 using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using Render

nginx優化-利用nginx限制HTTP的請求方法--防止指令碼上傳至伺服器執行該指令碼對系統的破壞

利用nginx限制HTTP的請求方法 $request_method --防止指令碼被上傳至伺服器執行該指令碼對系統的破壞 可以上傳檔案,但是不能讓指令碼檔案執行成功 例如:站點目錄下有一個/image目錄,這個目錄是使用者上傳的一些圖片,不能阻止使用者上傳圖片,但要阻止使用者用特殊的方法執行裡面的檔

Unity中用指令碼實現圖片替換

首先替換資源是要在當前專案中找到需要替換的資源 利用www類實現資源載入 程式碼如下 using UnityEngine; using System.Collections; using UnityEngine.Networking; using Syste

Unity指令碼模板

本文由本人簡書搬遷至此,並做小幅修改。 方法: 在Unity安裝目錄的 D:\Program Files\Unity5.56f1\Editor\Data\Resources\ScriptTemplates 下新增新的模板文字檔案。新增完成之後重啟Unity。 如: 84-Shader__Empt

Unity基礎篇:判定載入(切換)場景是否完成

老版本的Unity可以用 Application.LoadLevel(LoadSceneName); 來載入場景 用 Application.isLoadingLevel 來判定場景載入是否完成 可是Unity已經準備棄用這個方法了 --------------

Unity你用過哪些設計模式?你熟悉的設計模式有哪幾種呢?

以前寫過幾篇設計模式的詳細解釋,今天在這裡不詳細介紹,有興趣瞭解的可以去看前幾篇隨筆,今天就簡單的介紹我們常用的設計模式. (1)工廠模式 簡單工廠模式解決的問題是如何去例項化一個合適的物件. 簡單工廠模式的核心思想就是:有一個專門的類來負責例項過程,正規化出現大量產品需要建立,並且具有共同的介面時,可

前後端分離,如何防止介面其他人呼叫惡意重發

前後端分離,如何防止介面被其他人呼叫或惡意重發? 首先,http協議的無狀態特性決定了是無法徹底避免第三方呼叫你的後臺服務。我們可以通過crsf、介面呼叫頻率、使用者行為分析(來源等)等各個方面來增加第三方呼叫的難度,也可以通過新增一箇中間層比如node.js來實現;1. 非法訪問通常使用認證來解決,方法很

脫歐不順?英首相方案歐盟拒絕 再有閣僚辭職

11月29日訊息,@北京商報從度小滿金融人士處獲悉,百度正式拿到准許經營證券期貨的許可證。據許可證顯示,機構名稱為北京百度百盈科技有限公司(下稱“百度百盈”),證券期貨業務經營範圍為基金銷售。而今年8月22日,根據北京證監局官網顯示,證監局已核准百度百盈證券投資基金銷售業務資格。 企查查資訊顯示,百度百盈成