Is there a way to get an AssetBundle from a server and download the contents to a directory?
Hello,
There are a lot of answers about DLCs and downloading AssetBundles but all the ones I've seen are with the WWW.LoadFromCacheOrDownload(url, 0)
which is obsolete now.
I was wondering how to write assets to a directory using UnityWebRequest. I can get the file from a server and even get AudioClips from the bundle into a list. I just need to write to a directory in the unity project so the user doesn't need to connect to the internet to use the bundles every time.
I have seen a couple of answers that talked about AudioClip.GetData(samples,0);
but the File.WriteAllBytes()
takes a byte array
Thank you in advance!
Answer by mikeburns · Aug 24, 2019 at 05:54 AM
check out Application.persistentDataPath. What I do is save a settings file (JSON) there that I can update. When the game starts, I check the settings file to see what AssetBundles are downloaded. I also have a web service set up so I can send information to the server and get back information like "how many more new AssetBundles can I download?" or "should I update my existing AssetBundles?". The AssetBundles are also saved at Application.persistentDataPath, so then you can always just load from there.
Also, I believe the WWW class is deprecated - oh, yeah, you mentioned that. For downloading from a server, I use UnityWebRequest. For loading locally-downloaded AssetBundles, I use AssetBundle.LoadFromFile.
Hope that helps.
That is exactly what I need thank you. I hadn't thought of using a JSON file for showing what bundles were already downloaded. I was using Directory.GetFiles() and it was pretty messy.