当前位置:网站首页>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之DOM事件

对js中argumens的简单理解

命令行参数传递库argparse的使用

使用flask时代码无报错自动结束,无法保持连接,访问不了url。

关于U盘数据提示RAW,需要格式化,数据恢复笔记

Understanding the Role of Individual Units in a Deep Neural Networks(了解各个卷积核在神经网络中的作用)

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

利用Lambda表达式解决c#文件名排序问题(是100大还是11大的问题)

Dictionary & lt; T1,T2&gt; Sorting problem

Protobuf 使用
随机推荐
Samplecamerafilter
Teach-Repeat-Replan: A Complete and Robust System for Aggressive Flight in Complex Environments
对js中argumens的简单理解
【Unity VFX】VFX特效入门笔记-火花制作
H5 local storage data sessionstorage, localstorage
C#使用拉依达准则(3σ准则)剔除异常数据(.Net剔除一组数据中的奇异值)
向量到一个平面的投影向量
IT高薪者所具备的人格魅力
大学学习路线规划建议贴
C# SmoothProgressBar自定义进度条控件
Towords Open World Object Detection
Window10版MySQL设置远程访问权限后不起效果
索引被锁数据无法写入ES问题处理
Moment. Format of format method function in JS
Double sided shader
SAP CR传输请求顺序、依赖检查
promise all的实现
读取修改resource文件夹下的json文件
js之DOM学习三种创建元素的方式
UnityShader基础