string url = "http://www.mywebsite.com/mygame/assetbundles/assetbundle1.unity3d";
IEnumerator Start () {
// Start a download of the encrypted assetbundle
WWW www = new WWW (url);
// Wait for download to complete
yield return www;
// Get the byte data
byte[] encryptedData = www.bytes;
// Decrypt the AssetBundle data
byte[] decryptedData = YourDecryptionMethod(encryptedData);
// Create an AssetBundle from the bytes array
AssetBundle bundle = AssetBundle.CreateFromMemory(decryptedData);
// You can now use your AssetBundle
}
But it generates this error “CS0029: Cannot implicitly convert type UnityEngine.AssetBundleCreateRequest' to UnityEngine.AssetBundle’”
I would like to use this method to encrypt my asset bundle. I realy hope someone could point some light here…
That’s pretty cool, I didn’t even know that existed!
Looks like the doc example has a typo, though. If you check out the Scripting section of the manual, CreateFromMemory is asynchronous and actually returns an AssetBundleCreateRequest that you can yield on, then load the .assetBundle property.
string url = "http://www.mywebsite.com/mygame/assetbundles/assetbundle1.unity3d";
IEnumerator Start () {
// Start a download of the encrypted assetbundle
WWW www = new WWW (url);
// Wait for download to complete
yield return www;
// Get the byte data
byte[] encryptedData = www.bytes;
// Decrypt the AssetBundle data
byte[] decryptedData = YourDecryptionMethod(encryptedData);
// Create an AssetBundle from the bytes array
AssetBundleCreateRequest acr = AssetBundle.CreateFromMemory(decryptedData);
while (!acr.isDone)
{
yield;
}
AssetBundle bundle = acr.assetBundle;
// You can now use your AssetBundle
}