Noticias

¡RECUERDA QUE SI ERES UN NUEVO USUARIO, DEBES PRESENTARTE PARA PODER PUBLICAR MENSAJES! | TENEMOS CANAL OFICIAL DE TELEGRAM: t.me/unity3dspain

Escena no encontrada después de descargar archivo .obb

Iniciado por breakheart, Junio 07, 2015, 08:54:33 PM

Tema anterior - Siguiente tema
Junio 07, 2015, 08:54:33 PM Ultima modificación: Enero 01, 1970, 01:00:00 AM por breakheart
Buenas,
 
Después de descargar el archivo .obb al llamar a la siguiente escena me dice que no la encuentra, pero si una vez descargado el .obb cierras el juego y lo vuelvo abrir si funciona. ¿Qué puede ser?

using UnityEngine;
using System.Collections;
using System.IO;
using System;
using UnityEngine.UI;
public class DownloadFile : MonoBehaviour {
 
    private string path;
    private string url = "";
    private float m_CurrentValue = 0;
 
    public GameObject btnStart;
    private string nextScene = "Splash";
 
    void log( string t )
    {
        print("MYLOG " + t);
    }
 
    // Use this for initialization
    void Start ()
    {
        CheckObb ();
    }
 
    // Update is called once per frame
    void Update () {
    }
 
    void CheckObb()
    {
     
        if (!GooglePlayDownloader.RunningOnAndroid())
        {
            log ( "Use GooglePlayDownloader only on Android device!");
            return;
        }
     
        string expPath = GooglePlayDownloader.GetExpansionFilePath();
     
        if (expPath == null)
        {
            log("External storage is not available!");
        }
        else
        {
            string package = GooglePlayDownloader.Package();
            int version = GooglePlayDownloader.Version();
         
            path = String.Format("{0}/main.{1}.{2}.obb", expPath, version, package);
            url = String.Format("https://www.dropbox.com/s/xxxxxxxxxxxxxx/main.{0}.{1}.obb?dl=1", version, package);
         
            if (File.Exists(path))
            {
                // Carga la escena correctamente
                Application.LoadLevel(nextScene);
            }
            else
            {
                //check if directory doesn't exit
                if(!Directory.Exists(expPath))
                {
                    //if it doesn't, create it
                    Directory.CreateDirectory(expPath);
                }
                btnStart.SetActive(true);
            }
        }
    }
    // Click Start button download obb
    public void ClickStart()
    {
        btnStart.SetActive(false);
        StartCoroutine(DownloadObb());
    }
    // Download obb
    IEnumerator DownloadObb() {
        WWW download = new WWW(url);
        while( !download.isDone ) {
            m_CurrentValue = download.progress * 100;
            yield return null;
        }
        if (!string.IsNullOrEmpty(download.error)) {
            //Error
        } else
        {
            // success!
            File.WriteAllBytes (path, download.bytes);
            // Da error porqué no encuentra la escena
            Application.LoadLevel(nextScene);
        }
    }
}

Saludos.

Etiquetas: