当前位置:网站首页>Unity3d+GameFramework:资源分析,资源依赖,循环依赖检测
Unity3d+GameFramework:资源分析,资源依赖,循环依赖检测
2022-07-23 05:45:00 【四夕立羽】
资源依赖


先生成Resource
根据ResourceCollection.xml
Resource resource = Resource.Create(name, variant, fileSystem, loadType, packed, resourceGroups);
m_Resources.Add(resource.FullName.ToLowerInvariant(), resource);
增加打包资源:luoyikun/Cube1–>{“m_Assets”:[],“m_ResourceGroups”:[],“Name”:“luoyikun/Cube1”,“Variant”:null,“FullName”:“luoyikun/Cube1”,“AssetType”:0,“IsLoadFromBinary”:false,“FileSystem”:null,“LoadType”:0,“Packed”:false}
增加打包资源:luoyikun/Cube2–>{“m_Assets”:[],“m_ResourceGroups”:[],“Name”:“luoyikun/Cube2”,“Variant”:null,“FullName”:“luoyikun/Cube2”,“AssetType”:0,“IsLoadFromBinary”:false,“FileSystem”:null,“LoadType”:0,“Packed”:false}
再把asset塞入
UnityGameFramework.Editor.ResourceTools.ResourceCollection.AssignAsset
/// <summary>
/// 打某个asset 塞入bundle中
/// </summary>
public bool AssignAsset(string guid, string name, string variant)
{
Asset asset = GetAsset(guid);
if (asset == null)
{
asset = Asset.Create(guid);
m_Assets.Add(asset.Guid, asset);
}
resource.AssignAsset(asset, isScene);
}
bundle:luoyikun/Cube1中塞入asset->{“Guid”:“60a1645014198164680bd6871329b73b”,“Name”:“Assets/GameMain/luoyikun/Cube1.prefab”,“Resource”:null}
bundle:luoyikun/Cube2中塞入asset->{“Guid”:“f0ce9e0e8a0456d4f992300134cfd602”,“Name”:“Assets/GameMain/luoyikun/Cube2.prefab”,“Resource”:null}
生成依赖关系
UnityGameFramework.Editor.ResourceTools.ResourceAnalyzerController.Analyze
DependencyData dependencyData = new DependencyData();
AnalyzeAsset(assetName, assets[i], dependencyData, scriptAssetNames);
dependencyData.RefreshData();
PublicTools.DebugObj(dependencyData, "增加一条依赖关系:" + assetName + "-->");
m_DependencyDatas.Add(assetName, dependencyData);
增加一条依赖关系:Assets/GameMain/luoyikun/Cube1.prefab–>->{“m_DependencyResources”:[{“m_Assets”:[{“Guid”:“f0ce9e0e8a0456d4f992300134cfd602”,“Name”:“Assets/GameMain/luoyikun/Cube2.prefab”}],“m_ResourceGroups”:[],“Name”:“luoyikun/Cube2”,“Variant”:null,“FullName”:“luoyikun/Cube2”,“AssetType”:1,“IsLoadFromBinary”:false,“FileSystem”:null,“LoadType”:0,“Packed”:false}],“m_DependencyAssets”:[{“Guid”:“f0ce9e0e8a0456d4f992300134cfd602”,“Name”:“Assets/GameMain/luoyikun/Cube2.prefab”,“Resource”:{“m_Assets”:[],“m_ResourceGroups”:[],“Name”:“luoyikun/Cube2”,“Variant”:null,“FullName”:“luoyikun/Cube2”,“AssetType”:1,“IsLoadFromBinary”:false,“FileSystem”:null,“LoadType”:0,“Packed”:false}}],“m_ScatteredDependencyAssetNames”:[],“DependencyResourceCount”:1,“DependencyAssetCount”:1,“ScatteredDependencyAssetCount”:0}
增加一条依赖关系:Assets/GameMain/luoyikun/Cube2.prefab–>->{“m_DependencyResources”:[{“m_Assets”:[{“Guid”:“60a1645014198164680bd6871329b73b”,“Name”:“Assets/GameMain/luoyikun/Cube1.prefab”}],“m_ResourceGroups”:[],“Name”:“luoyikun/Cube1”,“Variant”:null,“FullName”:“luoyikun/Cube1”,“AssetType”:1,“IsLoadFromBinary”:false,“FileSystem”:null,“LoadType”:0,“Packed”:false}],“m_DependencyAssets”:[{“Guid”:“60a1645014198164680bd6871329b73b”,“Name”:“Assets/GameMain/luoyikun/Cube1.prefab”,“Resource”:{“m_Assets”:[],“m_ResourceGroups”:[],“Name”:“luoyikun/Cube1”,“Variant”:null,“FullName”:“luoyikun/Cube1”,“AssetType”:1,“IsLoadFromBinary”:false,“FileSystem”:null,“LoadType”:0,“Packed”:false}}],“m_ScatteredDependencyAssetNames”:[],“DependencyResourceCount”:1,“DependencyAssetCount”:1,“ScatteredDependencyAssetCount”:0}
循环依赖检测

循环引用解释

