zoukankan      html  css  js  c++  java
  • Unity AssetBundle的生成、加载和热更新

      当前使用的是unity2018.2.6版本。

      生成AssetBundle

      这个版本生成AssetBundle有两种方式,一种是在资源的Inspector面板下边配置AssetBundle名称,然后调用下面第一种方式打AssetBundle包。第二种方式是使用下面第二个API,在AssetBundleBuild数组中配置资源的路径和AssetBundle名称。

      public static AssetBundleManifest BuildAssetBundles(string outputPath, BuildAssetBundleOptions assetBundleOptions, BuildTargettargetPlatform);

      public static AssetBundleManifest BuildAssetBundles(string outputPath, AssetBundleBuild[] builds, BuildAssetBundleOptions assetBundleOptions,BuildTarget targetPlatform);

      生成AssetBundle时要注意当前Editor的目标平台,不同平台对应生成不同的AssetBundle。

      打完整包时的AssetBundle处理

      将版本配置文件放在StreamingAssets目录中,将生成的AssetBundle资源放在StreamingAssets文件夹下的各个平台对应的文件夹下,跟随完整包一起打出。游戏中从持久目录中加载资源,这种方式灵活性较高,可以方便替换跟随完整包一起打出的那部分AssetBundle资源,重要的是可以使用AssetBundle.LoasAsset()这种加载方式,也是官方推荐的加载方式。

      版本更新

      在启动游戏时检查persistentDataPath目录中是否有版本配置文件,如果没有,则需要将StreamingAssets目录中的版本配置文件和所有的AssetBundle文件拷贝过去。然后下载服务器的版本文件对比。版本号中包含大小版本标识,当大版本不一致时提示到下载完整包,当小版本号不一致增量更新资源服务器上的AssebBundle资源。

      加载StreamingAssets中的资源使用UnityWebRequest,文档推荐的加载方式,https://docs.unity3d.com/ScriptReference/Application-streamingAssetsPath.html

      增量更新:

        1.下载服务器上的AssetBundleManifest文件和本地AssetBundleManifest文件对比,记录HashCode不一致的AssetBundle文件和服务器有本地没有的AssetBundle文件。

        2.下载记录的文件列表中的AssetBundle文件到持久目录。

      资源加载

        1.编辑器中运行时使用AssetDatabase.LoadAssetAtPath加载资源

        2.在移动平台上运行时使用AssetBundle.LoadAsset加载

      github:https://github.com/sunsiwei/UnityHotfixABResource

      

  • 相关阅读:
    sobel
    构造函数
    #pragma once & ifnde
    #pragma comment
    SET容器
    重载[] int& operator[ ]( )
    仿函数 operator()()
    remove_if erase
    vector
    map
  • 原文地址:https://www.cnblogs.com/ssw-men/p/10510512.html
Copyright © 2011-2022 走看看