针对Unity资源包-AssetBundle格式简单且容易破解的问题,Unity中国团队推出了Unity AssetBundle 加密方案
BuildPipeline.SetAssetBundleEncryptKey("0123456789abcdef");
BuildPipeline.BuildAssetBundles(assetbundleBuildPath, BuildAssetBundleOptions.ChunkBasedCompression | BuildAssetBundleOptions.EnableProtection, EditorUserBuildSettings.activeBuildTarget);
BuildPipeline.SetAssetBundleEncryptKey(null);
加载AssetBundle时,先指定本次加载所使用的解密秘钥。
AssetBundle.SetAssetBundleDecryptKey(rightUserKey);
AssetBundle assetBundle = AssetBundle.LoadFromFile(GetAssetBundleFullPath());
AssetBundle.SetAssetBundleDecryptKey(null);
public Sprite LoadSprite(string _atlasName,string _spriteName) { SpriteAtlas m_spriteAtlas = Resources.Load<SpriteAtlas>(_atlasName); tempSprite = m_spriteAtlas.GetSprite(_spriteName); return tempSprite; }