我在Unity3D中创建一个应用程序,我对.obb文件有疑问。从我的Dropbox下载文件.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告诉我这个: "下载失败,因为无法找到资源"
感谢。
答案 0 :(得分:0)
我按照this教程将Unity应用分成* .obb文件。它对我帮助很大。
现在,当我在GooglePlay中作为Alpha版本进行测试时,一切正常,在应用程序中下载obb文件和进程,但它不会加载我的第一个场景。
我花了很多时间注意到当我将加载器作为场景0时,我的索引加载下一个场景是错误的。我知道这是一个糟糕的错误,但这是我10个小时研究背后的历史。
希望你会觉得有用。