zoukankan      html  css  js  c++  java
  • Unity3d AssetBundle 资源加载与管理

    设置AssetBundle

    BuildPipeline.BuildAssetBundles(
        outPath, 
        builds.ToArray(), 
        BuildAssetBundleOptions.ChunkBasedCompression, 
        BuildTarget.StandaloneWindows64
        );

    outPath是AssetBundle输出的目录,我们设置为StreamingAssets目录。

    包体内的AssetBundle只能放在StreamingAsstes目录,别的目录是无法读取的。

    加载AssetBundle之前,需要使用AssetBundleManifest提取每个AssetBundle的相互依赖关系。

    string outPath = Path.Combine(Application.dataPath, "StreamingAssets");
    //如果目录已经存在删除它
    if (Directory.Exists(outPath)){
        Directory.Delete(outPath, true);
    }
    Directory.CreateDirectory(outPath);

    builds是AssetBundleBuild类型的泛型集合

    List<AssetBundleBuild> builds = new List<AssetBundleBuild>();

    每个AssetBundle都需要一个AssetBundleBuild类型的实例对象来设置需要打包的文件和打包后的文件名

    builds.Add(new AssetBundleBuild() {
        assetBundleName = "Cube.unity3d",
        assetNames = new string[] {
            "Assets/Cube.prefab",
            "Assets/Cube 2.prefab"
        }
    });
    builds.Add(new AssetBundleBuild() {
        assetBundleName = "NewMaterial.unity3d",
        assetNames = new string[] {
            "Assets/New Material.mat"
        }
    });

    BuildAssetBundleOptions.ChunkBasedCompression是AssetBundle提供的一种压缩格式

    1.LZMA压缩,压缩体积小,但是每次使用都要解压,可能会卡顿,不建议使用。

    2.BuildAssetBundleOptions.UncompressedAssetBundle 不压缩,缺点是构建出来的AssetBundle体积比较大,有点事加载比较快。

    但可以将不被压缩的构建出来后再用第三方压缩算法压缩他上传到CDN,这样下载时还是压缩过的但使用时是不压缩的读取也更快了。

    3.BuildAssetBundleOptions.ChunkBasedCompression LZ4压缩,他是介于二者之间的折中方案,构建后的体积会比不压缩的小一些,加载速度比LZMA快一些,建议使用。

    BuildTarget.StandaloneWindows64是Bundle文件的构建平台。

    每个平台下的Bundle都不一样,需要指定BuildTarget的构建平台。

  • 相关阅读:
    网页常用的小工具--返回顶部
    关于javascript在作用域中的变量定义你所不知道的一些东西
    javascript中的function
    javascript判断非空
    jq实现多banner效果图
    JavaScript对下一个元旦倒计时,经常用于网店限时销售
    oracle 查看锁表情况并处理锁表
    ORACLE中的FTP例子代码
    Oracle包被锁定的原因分析及解决方案
    DOS和批处理基本命令
  • 原文地址:https://www.cnblogs.com/errornull/p/10455565.html
Copyright © 2011-2022 走看看