当前位置: 首页 > news >正文

肇庆网站建设方案优化互动营销

肇庆网站建设方案优化,互动营销,大学科研项目做网站,php网站开发实践指南目录 1.功能概述 2.完整代码 3. 实现原理 4. 使用预览 5.新增优化版本 在Unity项目开发过程中,管理和维护资源之间的引用关系是至关重要的。当然我们项目也是需要这个功能 毕竟项目大了之后查找资源引用还是交给 资源引用查找器 比较好。 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(){GetWindow<ResourceReferenceFinder>("Resource Reference Finder");}private static Object targetResource;private List<Object> referencingAssets = new List<Object>();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中,通过ObjectFieldButton控件实现了目标资源的选择和搜索按钮的功能。
  • 使用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 List<Object> referencingAssets = new List<Object>();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))){GetWindow<ResourceReferenceFinder>("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.hkea.cn/news/779/

相关文章:

  • 十大免费ppt网站在线推广的几种方式
  • 基础建设审计网站免费com域名申请注册
  • vs做网站添加背景百度网络营销中心官网
  • 辽阳低价网站建设公司seo是什么部门
  • 欧美在线做视频网站福州seo推广优化
  • 食药监局网站建设方案全国今日新增疫情
  • 门头沟网站建设外链工厂
  • 做部队网站技术网络游戏营销策略
  • 岭南地区网站建设好口碑关键词优化
  • 设计发布平台百度怎么优化关键词排名
  • 潍坊网站建设服务商品牌整合推广
  • 做催收的网站seo引擎优化是做什么的
  • 岳阳建设网站的公司网站建站网站
  • 上海html5网站制作公司网页搜索关键字
  • 国内免费高清视频素材seo经理招聘
  • 高端型网站制作市场营销策划包括哪些内容
  • 温州做网站的企业百度网站制作
  • ip地址访问不了网站百度明星人气榜
  • 电子商务网站建设薛万欣专业培训
  • 郑州网站制作哪家便宜最近一两天的新闻有哪些
  • 企业人事管理系统安卓优化大师旧版本下载
  • 深圳网站设计 创同盟绍兴seo排名
  • 中工信融做网站怎么样网页广告调词平台多少钱
  • 河南襄县做网站的公司杭州百度
  • 建设网站的标语百度图片
  • 网站流量和带宽百度贴吧热线客服24小时
  • 哪家网站遴选做的比较好91关键词
  • 东莞做网站 信科网络济南优化哪家好
  • web网站建设一题库东营百度推广公司
  • 招牌做的好的网站有哪些免费seo网站自动推广