Hi all!
This is my very first post in this forum. I am a beginner level programmer so i think i need so help from someone I have been trying to merge code for loading an AssetBundle from server with a AsyncOperation loader but after scratching my head for a long time this is the best i came up with but for some reason the loader takes ages to come up and load the scene… any ideas or improvements to my code?
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using System.Collections;
public class AssetBundleLoader : MonoBehaviour
{
public GameObject loaderCounter;
public GameObject internetChecker;
public Slider slider;
public Text percentagem;
public string cenaID;
public void Iniciar()
{
StartCoroutine (EnviarRequest ());
}
IEnumerator EnviarRequest()
{
using (UnityWebRequest request = UnityWebRequest.GetAssetBundle ("http://www.dimensao-digital.com/Unity/PublicidadeDigital/Android/CartazCinema/" + cenaID))
{
yield return request.SendWebRequest ();
if (request.isNetworkError || request.isHttpError )
{
internetChecker.gameObject.SetActive (true);
Debug.Log (request.error);
}
else
{
Debug.Log ("aqui?");
loaderCounter.gameObject.SetActive (true);
AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(request);
StartCoroutine (CenaLoader());
}
}
}
IEnumerator CenaLoader()
{
AsyncOperation operacao = SceneManager.LoadSceneAsync (cenaID);
while (!operacao.isDone)
{
float progress = Mathf.Clamp01 (operacao.progress / .9f);
slider.value = progress;
percentagem.text = progress * 100 + "%";
Debug.Log (percentagem.text);
yield return null;
}
}
}