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 查找脚本被场景中哪些对象引用
在需要查找的脚本上右键: 在场景中已经显示出所有引用该脚本的对象
- Unity Mono脚本 加密
加密环境 引擎版本:Unity3D 5.3.4 及更高版本 (使用Mono而并非IL2CPP) 操作系统:CentOS 6.2(Final) 加密环境:Android.IOS(暂定) 加密对象:C#源 ...
- 自制Unity小游戏TankHero-2D(5)声音+爆炸+场景切换+武器弹药
自制Unity小游戏TankHero-2D(5)声音+爆炸+场景切换+武器弹药 我在做这样一个坦克游戏,是仿照(http://game.kid.qq.com/a/20140221/028931.htm ...
- Unity查找物体的子物体、孙物体
Unity查找物体下的所有物体 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- 心分 ...
- Unity查找子物体的方式-怎么查找GameObject
Unity动态查找物体 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- 心分享.心创 ...
- 游戏编程之Unity常用脚本类的继承关系
前言学习Unity开发引擎的初学者会接触大量的脚本类,而这些类之间的关系往往容易被忽略.本文对Unity引擎开发中的一些常用类及其关系进行了简单的归纳总结. 博文首发地址:http://tieba.b ...
- Unity基础-脚本生命周期
理解Unity脚本的生命周期对游戏开发很重要,这篇文章对生命周期做一个记录和总结.Unity的脚本生命周期(消息),也就是在脚本运行时,自动并且按顺序执行的一系列函数.在unity官网中有对生命周期详 ...
- Lua脚本在redis分布式锁场景的运用
目录 锁和分布式锁 锁是什么? 为什么需要锁? Java中的锁 分布式锁 redis 如何实现加锁 锁超时 retry redis 如何释放锁 不该释放的锁 通过Lua脚本实现锁释放 用redis做分 ...
- Unity 查找泛型List中的相同与不同数据
Unity查找泛型集合中的不同数据 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- ...
随机推荐
- [Swift通天遁地]二、表格表单-(10)快速添加日期选择/多选/动作表单/地图等自定义表单
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- [Swift通天遁地]九、拔剑吧-(16)搭建卡片页面:Card Peek/Pop动态切换界面
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- 零基础如何学习Java和web前端
今天说一下零基础到底能不能学习Java,为什么有的人说学不了呢,那么接下来我为大家揭晓,零基础到底适合不适合学习Java. 零基础学习Java的途径第一个就是看视频,然后就是看书,或者在线下报个培训班 ...
- Ansible+Jenkins+Gitlab搭建及配置
Ansible+Jenkins+Gitlab搭建及配置,已经生产环境使用,运行良好. 主机组文件里面好多ip敏感信息就不写了
- CSS怎样改变行内样式(通过外部级联样式表) css !important用法CSS样式使用优先级判断
CSS样式优先级 行内>内部>外部 使用!important的css定义是拥有最高的优先级的.只是在ie6下出了一点小的bug,注意书写方式一般可以轻松避开的. CSS中的!importa ...
- Servlet到Servlet的请求转发与重定向的区别
Servlet跳转到另一个Servlet中: request.getRequestDispatcher().forward();代表默认的是post方法,即在被跳转的Servlet的doPost()方 ...
- cocos2dx实现单机版三国杀(二)
接上续,东西还没有做完 所以代码免不了改动 之前的头文件现在又改了不少,因为架构也改变了现在主要类就是GameScene.GameUI.PlayInfo.Poker这四个类 前面想的GameLoop ...
- Java系列学习(十三)-字符串
1.字符串基础 概念:字符串本质是打包字符数组的对象,是java.lang.String类的实例 2.字符串的构造方法 public String() public String(byte[] byt ...
- 如何用putty链接服务器端,并安装wdcp
首先把自己阿里云的磁盘格式化然后重启 自己下载一个PuTTY 打开后输入自己的Ip地址端口号默认是22 会跳出一个yes 跟no界面,点击yes 会进入一个类似cmd界面 直接输入root,然后会提示 ...
- 单实例redis分布式锁的简单实现
redis分布式锁的基本功能包括, 同一刻只能有一个人占有锁, 当锁被其他人占用时, 获取者可以等待他人释放锁, 此外锁本身必须能超时自动释放. 直接上java代码, 如下: package com. ...