GameFrameworkException: Can not load dependency asset ‘Assets/GameMain/luoyikun/Cube2.prefab’ when load asset ‘Assets/GameMain/luoyikun/Cube1.prefab’.
尝试在加载依赖时,已加载不放入任务
在GameFramework.Resource.ResourceManager.ResourceLoader.LoadDependencyAsset
List<LoadResourceTaskBase> listTask = new List<LoadResourceTaskBase>(8);
m_TaskPool.GetAllTasks(listTask);
bool isExist = false;
GameFrameworkLog.Info("所有任务数量{0}", listTask.Count);
for (int i = 0; i < listTask.Count; i++)
{
if (listTask[i].AssetName == assetName)
{
GameFrameworkLog.Info("所有任务中存在{0}", assetName);
isExist = true;
return true;
}
}
出现a等待b,b等待a,因为
GameFramework.Resource.ResourceManager.ResourceLoader.LoadResourceAgent.Start
//遍历依赖
foreach (string dependencyAssetName in m_Task.GetDependencyAssetNames())
{
//如果依赖asset不能spawn,接着等待
if (!m_ResourceLoader.m_AssetPool.CanSpawn(dependencyAssetName))
{
GameFrameworkLog.Info("{0}依赖项{1}未加载完成", m_Task.AssetName,dependencyAssetName);
m_Task.StartTime = default(DateTime);
return StartTaskStatus.HasToWait;
}
}
会互相等待依赖项加载完,所以cube1等待cube2,cube2等待cube1,不会执行下去
循环检测
UnityGameFramework.Editor.ResourceTools.ResourceAnalyzerController.CircularDependencyChecker
foreach (string host in hosts) //主资源被引用情况
{
LinkedList<string> route = new LinkedList<string>();
HashSet<string> visited = new HashSet<string>();
if (Check(host, route, visited))
{
results.Add(route.ToArray());
}
}
private bool Check(string host, LinkedList<string> route, HashSet<string> visited)
{
//把主资源,放入参观表,路径表
visited.Add(host);
route.AddLast(host);
foreach (Stamp stamp in m_Stamps)
{
if (host != stamp.HostAssetName) //只找当前host的依赖情况
{
GameFrameworkLog.Info("不是主资源名跳过{0}", host);
continue;
}
//如果参观表包含了依赖 stamp的依赖
if (visited.Contains(stamp.DependencyAssetName))
{
//插入路径表最后项目返回
route.AddLast(stamp.DependencyAssetName);
return true;
}
//递归检查 当前stamp的依赖 b
if (Check(stamp.DependencyAssetName, route, visited))
{
return true;
}
}
//路径表移除最后一个
route.RemoveLast();
//参观表移除host
visited.Remove(host);
return false;
}
在Stamps中存在循环引用的两对
记录1
"HostAssetName": "Assets/GameMain/luoyikun/Cube1.prefab",
"DependencyAssetName": "Assets/GameMain/luoyikun/Cube2.prefab",
记录2
"HostAssetName": "Assets/GameMain/luoyikun/Cube2.prefab",
"DependencyAssetName": "Assets/GameMain/luoyikun/Cube1.prefab",
- cube1放入visited,route中,挂起处1
- 遍历依赖对,递归调用,cube2放入visited ,route的最后
- 递归,遍历所有依赖对,cube2不是记录1的host,跳过记录1
- 来到记录2,此时visited包含了cube1,把cube1插入route的最后,,此时route 为 cube1,cube2,cube1返回true
- 再遍历记录2,依次找到循环
边栏推荐
- Embedded from entry to mastery (buried) - sharing of ultra detailed knowledge points 2
- 匿名上位机v7波形显示
- B树 和 B+树
- (1)ASIO
- LVS负载均衡调度原理及配置方法
- Analysis of 100 questions and answers in Higher Algebra
- 整数乘以整数溢出了
- Problems encountered in configuring the historical version of detectron
- vscode配置
- Find the saddle point of the matrix and its corresponding subscript.
猜你喜欢

Navicat for MySQL 安装教程
![[bootloader architecture and brushing process based on UDS service]](/img/c7/de4f1e32f89173e18d74d2f624f3f9.png)
[bootloader architecture and brushing process based on UDS service]

Questions and answers of basic principles of steel structure

Steel structure review questions

Using one-way linked list to realize queue
![[AUTOSAR candrive 2. understand the mapping relationship between communication HOH, canid and pduid]](/img/6d/ae145053b5fc46b583e5892ca4a945.png)
[AUTOSAR candrive 2. understand the mapping relationship between communication HOH, canid and pduid]

Anonymous upper computer V7 waveform display

Review of basic principles of steel structure

表格个人简历

Knowledge structure of advanced algebra
随机推荐
0双指针 LeetCode844. 比较含退格的字符串
【学习总结】
用单向链表实现 队列
[AUTOSAR com 3. signal sending and receiving process tx/rx]
ThreadLocal到底在干嘛?
5.4 installation and use of pyinstaller Library
Blog building I: Framework selection
使用InfluxDB数据库的疑惑
AWK 程序设计语言
Redis——配置及应用
视频编解码相关资料汇总
Vs attribute configuration related knowledge
Jetson TX1安装 Pytorch
C语言数据库:详细的说明用学生管理系统了解数据库的操作,简单易懂。
嵌入式从入门到精通(入土)——超详细知识点分享1
博客搭建三:评论系统选择
hot 100 动态规划
C语言小项目——学生成绩管理系统
【基于UDS服务的BootLoader架构和刷写流程】
Steel structure review questions