当前位置:网站首页>Unity gets a resource that is referenced by those resources
Unity gets a resource that is referenced by those resources
2022-04-23 07:51:00 【[struggling]】
Unity Get a resource referenced by those resources
stay API Only know how one resource depends on other resources AssetDatabase.GetDependencies
When you delete a resource, you are often afraid that it will be referenced by other resources , Cause error , It is often necessary to find out which files refer to the resource ,Unity There is no way , Can pass AssetDatabase.GetDependencies Collect the reference relationships of all resources in the project , For example, resources in the project
A Refer to the D, B Refer to the C,
be Reverse lookup can determine D By A Refer to the , C By B Refer to the
stay Editor Create a new script in the folder AssetBeDepend.cs
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class AssetBeDepend
{
// Store all dependencies
private static Dictionary<string, List<string>> referenceCacheDic = new Dictionary<string, List<string>>();
// stay Assets Right click under the file to add a button in the pop-up board AssetBeDepend
[MenuItem("Assets/AssetBeDepend")]
static void Select()
{
CollectDepend();
// Get all selected file 、 The folder GUID
string[] guids = Selection.assetGUIDs;
foreach (var guid in guids)
{
// take GUID Convert to route
string assetPath = AssetDatabase.GUIDToAssetPath(guid);
IsBeDepend(assetPath);
}
}
// Collect all dependencies in the project
static void CollectDepend()
{
int count = 0;
// obtain Assets All resources under the folder
string[] guids = AssetDatabase.FindAssets("");
foreach (string guid in guids)
{
// take GUID Convert to path
string assetPath = AssetDatabase.GUIDToAssetPath(guid);
// Get all the resources that the file directly depends on
string[] dependencies = AssetDatabase.GetDependencies(assetPath, false);
foreach (var filePath in dependencies)
{
// dependency By assetPath Rely on
// Store all dependencies in the dictionary
List<string> list = null;
if (!referenceCacheDic.TryGetValue(filePath, out list))
{
list = new List<string>();
referenceCacheDic[filePath] = list;
}
list.Add(assetPath);
}
count++;
EditorUtility.DisplayProgressBar("Search Dependencies", "Dependencies", (float)(count * 1.0f / guids.Length));
}
EditorUtility.ClearProgressBar();
}
// Determine whether the file is dependent
static bool IsBeDepend(string filePath)
{
List<string> list = null;
if (!referenceCacheDic.TryGetValue(filePath, out list))
{
return false;
}
// Print out dependencies
foreach(var file in list)
{
Debug.LogError(filePath + " By :" + file + " quote ");
}
return true;
}
}
The comments in the code are more detailed , Not explaining the code
The test method : stay Assets Select a folder 、 Multiple files , Right mouse button , Click... In the pop-up panel AssetBeDepend Button
版权声明
本文为[[struggling]]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230627004605.html
边栏推荐
- js中对象的三种创建方式
- 踩坑日记:Unable to process Jar entry [module-info.class]
- Rethink | open the girl heart mode of station B and explore the design and implementation of APP skin changing mechanism
- 关于U盘数据提示RAW,需要格式化,数据恢复笔记
- The problem of exporting excel form with wireframe and internal spacing of form by using web form
- C# 多个矩形围成的多边形标注位置的问题
- 定位、修饰样式
- C#使用拉依达准则(3σ准则)剔除异常数据(.Net剔除一组数据中的奇异值)
- State synchronization and frame synchronization
- 根据某一指定的表名、列名及列值来向前或向后N条查相关列值的SQL自定义标量值函数
猜你喜欢

向量到一个平面的投影向量

js之排他思想及案例

C# 多个矩形围成的多边形标注位置的问题

js之节点操作,为什么要学习节点操作

Date object (JS built-in object)

C#控制相机,旋转,拖拽观察脚本(类似Scenes观察方式)

FUEL: Fast UAV Exploration using Incremental Frontier Structure and Hierarchical Planning

H5 local storage data sessionstorage, localstorage

Window10版MySQL设置远程访问权限后不起效果

King glory - unity learning journey
随机推荐
常用Markdown语法学习
Daily question | fear dominated by reverse linked list
Mongodb 启动警告信息处理
Use of command line parameter passing library argparse
js中对象的三种创建方式
Teach-Repeat-Replan: A Complete and Robust System for Aggressive Flight in Complex Environments
MySQL8. 0 installation / uninstallation tutorial [window10 version]
Unity 获取一个文件依赖的资源
防抖和节流
NodeJS(一) 事件驱动编程
UnityShader基础
The page displays the current time in real time
Custom time format (yyyy-mm-dd HH: mm: SS week x)
Judge whether the beginning and end of the string contain target parameters: startswith() and endswith() methods
系统与软件安全研究(一)
层次输出二叉树
中间人环境mitmproxy搭建
js之作用域、作用域链、全局变量和局部变量
数组扁平化
js之排他思想及案例