当前位置:网站首页>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
边栏推荐
- Nodejs (I) event driven programming
- 斐波拉去动态规划
- SampleCameraFilter
- SVG中年月日相关的表达式
- NodeJS(六) 子进程操作
- Mongodb starts warning information processing
- 'NPM' is not an internal or external command, nor is it a runnable program or batch file
- Solve the problem of deploying mysql8 in docker with correct password but unable to log in to MySQL
- js之预解析
- 【NLP笔记】CRF原理初探
猜你喜欢
随机推荐
Unity获取真实地理地图应用Terrain笔记
平面定义-平面方程
instanceof的实现原理
.NET 5 的新功能 What‘s new in .NET 5
颜色转换公式大全及转换表格(31种)
js案例之求最大值,反转数组,冒泡排序
SQL针对字符串型数字进行排序
Unity screen adaptation
二叉树的深度
UnityShader基础
One of event management
数组扁平化
庄懂的TA笔记(七)<Lambert+Phong+Shadow+3EvColor+AO>
双面显示的shader
【NLP笔记】CRF原理初探
Daily question | fear dominated by reverse linked list
MySQL in window10 version does not work after setting remote access permission
Mongodb starts warning information processing
设置了body的最大宽度,但是为什么body的背景颜色还铺满整个页面?
Online Safe Trajectory Generation For Quadrotors Using Fast Marching Method and Bernstein Basis Poly









