zoukankan      html  css  js  c++  java
  • Unity5-ABSystem(一):AssetBundle原理

    转载自:http://blog.csdn.net/lodypig/article/details/51863683

    说明

    本系列所使用unity版本为5.3.4f1。


    AssetBundle简介

      AssetBundle是Unity Pro提供和推荐的资源导出方式,它可以把多个自定义的游戏对象或者资源以二进制形式保存到Assetbundle文件中。Assetbundle支持所有unity可识别的格式:模型、贴图、音频、整个场景等,其中最为方便的是可以将关联的内容制作成一个prefab,例如一个模型的贴图、动作和模型等,然后将整个prefab导出到AssetBundle,即可保留prefab中资源和脚本之间相互关联。

    AssetBundle


    AssetBundle内部格式

    • 以下图来自官网,黑体为翻译。

        一个AssetBundle本质上是将一些对象组合成一个序列化文件,根据是普通bundle(normal bundle)还是场景bundle(scene bundle),Assetbundle可以展开成略有不同的数据文件。

    normal bundle

     normal bundle

    scene bundle

     scene bundle

     后面会详细讲到其内部格式,现在可以看到,普通的AssetBundle包含了本身信息(Assetbundle)、各个对象和音频文件,而场景Assetbundle还包含了预加载数据(PreloadData)、shaderData和全局光照数据(Global Illumination Data)。


    压缩

     the ArchiveFileSystem container structure 
      AssetBundle可以选择是否压缩,Unity5.3之前只能使用LZMA压缩,Unity5.3之后支持选择LZ4压缩。 
      图中压缩部分显示了可能有块压缩(chunk-based)和流压缩(stream-based)两种方式。块压缩(LZ4)指的是原始数据被分成大小相同的子块并单独压缩。如果你想要实时解压/随机读取开销小,则应该使用这种。而流压缩(LZMA)在处理整个数据块时使用同一个字典,它提供了最大可能的压缩率但只支持顺序读取。 

      LZMA压缩方式的优点在于AssetBundle压缩率较高,但只能顺序读取意味着加载任意一个资源时,都需要将整个AssetBundle解压,造成卡顿和额外内存占用。LZ4压缩率较低(测试LZMA换LZ4:86.9M -> 108M),但不需要全部解压即可读取,不会有大的卡顿和额外内存占用。后面会详细对比两种压缩方式。


    AssetBundle内部格式

    这里有一篇Unity3D asset bundle 格式简析,分析了unity3.5下Assetbundle的内部格式,总结下来结构如下:

    • AssetBundleFileHead : 记录了版本、是否压缩等主要描述信息。
    • AssetFileHeader :包含一个文件列表,记录了每个资源的name,offset,length等。
    • Asset1 : 第一个资源本身,内部结构如下 
      • AssetHeader :包含了TypeTree大小、文件大小、format等。
      • TypeTree(可选):记录了asset 对象的class id,在 Unity3d 的官方文档 可以查到每个id的对象。
      • ObjectPath :主要记录了一个pathID(资源唯一索引id)。
      • AssetRef:记录了AssetBundle对外部资源的引用情况。
    • Asset2 :第二个资源,结构跟上面一样
    • ……> : 更多资源

      大致符合官网上normal bundle的内容,看来Unity在方面变动不大,文中也提到了分析方式是阅读disunity源码,而disunity也已经支持了unity5,有兴趣也可以分析unity5中Assetbundle的内部结构。

     
  • 相关阅读:
    买房的贷款时间是否是越长越好?https://www.zhihu.com/question/20842791
    asp.net cookie and session
    leelazero and google colab
    download file by python in google colab
    physical processor, core, logical processor
    通过powershell操作eventlog
    openxml in sql server
    get the page name from url
    How to Execute Page_Load() in Page's Base Class?
    Difference between HttpContext.Request and Request
  • 原文地址:https://www.cnblogs.com/yptianma/p/11775986.html
Copyright © 2011-2022 走看看