Notifications
Article
Unity增强版功能:AssetBundle加密说明文档
Updated 19 days ago
311
0
Unity增强版功能:AssetBundle加密说明
针对Unity资源包-AssetBundle格式简单且容易破解的问题,Unity中国团队推出了Unity AssetBundle 加密方案。
目前AssetBundle加密需要AssetBundle为LZ4压缩格式。后续会推出支持lzma和非压缩格式的加密。

构建AssetBundle:

构建AssetBundle时,先指定本次build所使用的加密秘钥。
注意,秘钥长度为16位字符(128bit):
BuildPipeline.SetAssetBundleEncryptKey("0123456789abcdef");
然后指定BuildAssetBundleOptions包含:ChunkBasedCompression 和 EnableProtection即可:
BuildPipeline.BuildAssetBundles(assetbundleBuildPath, BuildAssetBundleOptions.ChunkBasedCompression | BuildAssetBundleOptions.EnableProtection, EditorUserBuildSettings.activeBuildTarget);

通过指定秘钥为null来清除秘钥:

BuildPipeline.SetAssetBundleEncryptKey(null);

加载AssetBundle:

加载AssetBundle时,先指定本次加载所使用的解密秘钥。
AssetBundle.SetAssetBundleDecryptKey(rightUserKey);
然后加载AssetBundle即可:
AssetBundle assetBundle = AssetBundle.LoadFromFile(GetAssetBundleFullPath());
通过指定秘钥为null来清楚秘钥:
AssetBundle.SetAssetBundleDecryptKey(null);
Tags:
杨栋(Richard Yang)
Unity China Evangelist Lead / Product Manager - Manager
8
Comments