理论不多说,网上,官方文档都有。  这里有一篇介绍很全面的文章:https://www.cnblogs.com/ybgame/p/3973177.html

示例和注意点记录一下,用到时以便查阅。

 

一、打包代码(Editor)

我所知道的,有两种打包方法:1、所有打包参数在代码里设置,完全代码控制;2、在编辑器中设置打包参数,代码简便

第一种:

在代码中指定bundle包名,指定包含在该bundle里的所有资源路径

 1 [MenuItem("AssetsBundle/Build Bundle -- 代码中设置参数")]
 2     static void BuildAB()
 3     {
 4         string path = Application.streamingAssetsPath + "/AssetsBundles/";
 5 
 6         if (Directory.Exists(path))
 7             Directory.Delete(path, true);
 8         Directory.CreateDirectory(path);
 9 
10         AssetBundleBuild[] buildMap = new AssetBundleBuild[2];
11 
12         //指定bundle包名
13         buildMap[0].assetBundleName = "prefab_bundle";
14 
15         string[] assets = new string[2];
16         assets[0] = "Assets/AssetsBundleObj/Cube.prefab"; // 必须是完整的文件名(包括后缀)
17         assets[1] = "Assets/AssetsBundleObj/Sphere.prefab";
18         //指定bundle包含的资源路径数组
19         buildMap[0].assetNames = assets;
20 
21         buildMap[1].assetBundleName = "scene_bundle";
22         string[] scenes = new string[1];
23         scenes[0] = "Assets/_Scenes/Scene.unity";
24         buildMap[1].assetNames = scenes;
25 
26         BuildPipeline.BuildAssetBundles(path, buildMap, BuildAssetBundleOptions.DeterministicAssetBundle, BuildTarget.StandaloneWindows);
27     }
代码中设置参数

相关文章:

  • 2021-06-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-30
  • 2021-05-25
  • 2021-11-26
  • 2021-04-02
  • 2022-12-23
猜你喜欢
  • 2021-11-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-02
  • 2021-07-30
相关资源
相似解决方案