先说第一种方法
首先:标记资源(AssetBoudle名称,如xx.ab )
创建以下代码,放入“Asset—Editor”路径中 注意如果不放在Editor文件夹下是不行的,目前我用的2019.3
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
public class CreateAssetBunldesMain : MonoBehaviour
{
[MenuItem("AssetsBoundle/Build AssetBoudles")]
static void BuildAllAssetBoundles()
{
string strDir = Application.streamingAssetsPath;
if (Directory.Exists(strDir) == false)
{
Directory.CreateDirectory(strDir);
}
if (BuildPipeline.BuildAssetBundles(strDir, BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.WebGL))
{
Debug.LogWarning("打包成功");
// 刷新编辑器
AssetDatabase.Refresh();
}
else
{
Debug.LogWarning("打包失败");
}
}
}
打包格式的一些选项
BuildAssetBundleOptions:资源包编译选项
None:空
UncompressedAssetBundle :不压缩AB包,会导致AB包很大,但是加载和打包过程会很快
CollectDependencies :包含依赖关系
CompleteAssets :强制打包全部资源
DisableWriteTypeTree :不包含类型信息
DeterministicAssetBundle :使其拥有一个唯一的hash id
ForceRebuildAssetBundle :强制重新打包
IgnoreTypeTreeChanges :忽略TypeTree变化
AppendHashToAssetBundleName :附加hashid到AB名中
ChunkBasedCompression :使用Lz4格式压缩
StrictMode :严谨模式,出现任何差错都不会打包成功
DisableLoadAssetByFileName :不适用文件名来加载
我们会发现资源视图多了一个文件夹,我们创建的文件就在里面,test.cube就是我们的AB主文件,那么manifest是什么呢?
我们可以用记事本打开:
然后读取。。。
可以参考另外两篇帖子非常不错