- Home /
loading assetbundle offline
I am checking assetbundle example here; https://unity3d.com/learn/tutorials/topics/scripting/assetbundles-and-assetbundle-manager
In the assets bundle manager it is listed;
if (isLoadingAssetBundleManifest)
download = new WWW(url);
else
download = WWW.LoadFromCacheOrDownload(url, m_AssetBundleManifest.GetAssetBundleHash(assetBundleName), 0);
If we are downloading the assets for the first time downloading the manifest from the web make sense.
Suppose we download the content for the first time, then we don't have to go online to get the content. If the player is offline how to we download the manifest?
How to handle a situation like this?
Player download the content by going online. Then he turn off internet connection. If we start the game the manifest does not get loaded?
Suppose I am aware when the player suppose to go online is there a way to say get the bundleassets offline or from where it get saved ?
Best I can think of is that after you load the asset bundles you save them locally (Depending on your platform there are suggested folders to save data to. Or you may be able to use the application folder.).
But every time you go to load your asset bundle data you check if the files exist at the local directory first and then call WWW.Load from either the local or the web url as appropriate. For the url in WWW.Load you can use a local address and it will still work (ie. WWW.Load("C:\$$anonymous$$yGame\CachedData\assetbundle.asset"); on windows.).
This way you are not relying on Unity's cache too heavily and after the first launch the data will exist locally so the user doesn't need to be online. If this sounds good to you let me know and I'll mark this as an answer :)
I didn't realized it is possible to save objects like that.
Suppose I download a prefab from the assets bundle.
Is it possible to save it to a location on a Android device?
Yes it is. The main thing you need to do is make sure you write to an accessible location. I think Application.persistentDataPath will give you an appropriate path.
Look at this question, http://answers.unity3d.com/questions/539339/saving-data-in-to-files-android.html. This person is saving a .txt file but if you use File.WriteAllBytes you should be able to save the bytes field of your asset bundle.
Does that all make sense?
Answer by Brian-FJ · Sep 06, 2016 at 02:29 PM
Best I can think of is that after you load the asset bundles you save them locally (Depending on your platform there are suggested folders to save data to. Or you may be able to use the application folder.).
But every time you go to load your asset bundle data you check if the files exist at the local directory first and then call WWW.Load from either the local or the web url as appropriate. For the url in WWW.Load you can use a local address and it will still work (ie. WWW.Load("C:\MyGame\CachedData\assetbundle.asset"); on windows.).
This way you are not relying on Unity's cache too heavily and after the first launch the data will exist locally so the user doesn't need to be online.
Your answer
Follow this Question
Related Questions
How to import the object from server to unity 2 Answers
Whats the difference between an Object and A GameObject? 2 Answers
How to load Assets as GameObjects? 1 Answer
Object parent Asset Bundle 1 Answer
Streaming scenes in assetbundles 1 Answer