博客
关于我
AssetBundle框架主流程之MultiABMgr
阅读量:112 次
发布时间:2019-02-25

本文共 3758 字,大约阅读时间需要 12 分钟。

using System.Collections;using System.Collections.Generic;using UnityEngine;public class MultiABMgr {    private SingleABLoader _CurrentSingleABLoader;    private Dictionary
_DicSingleABLoaderCache; //当前Assetbundle 名称 private string _CurrentABName; //AB包与对应依赖和引用关系集合 private Dictionary
_DicABRelation; //当前模块(调试使用) private string _CurrentModelName; public MultiABMgr(string abname, string modlename) { _CurrentABName = abname; _CurrentSingleABLoader = new SingleABLoader(abname); _DicSingleABLoaderCache = new Dictionary
(); _DicABRelation = new Dictionary
(); _CurrentModelName = modlename; } ///
/// 加载AB包 递归加载 /// public void LoadAssetBundle(string abname) { Debug.Log("AB--" + abname); if (!_DicABRelation.ContainsKey(abname)) { ABRelation aBRelation = new ABRelation(abname); _DicABRelation.Add(abname, aBRelation); } ABRelation tmpaBRelationObj = _DicABRelation[abname]; //得到指定AB包的所有依赖和引用关系(查询Manifest清单文件) string[] strDependenceArray = ABManifestLoader.GetInstance().GetAllDepences(abname); foreach (var item in strDependenceArray) { //添加依赖 tmpaBRelationObj.AddDependence(item); //添加引用 if (!_DicABRelation.ContainsKey(item)) { ABRelation aBRelation = new ABRelation(item); aBRelation.AddReference(abname); _DicABRelation.Add(item, aBRelation); ABRelation tmpABRelationObj = _DicABRelation[item]; //先加载依赖AB包 LoadAssetBundle(item); } else //AB包已经加载 { ABRelation aBRelation = _DicABRelation[abname]; //添加AB包引用关系(被依赖) aBRelation.AddReference(abname); } } //真正加载AB包 if (_DicSingleABLoaderCache.ContainsKey(abname)) { return; //AB包已经加载 } else { _CurrentSingleABLoader = new SingleABLoader(abname); _DicSingleABLoaderCache.Add(abname, _CurrentSingleABLoader); _DicSingleABLoaderCache[abname].LoadAssetBundle(); } } ///
/// /// ///
///
///
///
public UnityEngine.Object LoadAsset(string abName, string assetName, bool isCache = false) { foreach (var item_abname in _DicSingleABLoaderCache.Keys) { Debug.Log(item_abname); if (abName == item_abname) { return _DicSingleABLoaderCache[item_abname].LoadAsset(assetName, isCache); } } Debug.Log("加载资源" + _DicSingleABLoaderCache.Count); Debug.LogError(GetType() + "/LoadAsset()/找不到Assetbundle包,无法加载资源,请检查abname=" + abName + ",assetName=" + assetName); return null; } ///
/// 释放所有的资源 /// public void DisposeAllAsset() { try { //逐一释放所有加载过的Asset Bundle 包中的资源 foreach (SingleABLoader item in _DicSingleABLoaderCache.Values) { item.DisposeAll(); } } finally { _DicSingleABLoaderCache.Clear(); _DicSingleABLoaderCache = null; //释放其他对象资源 _DicABRelation.Clear(); _DicABRelation = null; _CurrentABName = null; _CurrentModelName = null; //卸载未使用到的资源 Resources.UnloadUnusedAssets(); //强制垃圾收集 System.GC.Collect(); } }}

--若是对您有所帮助,世界便多了一份你我的温暖

--您的支持将是我的动力,手有余粮的话,一点点赞赏我将开心不已(一毛钱也是极好的)

转载地址:http://bkt.baihongyu.com/

你可能感兴趣的文章
mysql中int、bigint、smallint 和 tinyint的区别、char和varchar的区别详细介绍
查看>>
mysql中json_extract的使用方法
查看>>
mysql中json_extract的使用方法
查看>>
mysql中kill掉所有锁表的进程
查看>>
mysql中like % %模糊查询
查看>>
MySql中mvcc学习记录
查看>>
mysql中null和空字符串的区别与问题!
查看>>
MySQL中ON DUPLICATE KEY UPDATE的介绍与使用、批量更新、存在即更新不存在则插入
查看>>
MYSQL中TINYINT的取值范围
查看>>
MySQL中UPDATE语句的神奇技巧,让你操作数据库如虎添翼!
查看>>
Mysql中varchar类型数字排序不对踩坑记录
查看>>
MySQL中一条SQL语句到底是如何执行的呢?
查看>>
MySQL中你必须知道的10件事,1.5万字!
查看>>
MySQL中使用IN()查询到底走不走索引?
查看>>
Mysql中使用存储过程插入decimal和时间数据递增的模拟数据
查看>>
MySql中关于geometry类型的数据_空的时候如何插入处理_需用null_空字符串插入会报错_Cannot get geometry object from dat---MySql工作笔记003
查看>>
mysql中出现Incorrect DECIMAL value: '0' for column '' at row -1错误解决方案
查看>>
mysql中出现Unit mysql.service could not be found 的解决方法
查看>>
mysql中出现update-alternatives: 错误: 候选项路径 /etc/mysql/mysql.cnf 不存在 dpkg: 处理软件包 mysql-server-8.0的解决方法(全)
查看>>
Mysql中各类锁的机制图文详细解析(全)
查看>>