网络资源加载:

 string path ="file://"+ Application.streamingAssetsPath + "\\windows\\123";
string _path = "file://" +
Application.streamingAssetsPath + "\\windows\\ziyuab";
using (WWW www = new WWW(path))
{
yield return www;
using (WWW Xww = new WWW(_path))
{
yield return Xww;
if (www != null && Xww != null)
{
AssetBundle ab = www.assetBundle;
AssetBundle et= Xww.assetBundle;
if (ab != null)
{
GameObject tempObj = ab.LoadAsset<GameObject>("Cube");
Instantiate(tempObj);
}
}
else
{
Debug.Log("下载不成功!");
}
}
}

注意:定义路径如果是本地文件的话,在路径前加上"file://"

加载依赖关系:

   string ABPath;
public string ABName;
string bpath;
List<AssetBundle> aBlist;
void WanZheng()
{
aBlist=new List<AssetBundle>();
ABPath = Application.streamingAssetsPath + "\\windows\\";
bpath = Application.streamingAssetsPath + "/windows/windows";//依赖关系资源读取总路径
Yilai(bpath);//判断物体是否有依赖,有就加载出来,没有就不加载
#region 加载预制体,并实例化
AssetBundle _ab = AssetBundle.LoadFromFile(ABPath+ABName);//在此处_ab已将依赖加载出来了
GameObject obj = _ab.LoadAsset<GameObject>("Cube");
Instantiate(obj);
#endregion #region 释放内存
foreach (AssetBundle item in aBlist)
{
item.Unload(false);//清除依赖内存
}
_ab.Unload(true);//清除物体本身内存
AssetBundle _ab01 = AssetBundle.LoadFromFile(ABPath + ABName);//在此处_ab已将依赖加载出来了
GameObject obj01 = _ab01.LoadAsset<GameObject>("Cube");
Instantiate(obj01,Vector3.one,Quaternion.identity);
#endregion
}
void Yilai(string bpath)
{
AssetBundle yilaiAB = AssetBundle.LoadFromFile(bpath);//读取依赖
AssetBundleManifest manifest
= yilaiAB.LoadAsset<AssetBundleManifest>("AssetBundleManifest");//读取依赖关系列表
string[] depndencies = manifest.GetAllDependencies(ABName);//按照名字加载名字旗下的依赖关系 //将依赖放入列表并加载出来
if (depndencies.Length!=)
{
foreach (string s in depndencies)
{
aBlist.Add(loadDepndenciesByList(ABPath,s));
}
}
}
private AssetBundle loadDepndenciesByList(string ABpath,string name) //加载依赖文件,按列表里的名字
{
return AssetBundle.LoadFromFile(ABpath+name);
}

笔记:

yield return xy;意思是线程中断,等待过程完成之后再进行.

截至目前学习存在的问题:

1). 实战项目中成百上千的大量资源需要(批量)打包处理,不可能手工维护方式给每个资源添加assetbundle包名称

2). Unity维护AssetBundle包的依赖关系不是很完善,主要体现在Unity仅仅维护包与包之间依赖关系的记录上。

(通过每个包创建的*.manifest文本文件实现)。如果要加载一个有多重依赖项的AssetBundle包,则要手工写代码,

把底层所有依赖包关系需要预先进行加载后才可以

3). AssetBundle包的商业应用涉及很多步骤: AB包的加载、 AB包依赖关系(要求: 不遗漏、不重复)、 资源的

提取与释放等。手工以及简单写代码实现功能,将是一项繁重海量工作,效率低下

最新文章

  1. Linux 江湖系列阶段性总结
  2. 24个很赞的 Node.js 免费教程和在线指南
  3. Python关键字参数
  4. ifrog-1028 Bob and Alice are playing numbers(trie树)
  5. main函数和启动例程
  6. Visaul Studio2015安装以及c++单元测试使用方法
  7. POJ3254Corn Fields(状压DP)
  8. [转]使用Linux命令行测试网速
  9. C#单元测试工具包:MvcContrib
  10. 都能读懂的css3 3D变形效果
  11. Scikit-learn:主要模块和基本使用方法
  12. 【Spring Boot】关于上传文件例子的剖析
  13. ubuntu安装nvidia显卡驱动
  14. cocos2dx 3.17.1 导演类
  15. setDaemon 守护线程
  16. SpringBoot集成redis,使用@Cachexxxx
  17. 读取嵌入到word的Excel对象
  18. 从头到尾使用Geth的说明-3-geth参数说明和环境配置
  19. how to check the computer is 32 bit or 64bit in linux
  20. 20155202张旭 Exp4 恶意代码分析

热门文章

  1. 第28月第24天 requestSerializer
  2. webpack构建Vue工程
  3. TCP-IP详解笔记5
  4. sed 正则 ! 取反
  5. .Net Core---- 自带Json返回日期带T格式 解决
  6. [Linux]权限s权限和t权限
  7. java入门写的第一个代码《HelloWorld》
  8. Java_修饰符
  9. 数位dp-入门模板题 hdu2089
  10. 将Emacs Org任务树导出至Freeplane思维导图