How to download a Scene and Save it on SD Card and Load it
I have been searching for AssetBundles what I understood is that it only Loads the scenes at runtime by saving it into Cache. And it is not saved on Device. So it means every time a user has to play the level the scene will be downloaded first. Is there a way to use Assetbundles to store downloaded content on Device and use it next time without downloading it again next time?
I have total 30 Scenes which is already not a good approach but the game is already designed. The size is too much. I am looking for a solution which reduces the apk size for example only 10 scenes are added into the build setting. And the other 20 will be loaded when user has cleared 10 levels. And I want them to be downloaded once not every time.
Please help.
Thanks
Answer by aryaman1994 · Jun 06, 2016 at 11:25 AM
Use WWW.LoadFromCacheOrDownload to download your Asset Bundle. Save your scene to an Asset Bundle. When you download this Asset Bundle using LoadFromCacheOrDownload, the downloaded Bundle will be stored to the cache of the app (which is in the SD Card). It can then be loaded from there using hte same LoadFromCacheOrDownload function. More about it here http://docs.unity3d.com/ScriptReference/WWW.LoadFromCacheOrDownload.html
Answer by tej-pratap · May 18, 2017 at 11:01 AM
private IEnumerator downloadScene(string urlString) { String path = Application.persistentDataPath + "/" + Path.GetFileName(urlString); WWW www = new WWW(urlString); while (!www.isDone) { yield return null; } if (File.Exists(path)) {
File.Delete(path); } FileStream stream = File.Create(path); stream.Write(www.bytes, 0, www.bytes.Length); stream.Close(); }
Your answer
Follow this Question
Related Questions
How to reduce initial build size for Android 0 Answers
Unity not loading scene asset bundles properly 0 Answers
APK file size too big! 1 Answer
Why are the Levels (editor log) from build size so big 60.6% ? 2 Answers
Why apk size is so large? 0 Answers