闪电下载吧 最新软件 免费软件 绿色软件

教程资讯 软件专题

您的位置:SD124 > 网络资源 > 软件教程 > Unity Asset Bundle 2/3/4/5 October 2019 最新版 含加载方法

Unity Asset Bundle 2/3/4/5 October 2019 最新版 含加载方法

软件教程 发布日期:2019-10-15  浏览: 次 网友评论
AssetBundles是由 Unity 编辑器在编辑环境中(enit-time)创建的一些列的文件,这些文件可以被用在项目的运行环境中(run-time)。 AssetBundles 可以包括的资源文件有模型文件(models)、材质(materials)、纹理(textures)和场景(scenes)。AssetBundles 不能包含脚本文件。具体来说,一个 AssetBundle 就是把一系列的资源文件或者场景文件以某种方式紧密保存的一个文件。这个 AssetBundle 文件可以被单独加载到可执行的应用程序中。AssetBundles 可以由被 Unity 构建的游戏或者应用按需加载使用。这允许对像模型、纹理、音频、甚至是整个的游戏场景这样的资源进行流式加载和异步加载。AssetBundles 可以预缓存(pre-cached)和存储在本地,这样在运行时就可以立即加载它们。但是 AssetBundles 技术的主要的目的是在需要的时候能够从远端的服务器上按需请求特定的资源,并加载到游戏中。AssetBundles 可以包含 Unity 可以识别的任何类型的资源,包括自定义的二进制数据。唯一的例外是,脚本资源是不被允许的。

什么是AssetBundle  

估计很多人只知道Unity的模型之类的东西可以导出成一种叫做AssetBundle的文件,然后打包后可以在Unity程序运行的时候再加载回来用。  
那么AssetBundle是一个什么样的东西呢?其实AssetBundle只是一种使用LZMA压缩方式压缩的资源文件。具体LZMA是什么请百度,你可以理解成就是一种压缩文件就行了,至于它的后缀名是什么,一点关系都没有,你可以自己定。  
AssetBundle打包的时候,你可以指定一个mainAsset,那么加载完之后就可以通过AssetBundle.mainAsset来获取到了。你也可以不指定mainAsset,直接打包一堆内容进去,然后加载后通过AssetBundle.LoadAsset指定名字的读取出来。  
在资源之间,存在着依赖的关系。你可以把资源拆分得很细,比如一个模型,由网格模型、材质、贴图构成,你可以把每一个小部分都拆开,各自打包成压缩文件。当Unity需要加载使用的时候,把该模型的所有依赖的小资源都加载起来,然后根据依赖关系组装,就变回了我们看到的资源了。

详细内容

Includes:

All Settings Pro v1.0.5.unitypackage
Blend Modes v3.4.unitypackage
Crosshair Assembler 1.1.0.unitypackage
DDA Fog 1.02.unitypackage
Distortion Shader Pack 1.3.unitypackage
Exploder 1.7.8.unitypackage
Fantasy Skybox.unitypackage
Lyme 1.0.unitypackage
Mobile City Pack 1.1.unitypackage
Mobile City Pack 1.2.unitypackage
Stylized Forest 1.2.unitypackage
Toon Soldiers v2.0.unitypackage
UniStorm – Dynamic Modular Weather v3.0.1.1.unitypackage
Vistas v3.0.unitypackage
Vistas v4.0.unitypackage
Volumetric Light Beam v1.60.unitypackage
Pixel Platformer Engine – Responsive 2d Platformer Toolkit 1.1.zip
Stylized Low-Poly Nature _et v2.0.zip
Universal WebGL Template 1.2.1.zip

加载方法

大致经历以下过程  
WWW  
AssetBundle  
Asset  
WWW  
加载:通过url加载  
内存大小:  
压缩资源:翻倍(为什么会得出翻倍?)  
非压缩:几乎相同  
内存对象:WebStream  
AssetBundle  
加载:随着WWW加载,第一次访问的时候会在内存生成一个SerializeFile,内存也会跟着增加0.4M左右(这个0.4M是什么?)  
内存大小:在WWW的基础上增加0.4M(非固定)  
内存对象:SerializeFile(archive/Cab-XXXX)  
Asset  
加载:AssetBundle.LoadAsset  
相关的脚本,shader,Asset,Transform,GameObject都会被加载进来,存放在内存的Asset下  
大小:完整大小,(会对相关的资源进行一次解压)

Unity加载AssetBundle的方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using UnityEngine.Networking;
 
