Loxodon Framework Bundle是一个非常好用的AssetBundle加载器,也是一个AssetBundle冗余分析工具。它能够自动管理AssetBundle之间复杂的依赖关系,它通过引用计数来维护AssetBundle之间的依赖。你既可以预加载一个AssetBundle,自己管理它的释放,也可以直接通过异步的资源加载函数直接加载资源,资源加载函数会自动去查找资源所在的AB包,自动加载AB,使用完后又会自动释放AB。 它还支持弱缓存,如果对象模板已经在缓存中,则不需要重新去打开AB。它支持多种加载方式,WWW加载,UnityWebRequest加载,File方式的加载等等(在Unity5.6以上版本,请不要使用WWW加载器,它会产生内存峰值)。它提供了一个AssetBundle的打包界面,支持加密AB包(只建议加密敏感资源,因为会影响性能)。同时它也绕开了Unity3D早期版本的一些bug,比如多个协程并发加载同一个资源,在android系统会出错。它的冗余分析是通过解包AssetBundle进行的,这比在编辑器模式下分析的冗余更准确。

下载地址:AssetStore 下载

打包工具介绍

  • 编辑打包的工具:
  • 打包后的文件概要信息
  • 打包后的文件
  • 冗余分析工具
  • 冗余分析结果

使用示例

  • 初始化IResources

整个项目面向接口设计,任何组件都是可以自定义或者可选的,下图是我默认的一个示例。

IResources 

  • 自定义AB的查询规则

AssetBundle资源可以存在Unity3D的缓存中,也可以存在持久化目录中或者在StreamingAssets目录中,关于如何存储资源,一般和项目怎么更新资源有关系,在我的CustomBundleLoaderBuilder中,你可以自定义自己的加载规则和选择使用自己喜欢的加载器(WWW、UnityWebRequest、File等)。

