无法从 Vuforia 7.04 v 中的 obb 加载数据集

Can't load data-set from obb in Vuforia 7.04 v

我正在使用 unity 2017.03 与 Vuforia 7.04 V 一起工作。

我的问题是我的 apk 大小超过 120mb,所以我不得不尝试拆分二进制文件并将其上传到 google 游戏商店。

拆分前应用程序运行良好,但拆分后它无法正常工作,除了 AR 场景都可以正常工作。

在移动设备上测试控制台时出现此错误:

fail to load dataset /storage/emulated0/Android/data/com.xyz.game/files/QCAR/dbname.xml

在 google 搜索后我得到了这个代码

private IEnumerator ExtractObbDatasets () {
    string[] filesInOBB = {"FriendsJungle_DB.dat", "FriendsJungle_DB.xml"};
    foreach (var filename in filesInOBB) {
        string uri = Application.streamingAssetsPath + "/QCAR/" + filename;

        string outputFilePath = Application.persistentDataPath + "/QCAR/" + filename;
        if(!Directory.Exists(Path.GetDirectoryName(outputFilePath)))
            Directory.CreateDirectory(Path.GetDirectoryName(outputFilePath));

        var www = new WWW(uri);
        yield return www;

        Save(www, outputFilePath);
        yield return new WaitForEndOfFrame();
    }

    // When done extracting the datasets, Start Vuforia AR scene
    SceneManager.LoadScene("Home"); 

}

private void Save(WWW www, string outputPath) {
    File.WriteAllBytes(outputPath,www.bytes);

    // Verify that the File has been actually stored
    if(File.Exists(outputPath))
        Debug.Log("File successfully saved at: " + outputPath);
    else
        Debug.Log("Failure!! - File does not exist at: " + outputPath);
}

但是运气不好,还是报同样的错误。

请有人帮助我!

我正在使用 this 作为参考

经过长时间的搜索和调试,我找到了解决这个问题的方法。以下是解决此问题的代码和步骤:

public class ARFix : MonoBehaviour {
private string nextScene = "QRScaner";

private bool obbisok = false;
private bool loading = false;
private bool replacefiles = false; //true if you wish to over copy each time

private string[] paths ={
    "Vuforia/FriendsJungle_DB.dat",
    "Vuforia/FriendsJungle_DB.xml",
};

void Update()
{
    if (Application.platform == RuntimePlatform.Android)
    {
        if (Application.dataPath.Contains(".obb") && !obbisok)
        {
            StartCoroutine(CheckSetUp());
            obbisok = true;
        }
    }
    else
    {
        if (!loading)
        {
            StartApp();
        }
    }
}


public void StartApp()
{
    loading = true;
    SceneManager.LoadScene(nextScene);
}

public IEnumerator CheckSetUp()
{
    //Check and install!
    for (int i = 0; i < paths.Length; ++i)
    {
        yield return StartCoroutine(PullStreamingAssetFromObb(paths[i]));
    }
    yield return new WaitForSeconds(3f);
    StartApp();
}

//Alternatively with movie files these could be extracted on demand and destroyed or written over
//saving device storage space, but creating a small wait time.
public IEnumerator PullStreamingAssetFromObb(string sapath)
{
    if (!File.Exists(Application.persistentDataPath + sapath) || replacefiles)
    {
        WWW unpackerWWW = new WWW(Application.streamingAssetsPath + "/" + sapath);
        while (!unpackerWWW.isDone)
        {
            yield return null;
        }
        if (!string.IsNullOrEmpty(unpackerWWW.error))
        {
            Debug.Log("Error unpacking:" + unpackerWWW.error + " path: " + unpackerWWW.url);

            yield break; //skip it
        }
        else
        {
            Debug.Log("Extracting " + sapath + " to Persistant Data");

            if (!Directory.Exists(Path.GetDirectoryName(Application.persistentDataPath + "/" + sapath)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(Application.persistentDataPath + "/" + sapath));
            }
            File.WriteAllBytes(Application.persistentDataPath + "/" + sapath, unpackerWWW.bytes);
            //could add to some kind of uninstall list?
        }
    }
    yield return 0;
}}

步骤:

  1. 创建一个空场景并将此脚本添加到空对象中。
  2. 保存该场景并在所有场景之前加载。
  3. 不要忘记更改下一个场景名称和数据库名称。