public class DownLoad : MonoBehaviour
{
    IEnumerator Start()
    {
        //资源包路径
        string path1 = "AssetBundles/cubewall.unity3d";
        //共享依赖资源包路径
        string path2 = "AssetBundles/share.unity3d";
 
        //第一种加载AB的方式 ,从内存中加载 LoadFromMemory
 
        #region
 
        //方法一:异步加载
        //加载资源
        AssetBundleCreateRequest request = AssetBundle.LoadFromMemoryAsync(File.ReadAllBytes(path1));
        yield return request;
        //加载共同依赖资源,如贴图、材质
        AssetBundleCreateRequest request2 = AssetBundle.LoadFromMemoryAsync(File.ReadAllBytes(path2));
        yield return request2;
        AssetBundle ab = request.assetBundle;
        AssetBundle ab2 = request2.assetBundle;
 
        //使用里面的资源
        GameObject wallPrefab1 = (GameObject) ab.LoadAsset("CubeWall");
        Instantiate(wallPrefab1);
 
        //方法二:同步加载(无需用协程)
        //加载资源
        AssetBundle ab3 = AssetBundle.LoadFromMemory(File.ReadAllBytes(path1));
        //加载共同依赖资源,如贴图、材质
        AssetBundle ab4 = AssetBundle.LoadFromMemory(File.ReadAllBytes(path2));
 
        //使用里面的资源
        GameObject wallPrefab2 = (GameObject) ab.LoadAsset("CubeWall");
        Instantiate(wallPrefab2);
 
        #endregion
 
 
        //第二种加载AB的方式 ,从本地加载 LoadFromFile(无需用协程)
 
        #region
 
        AssetBundle ab5 = AssetBundle.LoadFromFile(path1);
        AssetBundle ab6 = AssetBundle.LoadFromFile(path2);
 
        GameObject wallPrefab3 = (GameObject) ab5.LoadAsset("CubeWall");
        Instantiate(wallPrefab3);
 
        #endregion
 
        //第三种加载AB的方式 ,从本地或服务器加载 WWW(将被弃用)
 
        #region
 
        //是否准备好
        while (Caching.ready == false)
        {
            yield return null;
        }
        //从本地加载
        //WWW www = WWW.LoadFromCacheOrDownload(@"file:/E:AssetBundleProject\AssetBundleProject\AssetBundles", 1);
        //从服务器加载
        WWW www = WWW.LoadFromCacheOrDownload(@"http://localhost/AssetBundles/cubewall.unity3d", 1);
        yield return www;
        //是否报错
        if (string.IsNullOrEmpty(www.error) == false)
        {
            Debug.Log(www.error);
            yield break;
        }
        AssetBundle ab7 = www.assetBundle;
 
        //使用里面的资源
        GameObject wallPrefab4 = (GameObject) ab7.LoadAsset("CubeWall");
        Instantiate(wallPrefab4);
 
        #endregion
 
        //第四种加载AB方式 从服务器端下载 UnityWebRequest(新版Unity使用)
 
        #region
 
        //服务器路径 localhost为IP
        string uri = @"http://localhost/AssetBundles/cubewall.unity3d";
        UnityWebRequest request3 = UnityWebRequest.GetAssetBundle(uri);
        yield return request3.Send();
 
        //AssetBundle ab8 = ((DownloadHandlerAssetBundle)request3.downloadHandler).assetBundle;
        AssetBundle ab8 = DownloadHandlerAssetBundle.GetContent(request3);
 
        //使用里面的资源
        GameObject wallPrefab5 = (GameObject) ab8.LoadAsset("CubeWall");
        Instantiate(wallPrefab5);
 
        //加载cubewall.unity3d资源包所依赖的资源包
        AssetBundle manifestAB = AssetBundle.LoadFromFile("AssetBundles/AssetBundles");
        AssetBundleManifest manifest = (AssetBundleManifest) manifestAB.LoadAsset("AssetBundleManifest");
 
        //foreach(string name in manifest.GetAllAssetBundles())
        //{
        //    print(name);
        //}
 
        //cubewall.unity3d资源包所依赖的资源包的名字
        string[] strs = manifest.GetAllDependencies("cubewall.unity3d");
        foreach (string name in strs)
        {
            AssetBundle.LoadFromFile("AssetBundles/" + name);
        }
 
        #endregion
    }
}

Unity Asset Bundle 2 – October
链接: https://pan.baidu.com/s/1OQS1DlDBtreCAA4nBOpWeA 提取码: mnqh

Unity Asset Bundle 3 – September 2019
链接: https://pan.baidu.com/s/1ApZkx25phnT96DPtug4WWQ 提取码: q7qj
Unity Asset Bundle 4 – May 2019
链接: https://pan.baidu.com/s/1Jigr5xPRDVFMAZXFeOqfpw 提取码: 1n4s
解压密码 -0daydown

Unity Asset Bundle 5 – July 2019

链接: https://pan.baidu.com/s/1OTIM1iEn8dGy1BsWN9d7eg 提取码: iavc

本文地址:http://www.sd124.com/article/2018/0615/223677.html
《Unity Asset Bundle 2/3/4/5 October 2019 最新版 含加载方法》由闪电下载吧整理并发布,欢迎转载!

  • 相关文章:
  • 相关软件:
本周热点
本月热点
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图 - 网站标签
有任何意见或者建议请联系邮箱:858898909[at]qq.com 本站部分内容收集于互联网,如果有侵权内容、不妥之处,请联系我们删除。敬请谅解!
Copyright © 2012 SDBETA.com. All Rights Reserved 豫ICP备12021367号 豫公网安备 41019702002546号闪电下载吧