【问题标题】:After downloading file .obb not find the next scene下载文件 .obb 后找不到下一个场景
【发布时间】:2015-06-07 20:57:18
【问题描述】:

我正在 Unity3D 中制作应用程序,但文件 .obb 有问题。从我的保管箱下载文件 .obb 后,尝试打开下一个场景并告诉我找不到它。如果我关闭应用程序并返回打开功能正常。可以是什么?

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))
        {
            // After downloading the file if you close the game and you become open, OK ¿?
            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);
        // Here says that there is the scene
        Application.LoadLevel(nextScene);
    }
}
}    

我尝试在开发者控制台中将 apk 和 obb 作为 alpha 版本上传,但是当我去下载 .obb 时告诉我: "下载失败,因为找不到资源"

谢谢。

【问题讨论】:

  • 不要使用统一标签,因为它不是你想要的。

标签: android unity3d unityscript


【解决方案1】:

我按照this 教程将我的 Unity 应用程序拆分为 *.obb 文件。对我帮助很大。

现在,当我在 GooglePlay 中作为 Alpha 版本执行测试时,一切正常,下载了 obb 文件和应用程序中的进程,但它没有加载我的第一个场景。

我花了很多时间才注意到,当我将加载器作为场景 0 时,我加载下一个场景的索引是错误的。我知道这是一个糟糕的错误,但这就是我 10 小时研究背后的历史。

希望你会发现有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多