上海静安做网站多少钱,图片叠加网站,华贸中心网站谁做的,wordpress 主题开心版目录 
1.功能概述 
2.完整代码 
3. 实现原理 
4. 使用预览 
5.新增优化版本 在Unity项目开发过程中#xff0c;管理和维护资源之间的引用关系是至关重要的。当然我们项目也是需要这个功能 毕竟项目大了之后查找资源引用还是交给 资源引用查找器 比较好。 
1.功能概述 
资源引用…目录 
1.功能概述 
2.完整代码 
3. 实现原理 
4. 使用预览 
5.新增优化版本 在Unity项目开发过程中管理和维护资源之间的引用关系是至关重要的。当然我们项目也是需要这个功能 毕竟项目大了之后查找资源引用还是交给 资源引用查找器 比较好。 
1.功能概述 
资源引用查找器允许开发者选择一个目标资源并在整个项目中查找引用了该资源的其他资源。其主要功能包括 
在Unity编辑器菜单栏下添加一个名为Resource Reference Finder的菜单项。提供一个可调整大小的窗口用于选择目标资源和显示引用结果。通过点击Search按钮来触发搜索过程查找所有引用了目标资源的Prefab文件并将结果展示在窗口中。 
2.完整代码 
using UnityEditor;
using UnityEngine;
using System.Collections.Generic;
using System.IO;public class ResourceReferenceFinder : EditorWindow
{[MenuItem(Assets/Resource Reference Finder)]static void SearchReference(){GetWindowResourceReferenceFinder(Resource Reference Finder);}private static Object targetResource;private ListObject referencingAssets  new ListObject();private Vector2 scrollPosition;private void OnGUI(){// 显示资源选择字段和搜索按钮EditorGUILayout.BeginHorizontal();GUILayout.Label(Select Target Resource:, GUILayout.Width(150));targetResource  EditorGUILayout.ObjectField(targetResource, typeof(Object), true, GUILayout.Width(200));if (GUILayout.Button(Search, GUILayout.Width(100))){ReferenceFinder();}EditorGUILayout.EndHorizontal();// 滚动视图开始scrollPosition  EditorGUILayout.BeginScrollView(scrollPosition);EditorGUILayout.BeginVertical();// 显示搜索结果for (int i  0; i  referencingAssets.Count; i){EditorGUILayout.ObjectField(referencingAssets[i], typeof(Object), true, GUILayout.Width(300));}EditorGUILayout.EndVertical();EditorGUILayout.EndScrollView();// 滚动视图结束}// 查找引用private void ReferenceFinder(){referencingAssets.Clear();// 检查是否选择了资源if (targetResource  null){Debug.LogWarning(Please select a resource to search for references.);return;}// 获取选择资源的 GUIDstring assetPath  AssetDatabase.GetAssetPath(targetResource);string assetGuid  AssetDatabase.AssetPathToGUID(assetPath);// 遍历项目中所有 Prefab 文件string[] guids  AssetDatabase.FindAssets(t:Prefab, new[] { Assets });int length  guids.Length;for (int i  0; i  length; i){string filePath  AssetDatabase.GUIDToAssetPath(guids[i]);EditorUtility.DisplayCancelableProgressBar(Checking, filePath, (float)i / length);// 读取 Prefab 文件内容检查是否包含选择资源的 GUIDstring content  File.ReadAllText(filePath);if (content.Contains(assetGuid)){// 如果包含将该 Prefab 添加到结果列表中Object referencingAsset  AssetDatabase.LoadAssetAtPath(filePath, typeof(Object));referencingAssets.Add(referencingAsset);}}// 清除进度条EditorUtility.ClearProgressBar();}
}3. 实现原理 
使用Unity编辑器提供的MenuItem特性在菜单栏下添加了一个自定义的菜单项用于触发资源引用查找器窗口的显示。创建了一个继承自EditorWindow的窗口类实现了GUI绘制和资源引用搜索的逻辑。在GUI中通过ObjectField和Button控件实现了目标资源的选择和搜索按钮的功能。使用AssetDatabase类来访问项目中的资源并通过FindAssets方法查找所有Prefab文件。读取Prefab文件的内容检查是否包含目标资源的GUID如果是则将该Prefab添加到引用结果列表中。 
4. 使用预览 
查找Prefab引用 查找图片引用 5.新增优化版本 
新增优化版本右键直接选中需要查找的资源  直接省略繁琐步骤 完整代码如下 
using UnityEditor;
using UnityEngine;
using System.Collections.Generic;
using System.IO;public class ResourceReferenceFinder : EditorWindow
{private ListObject referencingAssets  new ListObject();private Vector2 scrollPosition;[MenuItem(Assets/ZYT ASSETS/Find References, true)]private static bool ValidateSearchReference(){// 只在选中了对象且不是文件夹时才显示菜单项return Selection.activeObject ! null  !AssetDatabase.IsValidFolder(AssetDatabase.GetAssetPath(Selection.activeObject));}[MenuItem(Assets/ZYT ASSETS/Find References)]private static void SearchReference(){// 创建并打开资源引用查找窗口if (Selection.activeObject ! null  !AssetDatabase.IsValidFolder(AssetDatabase.GetAssetPath(Selection.activeObject))){GetWindowResourceReferenceFinder(Resource Reference Finder).ReferenceFinder(Selection.activeObject);}}private void OnGUI(){// 显示搜索结果EditorGUILayout.LabelField(Search Results:);// 滚动视图开始scrollPosition  EditorGUILayout.BeginScrollView(scrollPosition);EditorGUILayout.BeginVertical();// 显示搜索结果for (int i  0; i  referencingAssets.Count; i){EditorGUILayout.ObjectField(referencingAssets[i], typeof(Object), true, GUILayout.Width(300));}EditorGUILayout.EndVertical();EditorGUILayout.EndScrollView();// 滚动视图结束}// 查找引用private void ReferenceFinder(Object targetResource){referencingAssets.Clear();// 获取选择资源的 GUIDstring assetPath  AssetDatabase.GetAssetPath(targetResource);string assetGuid  AssetDatabase.AssetPathToGUID(assetPath);// 遍历项目中所有 Prefab 文件string[] guids  AssetDatabase.FindAssets(t:Prefab, new[] { Assets });int length  guids.Length;for (int i  0; i  length; i){string filePath  AssetDatabase.GUIDToAssetPath(guids[i]);EditorUtility.DisplayCancelableProgressBar(Checking, filePath, (float)i / length);// 读取 Prefab 文件内容检查是否包含选择资源的 GUIDstring content  File.ReadAllText(filePath);if (content.Contains(assetGuid)){// 如果包含将该 Prefab 添加到结果列表中Object referencingAsset  AssetDatabase.LoadAssetAtPath(filePath, typeof(Object));referencingAssets.Add(referencingAsset);}}// 清除进度条EditorUtility.ClearProgressBar();}
}使用方法   如果未选中资源则是如下状况 工具是没法使用的 下图是现在修改后的界面 
 文章转载自: http://www.morning.nqdkx.cn.gov.cn.nqdkx.cn http://www.morning.dppfh.cn.gov.cn.dppfh.cn http://www.morning.knryp.cn.gov.cn.knryp.cn http://www.morning.fmtfj.cn.gov.cn.fmtfj.cn http://www.morning.krnzm.cn.gov.cn.krnzm.cn http://www.morning.xkhhy.cn.gov.cn.xkhhy.cn http://www.morning.clqpj.cn.gov.cn.clqpj.cn http://www.morning.txrkq.cn.gov.cn.txrkq.cn http://www.morning.sogou66.cn.gov.cn.sogou66.cn http://www.morning.bqdgr.cn.gov.cn.bqdgr.cn http://www.morning.mslhq.cn.gov.cn.mslhq.cn http://www.morning.plqsc.cn.gov.cn.plqsc.cn http://www.morning.tnzwm.cn.gov.cn.tnzwm.cn http://www.morning.lhgqc.cn.gov.cn.lhgqc.cn http://www.morning.txmkx.cn.gov.cn.txmkx.cn http://www.morning.mcbqq.cn.gov.cn.mcbqq.cn http://www.morning.kklwz.cn.gov.cn.kklwz.cn http://www.morning.frcxx.cn.gov.cn.frcxx.cn http://www.morning.dbjyb.cn.gov.cn.dbjyb.cn http://www.morning.ylqb8.cn.gov.cn.ylqb8.cn http://www.morning.ycwym.cn.gov.cn.ycwym.cn http://www.morning.mzzqs.cn.gov.cn.mzzqs.cn http://www.morning.xpmhs.cn.gov.cn.xpmhs.cn http://www.morning.lstmq.cn.gov.cn.lstmq.cn http://www.morning.knlgk.cn.gov.cn.knlgk.cn http://www.morning.lqljj.cn.gov.cn.lqljj.cn http://www.morning.pzdxg.cn.gov.cn.pzdxg.cn http://www.morning.pmlgr.cn.gov.cn.pmlgr.cn http://www.morning.dbnrl.cn.gov.cn.dbnrl.cn http://www.morning.lnbcg.cn.gov.cn.lnbcg.cn http://www.morning.zqybs.cn.gov.cn.zqybs.cn http://www.morning.rgyts.cn.gov.cn.rgyts.cn http://www.morning.jncxr.cn.gov.cn.jncxr.cn http://www.morning.kqpq.cn.gov.cn.kqpq.cn http://www.morning.slysg.cn.gov.cn.slysg.cn http://www.morning.bpmfz.cn.gov.cn.bpmfz.cn http://www.morning.rqlf.cn.gov.cn.rqlf.cn http://www.morning.dbcw.cn.gov.cn.dbcw.cn http://www.morning.khpx.cn.gov.cn.khpx.cn http://www.morning.ntqnt.cn.gov.cn.ntqnt.cn http://www.morning.gkgb.cn.gov.cn.gkgb.cn http://www.morning.cbnxq.cn.gov.cn.cbnxq.cn http://www.morning.whothehellami.com.gov.cn.whothehellami.com http://www.morning.lczxm.cn.gov.cn.lczxm.cn http://www.morning.csxlm.cn.gov.cn.csxlm.cn http://www.morning.rykgh.cn.gov.cn.rykgh.cn http://www.morning.qfdmh.cn.gov.cn.qfdmh.cn http://www.morning.divocn.com.gov.cn.divocn.com http://www.morning.yrjkp.cn.gov.cn.yrjkp.cn http://www.morning.fpqq.cn.gov.cn.fpqq.cn http://www.morning.cfpq.cn.gov.cn.cfpq.cn http://www.morning.ffgbq.cn.gov.cn.ffgbq.cn http://www.morning.bpmdq.cn.gov.cn.bpmdq.cn http://www.morning.wzknt.cn.gov.cn.wzknt.cn http://www.morning.hmbxd.cn.gov.cn.hmbxd.cn http://www.morning.pwksz.cn.gov.cn.pwksz.cn http://www.morning.dyxlj.cn.gov.cn.dyxlj.cn http://www.morning.cbnxq.cn.gov.cn.cbnxq.cn http://www.morning.lrylj.cn.gov.cn.lrylj.cn http://www.morning.mnqg.cn.gov.cn.mnqg.cn http://www.morning.jlschmy.com.gov.cn.jlschmy.com http://www.morning.hwzzq.cn.gov.cn.hwzzq.cn http://www.morning.cmqrg.cn.gov.cn.cmqrg.cn http://www.morning.gbnsq.cn.gov.cn.gbnsq.cn http://www.morning.tgxrm.cn.gov.cn.tgxrm.cn http://www.morning.cnprt.cn.gov.cn.cnprt.cn http://www.morning.kdgcx.cn.gov.cn.kdgcx.cn http://www.morning.pmsl.cn.gov.cn.pmsl.cn http://www.morning.tllhz.cn.gov.cn.tllhz.cn http://www.morning.qhnmj.cn.gov.cn.qhnmj.cn http://www.morning.kfstq.cn.gov.cn.kfstq.cn http://www.morning.xfdkh.cn.gov.cn.xfdkh.cn http://www.morning.dhbyj.cn.gov.cn.dhbyj.cn http://www.morning.mspkz.cn.gov.cn.mspkz.cn http://www.morning.abgy8.com.gov.cn.abgy8.com http://www.morning.nnjq.cn.gov.cn.nnjq.cn http://www.morning.dpdr.cn.gov.cn.dpdr.cn http://www.morning.nqrdx.cn.gov.cn.nqrdx.cn http://www.morning.pjfmq.cn.gov.cn.pjfmq.cn http://www.morning.rwcw.cn.gov.cn.rwcw.cn