using System;using Loxodon.Framework.Bundles;namespace Loxodon.Framework.Examples.Bundle
{public class CustomBundleLoaderBuilder : AbstractLoaderBuilder{private bool useCache;private IDecryptor decryptor;public CustomBundleLoaderBuilder(Uri baseUri, bool useCache) : this(baseUri, useCache, null){}public CustomBundleLoaderBuilder(Uri baseUri, bool useCache, IDecryptor decryptor) : base(baseUri){this.useCache = useCache;this.decryptor = decryptor;}public override BundleLoader Create(BundleManager manager, BundleInfo bundleInfo, BundleLoader[] dependencies){//Customize the rules for finding assets.Uri loadBaseUri = this.BaseUri; //eg: http://your ip/bundlesif (this.useCache && BundleUtil.ExistsInCache(bundleInfo)){//Load assets from the cache of Unity3d.loadBaseUri = this.BaseUri;
#if UNITY_5_4_OR_NEWERreturn new UnityWebRequestBundleLoader(new Uri(loadBaseUri, bundleInfo.Filename), bundleInfo, dependencies, manager, this.useCache);
#elsereturn new WWWBundleLoader(new Uri(loadBaseUri, bundleInfo.Filename), bundleInfo, dependencies, manager, this.useCache);
#endif}if (BundleUtil.ExistsInStorableDirectory(bundleInfo)){//Load assets from the "Application.persistentDataPath/bundles" folder./* Path: Application.persistentDataPath + "/bundles/" + bundleInfo.Filename  */loadBaseUri = new Uri(BundleUtil.GetStorableDirectory());}#if !UNITY_WEBGL || UNITY_EDITORelse if (BundleUtil.ExistsInReadOnlyDirectory(bundleInfo)){//Load assets from the "Application.streamingAssetsPath/bundles" folder./* Path: Application.streamingAssetsPath + "/bundles/" + bundleInfo.Filename */loadBaseUri = new Uri(BundleUtil.GetReadOnlyDirectory());}
#endifif (bundleInfo.IsEncrypted){if (this.decryptor != null && bundleInfo.Encoding.Equals(decryptor.AlgorithmName))return new CryptographBundleLoader(new Uri(loadBaseUri, bundleInfo.Filename), bundleInfo, dependencies, manager, decryptor);throw new NotSupportedException(string.Format("Not support the encryption algorithm '{0}'.", bundleInfo.Encoding));}//Loads assets from an Internet address if it does not exist in the local directory.
#if UNITY_5_4_OR_NEWERif (this.IsRemoteUri(loadBaseUri))return new UnityWebRequestBundleLoader(new Uri(loadBaseUri, bundleInfo.Filename), bundleInfo, dependencies, manager, this.useCache);elsereturn new FileAsyncBundleLoader(new Uri(loadBaseUri, bundleInfo.Filename), bundleInfo, dependencies, manager);
#elsereturn new WWWBundleLoader(new Uri(loadBaseUri, bundleInfo.Filename), bundleInfo, dependencies, manager, this.useCache);
#endif}}
}

  • 加载一个资源

加载资源是根据资源的路径来加载的,如果你选择了路径自动映射的路径解析器,那么通过资源的路径,就可以自动找到所在的AssetBundle包。下面是资源加载的示例。

  1. 通过回调的方式加载一个资源
        void Load(string[] names){IProgressResult<float, GameObject[]> result = resources.LoadAssetsAsync<GameObject>(names);result.Callbackable().OnProgressCallback(p =>{Debug.LogFormat("Progress:{0}%", p * 100);});result.Callbackable().OnCallback((r) =>{try{if (r.Exception != null)throw r.Exception;foreach (GameObject template in r.Result){GameObject.Instantiate(template);}}catch (Exception e){Debug.LogErrorFormat("Load failure.Error:{0}", e);}});}

2.通过回调方式加载场景

        void LoadSceneByCallback(string sceneName){ISceneLoadingResult<Scene> result = this.resources.LoadSceneAsync(sceneName);result.AllowSceneActivation = false;result.OnProgressCallback(p =>{//Debug.LogFormat("Loading {0}%", (p * 100));});result.OnStateChangedCallback(state =>{if (state == LoadState.Failed)Debug.LogFormat("Loads scene '{0}' failure.Error:{1}", sceneName, result.Exception);else if (state == LoadState.Completed)Debug.LogFormat("Loads scene '{0}' completed.", sceneName);else if (state == LoadState.AssetBundleLoaded)Debug.LogFormat("The AssetBundle has been loaded.");else if (state == LoadState.SceneActivationReady){Debug.LogFormat("Ready to activate the scene.");result.AllowSceneActivation = true;}});}

3.通过协程的方式加载场景

        IEnumerator LoadSceneByCoroutine(string sceneName){ISceneLoadingResult<Scene> result = this.resources.LoadSceneAsync(sceneName);while (!result.IsDone){//Debug.LogFormat("Loading {0}%", (result.Progress * 100));yield return null;}if (result.Exception != null){Debug.LogFormat("Loads scene '{0}' failure.Error:{1}", sceneName, result.Exception);}else{Debug.LogFormat("Loads scene '{0}' completed.", sceneName);}}

  • 下载示例

我提供了一个AssetBundle资源下载的示例,它通过最新版本的资源索引库Manifest.dat ,查找本地不存在的AB资源,然后通过网络下载本地缺失的AB资源。

IEnumerator Download(){this.downloading = true;try{IProgressResult<Progress, BundleManifest> manifestResult = this.downloader.DownloadManifest(BundleSetting.ManifestFilename);yield return manifestResult.WaitForDone();if (manifestResult.Exception != null){Debug.LogFormat("Downloads BundleManifest failure.Error:{0}", manifestResult.Exception);yield break;}BundleManifest manifest = manifestResult.Result;IProgressResult<float, List<BundleInfo>> bundlesResult = this.downloader.GetDownloadList(manifest);yield return bundlesResult.WaitForDone();List<BundleInfo> bundles = bundlesResult.Result;if (bundles == null || bundles.Count <= 0){Debug.LogFormat("Please clear cache and remove StreamingAssets,try again.");yield break;}IProgressResult<Progress, bool> downloadResult = this.downloader.DownloadBundles(bundles);downloadResult.Callbackable().OnProgressCallback(p =>{Debug.LogFormat("Downloading {0:F2}KB/{1:F2}KB {2:F3}KB/S", p.GetCompletedSize(UNIT.KB), p.GetTotalSize(UNIT.KB), p.GetSpeed(UNIT.KB));});yield return downloadResult.WaitForDone();if (downloadResult.Exception != null){Debug.LogFormat("Downloads AssetBundle failure.Error:{0}", downloadResult.Exception);yield break;}Debug.Log("OK");if (this.resources != null){//update BundleManager's manifestBundleManager manager = (this.resources as BundleResources).BundleManager as BundleManager;manager.BundleManifest = manifest;}#if UNITY_EDITORUnityEditor.EditorUtility.OpenWithDefaultApp(BundleUtil.GetStorableDirectory());
#endif}finally{this.downloading = false;}}

下面是这个项目在AssetStore上的介绍

AssetBundle Manager for Unity3D

Loxodon Framework Bundle is an AssetBundle manager.It provides a functionality that can automatically manage/load an AssetBundle and its dependencies from local or remote location.Asset Dependency Management including BundleManifest that keep track of every AssetBundle and all of their dependencies. An AssetBundle Simulation Mode which allows for iterative testing of AssetBundles in a the Unity editor without ever building an AssetBundle.

The Loxodon Framework Bundle includes all the source code, it works alone, or works with the Loxodon Framework, AssetBundles-Browser.

For tutorials,examples and support,please see the project.You can also discuss the project in the Unity Forums.

Asset Redundancy Analyzer

The asset redundancy analyzer can help you find the redundant assets included in the AssetsBundles.Create a fingerprint for the asset by collecting the characteristic data of the asset. Find out the redundant assets in all AssetBundles by fingerprint comparison.it only supports the AssetBundle of Unity 5.6 or higher.

Tested in Unity 3D on the following platforms:
PC/Mac/Linux
Android
IOS
UWP(Windows 10)
WebGL

Key features:

  • Support encryption and decoding of the AssetBundle files(支持AssetBundle文件的加密和解密);
  • Use reference counting to manage the dependencies of AssetBundle(使用引用计数来管理AssetBundle的依赖关系);
  • Automatically unloading AssetBundle with reference count 0 by destructor or "Dispose" method(当引用计数为0时,通过析构函数或者Dispose函数自动卸载AssetBundle);
  • Use weak cache to optimize load performance(使用弱缓存来优化加载性能);
  • Interface-oriented programming, you can customize the loader and file search rules for the AssetBundle(面向接口编程,可以自定义加载器,自定义AssetBundle的查找规则);
  • Support for simulating loading in the editor without building AssetBundles(在编辑器下,支持模拟AssetBundle的方式加载资源以方便测试);
  • Supports the unpacking and the redundancy analysis of the AssetBundle(支持通过AssetBundle包来分析资源冗余,这比在Editor模式分析的冗余更准确);

For More Information Contact Us at: yangpc.china@gmail.com

unity 异步加载网络图片_一个非常好用的AssetBundle资源加载器相关推荐

  1. Unity3D之AssetBundle资源加载封装

    转载自:http://www.luzexi.com/unity3d/游戏通用模块/前端技术/2014/04/16/Unity3D之AssetBundle资源加载封装/ GitHub:https://g ...

  2. python selenium 等待js加载完成_一个用python完成的RSA成功模拟JS加密完成自动登录...

    编程工具启动图 自从做了产品,很久没有正二八经的写过代码了.最近这几天由于工作需要,一时心血来潮开始写python代码,最开始以为一个自动登录应该很简单,又没有手机验证和图片验证.结果一执行卡在一个加 ...

  3. java懒加载注解_在springboot中实现个别bean懒加载的操作

    懒加载---就是我们在spring容器启动的是先不把所有的bean都加载到spring的容器中去,而是在当需要用的时候,才把这个对象实例化到容器中. @Lazy 在需要懒加载的bean上加上@Lazy ...

  4. python如何校验页面元素是否加载完毕_爬虫(八十七)等待页面加载完成(Waits)...

    现在的大多数的Web应用程序是使用Ajax技术.当一个页面被加载到浏览器时, 该页面内的元素可以在不同的时间点被加载.这使得定位元素变得困难, 如果元素不再页面之中,会抛出 ElementNotVis ...

  5. sql文件加载出错_四十二、SparkSQL通用数据源加载(load)和保存(save)

    SparkSQL能用数据加载(load)和保存(save) 对于Spark SQL的DataFrame来说,无论是从什么数据源创建出来的DataFrame,都有一些共同的load和save操作.loa ...

  6. java8 时间加一秒_年货买瓜子有讲究!这些加了“料”的瓜子不安全!

    还有不到一个月的时间 就是春节假期 不少人都开始置办年货了 过年一家老小围坐在一起 边嗑瓜子边唠嗑 是不少家庭的日常动作 瓜子可以说是最常见 最受欢迎的年货之一了 它不但含有丰富的不饱和脂肪酸 及维生 ...

  7. 我的世界java服务器怎么加材质包_我的世界网易版服务器怎么加材质包

    我的世界网易版服务器加材质包方法 1.如果是mcpack文件直接使用Win10的我的世界打开即可. 2.如果是压缩包就要解压到:C:\Users\你的用户名\appdata\Local\Package ...

  8. 【从零开始游戏开发】Unity3D AssetBundle资源加载和封装 | 全面总结 | 建议收藏

    你知道的越多,你不知道的越多

  9. android 图片加载 软引用_Android 异步加载网络图片并缓存到本地 软引用 学习分享(转)...

    迪 王. 于 星期四, 20/02/2014 - 21:36 提交 在android应用开发的时候,加载网络图片是一个非常重要的部分,很多图片不可能放在本地,所以就必须要从服务器或者网络读取图片. 软 ...

最新文章

  1. wkwebView基本使用方法
  2. 理解 Delphi 的类(十) - 深入方法[28] - 递归函数实例: 搜索当前目录下的所有嵌套目录...
  3. 如何使用lazyCSRF在Burp Suite上生成强大的CSRF PoC
  4. 2、Spring Cloud - 入门概述
  5. .NET异常设计原则
  6. 快速检查REST API是否有效的方法-从清单文件中获取详细信息
  7. myeclipse怎么运行c语言,windows下MyEclipse安装配置C/C++开发环境
  8. java学生签到系统视频教程_手把手教你做一个Java web学生信息、选课、签到考勤、成绩管理系统附带完整源码及视频开发教程...
  9. 【数据库系统】数据库体系结构
  10. SUPERSET使用笔记
  11. 【工程项目经验】之C不定宏参数加颜色打印
  12. java反射优化_JAVA反射优化
  13. 2019牛客多校第二场E MAZE(线段树 + 矩阵)题解
  14. 3月10日 QR分解求非齐次线性,SVD分解求齐次线性最小二乘
  15. nonebot2.0.0a16-qq机器人框架安装及搭建教程
  16. 慕课-现代通信技术-知识点记录
  17. 开箱体验: Web研发从石器时代过渡青铜时代复盘心得
  18. 闰年2月29天,我们都知道怎样判断,但知道为什么那样做吗?
  19. linux vdi,linux – 调整vdi大小不能正常工作
  20. python基于flask_sockets实现WebSocket——叁

热门文章

  1. A Tutorial on Clustering Algorithms-聚类小知识
  2. CVPR 2019 GCT:《Graph Convolutional Tracking》论文笔记
  3. 组合的输出pascal程序
  4. 美元汇率pascal程序
  5. dmx512协议c语言编程,DMX512协议+c程序代码.pdf
  6. mc服务器村民交易修改,【原创】【教程】MCPE自定义村民交易内容
  7. react 判断地址是否有效_继续,react-redux原理解析
  8. Soring冲刺计划第三天(个人)
  9. PP生产订单成本的计划、控制和结算
  10. BZOJ2194 快速傅立叶之二 【fft】