unity的assetbundle加载
来源:互联网 发布:北大青鸟怎么样知乎 编辑:程序博客网 时间:2024/06/02 03:58
最近在写assetbundle的编辑器,顺便写了一下unity的资源管理器。
研究了一下王者农药的热更新机制,发现它的首页动画界面也可以热更新,但是这个时候才在启动进度条界面。
猜想了1下,他的资源加载路径是变化的。
优先加载缓存,发现缓存没得就加载包。
下次重新进入游戏,因为新数据已经down下来了,这个时候是直接加载缓存,就会发现初始动画改编了。
这里就需要动态设置加载路径。
说跑题了, 现先上传代码
/*************************************************************************************
**文 件 名:ResourceManager
**创建时间:2017/9/22 星期五 下午 1:55:46
**作 者:worthgod(qq: 243515320)
**工 号:
**说 明:
**版 本:V1.0.0
**修改时间:
**修 改 人:
*************************************************************************************/
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using WorthGodFramework;
using WorthGodFramework.Config;
using WorthGodFramework.Core;
using WorthGodFramework.Log;
namespace WorthGod
{
public class ResourceManager : SingletonMono<ResourceManager>
{
public Dictionary<string, AssetBundle> ObjectPool = new Dictionary<string, AssetBundle>();
void Awake()
{
DontDestroyOnLoad(this);
}
private string _baseDownloadingURL = "";
public string BaseDownloadingURL
{
get
{
if (string.IsNullOrEmpty(_baseDownloadingURL))
{
#if !UNITY_EDITOR
_baseDownloadingURL = Util.GetRelativePath()+ "WorthGodFramework/";
#else
_baseDownloadingURL = Util.DataPath + "WorthGodFramework/";
#endif
}
return _baseDownloadingURL;
}
set
{
_baseDownloadingURL = value;
}
}
// The base downloading url which is used to generate the full downloading url with the assetBundle names.
public void LoadAssetAsync<T>(string abname, string assetname, WorthGodFrameworkAction<T> func) where T:UnityEngine.Object
{
if (ObjectPool.ContainsKey(abname))
{
var a = ObjectPool[abname].AllAssetNames();
var m_Request = ObjectPool[abname].LoadAssetAsync(assetname, typeof(T));
if (func != null)
{
func(m_Request.asset as T);
}
}
else {
StartCoroutine(LoadingAb(abname, assetname, func));
}
}
IEnumerator LoadingAb<T>(string abname, string assetname, WorthGodFrameworkAction<T> func) where T : UnityEngine.Object
{
var filePath = BaseDownloadingURL + abname;
if (!File.Exists(filePath))
{
filePath = Util.DataPath + "WorthGodFramework/" + abname;
}
var download = new WWW(filePath);
yield return download;
if (download.error != null)
{
//todo 弹出下载失败的提示 --> 输出
_Log.Error("下载初始动画界面,路径--》 " + BaseDownloadingURL + abname);
yield return null;
}
else
{
if (download.isDone)
{
var EncryptByte = download.bytes;
if (EncryptByte != null)
{
////反解密
var BundleBytes = EncryptionHelper.getInstance().Decrypt(EncryptByte, WorthGodFrameworkConfig.EncryptionKey);
AssetBundle bundle = AssetBundle.LoadFromMemory(BundleBytes);
ObjectPool.Add(abname, bundle);
var m_Request = ObjectPool[abname].LoadAssetAsync(assetname, typeof(T));
if (func != null)
{
func(m_Request.asset as T);
}
}
}
}
download.Dispose();
download = null;
yield break;
}
public T LoadAsset<T>(string abname, string assetname) where T : UnityEngine.Object
{
if (ObjectPool.ContainsKey(abname))
{
var m_Request = ObjectPool[abname].LoadAssetAsync(assetname, typeof(T));
return m_Request.asset as T;
}
else
{
var filePath = BaseDownloadingURL + abname;
if (!File.Exists(filePath))
{
filePath = Util.DataPath + "WorthGodFramework/" + abname;
}
Debug.LogWarning("$#@$#@$#@ " + filePath);
if (!File.Exists(filePath)) return null as T;
var EncryptByte = File.ReadAllBytes(filePath);
////反解密
var BundleBytes = EncryptionHelper.getInstance().Decrypt(EncryptByte, WorthGodFrameworkConfig.EncryptionKey);
var bundle = AssetBundle.LoadFromMemory(BundleBytes);
ObjectPool.Add(abname, bundle);
var m_Request = bundle.LoadAsset(assetname, typeof(T));
return m_Request as T;
}
}
public void UnloadAb(string abname) {
if (ObjectPool.ContainsKey(abname))
{
ObjectPool[abname].Unload(false);
ObjectPool.Remove(abname);
}
}
}
}
- unity的assetbundle加载
- Unity的动态加载AssetBundle资源笔记。
- Unity中AssetBundle的打包和加载
- [unity]AssetBundle加载
- Unity AssetBundle依赖加载
- Unity AssetBundle 加载
- Unity创建Assetbundle与加载
- unity AssetBundle 加载资源 笔记
- unity AssetBundle打包以及加载
- Unity Assetbundle的加载方式的效率和内存占用
- Unity Assetbundle的加载方式的效率和内存占用
- Unity游戏开发使用Assetbundle加载场景的原理
- Unity游戏开发使用Assetbundle加载场景的原理
- Unity游戏开发使用Assetbundle加载场景的原理
- Unity游戏开发使用Assetbundle加载场景的实战
- unity 关于assetbundle 打包和加载的方法
- Unity最新版打包AssetBundle和加载的方法
- Unity AssetBundle的使用
- hdfs名字空间配额管理指南
- 水仙花数
- windows 命令行 jps查看java进程没有反应,如何用jps查看java进程
- Spring Cloud Stream中文翻译
- A多线程与并发学习总结
- unity的assetbundle加载
- 深度优先搜索(DFS)
- 【特征检测】FAST特征点检测算法
- Hello World以及jsx语法糖的介绍
- WdatePicker改变事件触发优化
- 11g搭建DataGuard的步骤
- 世界互联网大会,马云、马化腾、库克、李彦宏都说了一件事
- Android系统移植与调试之安装apk时MTK命令和出现Failure [INSTALL_FAILED_DEXOPT]问题解决方法
- ideal激活