我遇到了一个持续存在的问题,即当我将应用程序构建为具有拆分二进制选项的 Android 应用程序包 (AAB) 时,无法识别 Vuforia 数据库。但是,当我将项目构建为 APK 时,一切正常。
这是我到目前为止所探索的内容:
我了解 AAB 中的 StreamingAssets 文件夹存在特定注意事项,例如下载内容时可能出现延迟。 我尝试使用 AssetBundles 打包 Vuforia 数据库。不幸的是,.dat 文件似乎无法包含在 AssetBundle 中。作为参考,该应用程序确实上传,我可以打开它。只是 Vuforia 不起作用!
我在 Unity 中有一个加载场景,我的主场景在之后加载
设置详情:
Unity 2022.3.25f1
Vuforia 10.22.5
Build App Bundle (Google Play) [Check]
Split Application Binary [Check]
Base Scene Size: ~50MB
Main Scene Size: ~1.5GB
我花了几个晚上的时间试图解决这个问题,但没有成功。有人对如何确保正确识别 Vuforia 数据库并以 AAB 格式加载有建议吗?任何见解或修复将不胜感激。
谢谢你, 运动大脑
我尝试这样做来延迟流媒体资产文件夹。
IEnumerator Start()
{
#if UNITY_EDITOR
yield return null;
#else
string[] assetPackNames = AndroidAssetPacks.GetCoreUnityAssetPackNames();
if (!AndroidAssetPacks.coreUnityAssetPacksDownloaded)
{
yield return StartCoroutine(WaitForAssetPacksDownload(assetPackNames));
}
else{
yield return StartCoroutine(CheckAssetPacksDownloaded(assetPackNames));
}
#endif
}
IEnumerator WaitForAssetPacksDownload(string[] assetPackNames)
{
bool allDownloaded = false;
// App cannot load without UnityStreamingAssetsPack being downloaded first
while (!allDownloaded)
{
var operation = AndroidAssetPacks.GetAssetPackStateAsync(assetPackNames);
yield return operation; // Wait for the state check to complete
if (operation.isDone)
{
allDownloaded = true;
}
if (!allDownloaded)
{
// Wait before checking again to avoid spamming checks
yield return new WaitForSeconds(3);
}
}
errorTtext.SetText("All asset packs downloaded.");
AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(1);
asyncOperation.allowSceneActivation = false;
while (!asyncOperation.isDone)
{
float progress = asyncOperation.progress * 100;
loadingPercent.text = (int)progress + "%";
if (asyncOperation.progress >= 0.90f)
{
yield return new WaitForSeconds(5);
asyncOperation.allowSceneActivation = true;
}
yield return null;
}
}
编辑:
如果应用程序大小为 < 150MB.
,Vuforia 即可工作找到解决方案:
恢复至 Vuforia 9.8.5。 并在加载我的 MainScene (大场景)时使用了此代码
private string datUrl = "url.dat";
private string xmlUrl = "url.xml";
private string datasetName = "datasetName";
IEnumerator DownloadAndLoadDatasets()
{
// Download DAT file
UnityWebRequest datRequest = UnityWebRequest.Get(datUrl);
yield return datRequest.SendWebRequest();
if (datRequest.isNetworkError || datRequest.isHttpError)
{
statusText.text += "Failed to download DAT file: " + datRequest.error;
yield break;
}
// Download XML file
UnityWebRequest xmlRequest = UnityWebRequest.Get(xmlUrl);
yield return xmlRequest.SendWebRequest();
if (xmlRequest.isNetworkError || xmlRequest.isHttpError)
{
statusText.text += "Failed to download XML file: " + xmlRequest.error;
yield break;
}
// Save downloaded files
string datPath = Path.Combine(Application.persistentDataPath, datasetName + ".dat");
string xmlPath = Path.Combine(Application.persistentDataPath, datasetName + ".xml");
File.WriteAllBytes(datPath, datRequest.downloadHandler.data);
File.WriteAllBytes(xmlPath, xmlRequest.downloadHandler.data);
// Load and activate dataset
LoadAndActivateDataset(datPath, xmlPath);
}
void LoadAndActivateDataset(string datPath, string xmlPath)
{
ObjectTracker objectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
DataSet dataSet = objectTracker?.CreateDataSet();
if (dataSet != null /*&& dataSet.Load(xmlPath, VuforiaUnity.StorageType.STORAGE_ABSOLUTE)*/)
{
objectTracker.Stop();
objectTracker.ActivateDataSet(dataSet);
objectTracker.Start();
}
else
{
statusText.text += "Failed to load dataset.";
}
}