unity分包obb与vuforia加载数据集出错

转载链接:https://developer.vuforia.com/forum/faq/load-dataset-android-split-binary-obb

因为提交应用上GooglePlay超过一百兆就要分包处理,在使用Vuforia的时候分包,有可能会丢失一些数据,所以我们就要保证Vuforia的数据全部加载进主包中(自我理解是这样的,如果有错误望指出)。

以下是原博主提出的解决办法,而我们正是用这个方法解决了问题,非常感谢博主。

创建一个新的Unity项目并导入Vuforia SDK和Vuforia示例项目。在此下载:https//developer.vuforia.com/downloads/sdk

Vuforia配置

  • 输入您的许可证密钥
  • 确保你的数据集被加载和激活(在这个例子中,我将使用示例项目中存在的StonesAndChips数据集)

播放器设置 - > Android设置

  • 其他设置:将“写入权限”设置为“外部(SDCard)”
  • 发布设置:选中“拆分应用程序二进制文件”框

一旦完成了以上设置,请复制此帖子底部的代码(ObbExtractor.cs)并创建一个新场景。在这个场景中,用下面的代码创建一个新脚本并将其附加到一个对象。这个场景需要在Vuforia初始化以正常运行之前运行。

在本例中,将Vuforia示例项目场景添加到构建设置的“构建场景”中,然后使用场景列表顶部的ObbExtractor添加此额外场景。这将在此场景中启动应用程序,并允许在下列场景中移动到Vuforia初始化之前提取数据集。在这种情况下提供的示例脚本将在提取完成时自动加载场景“Vuforia-0-Splash”。

一旦Vuforia加载完成,StonesAndChips数据集的图像目标将准备就绪。

免责声明:此代码是作为Vuforia 6.2示例应用程序的教学示例。

using System.IO;
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
 
 
public class ObbExtractor : MonoBehaviour {
 
     void Start () {
         StartCoroutine(ExtractObbDatasets());
     }
 
     private IEnumerator ExtractObbDatasets () {
         string [] filesInOBB = { "StonesAndChips.dat" , "StonesAndChips.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( "Vuforia-0-Splash" );
     }
 
     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 );   
         }
     }
}

此代码将从obb中提取StonesAndChips .dat和.xml文件,并将其输出到应用程序persistentDataPath中,以便在Vuforia初始化时加载它们。此代码需要在Vuforia初始化之前运行。

亲测可解决问题。我遇到的问题是:分包之后,imagert丢失,即找不到扫描图片的目标。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值