I am working in unity 2018 Asset Bundle. In my project i have to pack the entire scene inside of an AssetBundle and when i needed, the game will download the AssetBundle from the internet and then it should unpack it.
I have used this code.for loading the scene from assetbundle.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
using System.IO;
using UnityEngine.SceneManagement;
public class AssetBundleSceneLoader : MonoBehaviour
{
public string url;
public int downloaded = 0;
AssetBundle bundle;
public System.Object test;
public Slider progressbar;
public float progress;
WWW www;
void Update()
{
progress = www.progress;
progressbar.value = progress;
}
IEnumerator Start()
{
ClearCacheExample ();
if (downloaded == 0)
{
using ( www = WWW.LoadFromCacheOrDownload (url, 0))
{
yield return www;
if (www.error != null)
throw new Exception ("WWW download had an error:" + www.error);
if (www.error == null)
{
bundle = www.assetBundle;
}
}
if (Caching.ready == true)
{
downloaded = 1;
string[] scenePath = bundle.GetAllScenePaths();
Debug.Log(scenePath[0]);
SceneManager.LoadScene(scenePath[0]);
}
}
}
void ClearCacheExample()
{
Directory.CreateDirectory("Cache1");
Directory.CreateDirectory("Cache2");
Directory.CreateDirectory("Cache3");
Caching.AddCache("Cache1");
Caching.AddCache("Cache2");
Caching.AddCache("Cache3");
bool success = Caching.ClearCache();
if (!success)
{
Debug.Log("Unable to clear cache");
}
}
}
I have packed my scene and put it in Dropbox. It is downloaded from the internet. The scene is loading fine. I have faced some problems here:
Not the entire screen is loading. The screen reduces to a quarter of its size and then it is playing.
What's wrong in my code? Is there any separate procedure available for loading scene from asset bundle...?
How can I load from a scene from an asset bundle? Is there any sample project available?
.
in the file name (not including the.scene
) then there is a known bug that was fixed in 2018.3.4 – Draco18s no longer trusts SE