Vuforia Engine lets you load Vuforia targets from app-specific storage on Android. Dataset (.xml and .dat) files that are downloaded at runtime can be saved to that location and loaded using the following example.
Load from App-specific Storage
Unity provides an abstraction for app-specific storage, which is accessible using the persistentDataPath.
1CopyexternalPath = UnityEngine.Application.persistentDataPath;
On most devices, the persistent datapath looks like this:
1Copy/storage/emulated/0/data/ + <package-name> + /files
For example, if your package name is com.myorg.myapps, you should see:
1Copy
/storage/emulated/0/Android/data/com.myorg.myapps/files
Based on the above information, you should store your dataset files in the above directory once they are downloaded. For example, for the VuforiaMars_Images database, you should copy the dataset files into a subdirectory in /files/ or into the following directory:
12Copy
/storage/emulated/0/Android/data/com.myorg.myapps/files/VuforiaMars_Images.xml /storage/emulated/0/Android/data/com.myorg.myapps/files/VuforiaMars_Images.dat
The following code snippet shows how to load dataset files from the app-specific storage in a C# script. In the following example, the database is called VuforiaMars_Images (dataset files VuforiaMars_Images.xml and VuforiaMars_Images.dat) and the target is called Astronaut. The database was saved directly into UnityEngine.Application.persistentDataPath
:
12345678910111213141516171819Copyusing UnityEngine;
using Vuforia;
public class AppStorageDataSetLoader : MonoBehaviour
{
private void Start()
{
VuforiaApplication.Instance.OnVuforiaStarted += LoadObserver;
}
void LoadObserver()
{
string externalPath = Application.persistentDataPath + "/VuforiaMars_Images.xml";
string target = "Astronaut";
// Create target from path and target name
var imageTarget = VuforiaBehaviour.Instance.ObserverFactory.CreateImageTarget(externalPath, target);
}
}