Unity5.0 AssetBundle 实验
来源:互联网 发布:网络IP盗取 编辑:程序博客网 时间:2024/05/17 05:05
在unity5中,选中资源一键打包,创建一个简单的脚本,一句代码就行:
BuildPipeline.BuildAssetBundles(Application.dataPath + "/AssetBundle", BuildAssetBundleOptions.UncompressedAssetBundle);
资源打包好后,在我们的AssetBundle文件夹中,有好多manifest文件,可以供我们来查看是否有依赖关系,哈希ID,和CRC信息
接下来,我们需要写一个脚本来加载,首先加载有依赖的项,然后再加载被依赖的项,保证这个顺序正确,代码如下:
void OnGUI()
{
if (GUILayout.Button("LoadAssetbundle"))
{
//Find the path of your mainfest file
AssetBundle manifestBundle = AssetBundle.CreateFromFile(Application.dataPath +
"/AssetBundle/AssetBundle");
if (manifestBundle != null)
{
//Load it at first
AssetBundleManifest manifest = (AssetBundleManifest)manifestBundle.LoadAsset
("AssetBundleManifest");
//Choose one you want to add
string[] cubedepends = manifest.GetAllDependencies("cubezero");
AssetBundle[] dependsAssetbundle = new AssetBundle[cubedepends.Length];
//Add all childs
for (int index = 0; index < cubedepends.Length; index++)
{
dependsAssetbundle[index] = AssetBundle.CreateFromFile(Application.dataPath
+ "/Assetbundle/" + cubedepends[index]);
}
}
//Instantiate the prefab
AssetBundle cubeBundle = AssetBundle.CreateFromFile(Application.dataPath + "/Assetbundle/cubezero");
GameObject cube = cubeBundle.LoadAsset("Cube0") as GameObject;
if (cube != null)
{
Instantiate(cube);
}
}
}
这样就能把打包好的东西从场景中加载出来了,还是很有意思的,哈哈。
很棒的参考文章 :http://gad.qq.com/college/articledetail/43
- Unity5.0 AssetBundle 实验
- Unity5.0 AssetBundle 学习心得
- unity5.0AssetBundle学习
- unity5.0资源打包AssetBundle
- Unity5 AssetBundle
- unity5 assetbundle参考
- Unity5 AssetBundle管理
- unity5中AssetBundle相关
- Unity5打包assetbundle
- Unity5的AssetBundle
- Unity5 AssetBundle资源管理
- unity5.X AssetBundle
- Unity5.X AssetBundle打包
- Unity5.X AssetBundle加载
- [Unity5.X]AssetBundle总结
- Unity5.4打包AssetBundle
- unity5.X AssetBundle使用(一 )
- unity5.X AssetBundle使用(二 )
- CF 593D LCA,贪心
- LeetCode 026 Remove Duplicates from Sorted Array
- 使用jersey实现应用服务器和图片服务器分离
- libevent代码阅读(7)——“hello-world.c”之 io复用机制的初始化
- 图片上传以及保存
- Unity5.0 AssetBundle 实验
- AFNpost请求上传服务器
- Disruptor介绍(一)
- Struts2 验证码图片生成实例
- DOS HOP舞蹈环境!当公主又见王子,绅士开始跳舞,我们在此相遇!
- java对象篇
- Nagios排错集合
- node.js 相关软件linux安装
- LeetCode House Robber || DP