'load assetbundles dynamically from JSON - Unity Vuforia
I have created an app where I am trying to load the asset bundles from a JSON file.
JSONNode targetAsset = JSON.Parse(request.downloadHandler.text);
int counter = 0;
for (int i = 0 ; i < targetAsset.Count ; i++) {
counter++;
if (targetAsset[i]["targetid"].Value.Equals(targetAsset[i][0])) {
Debug.Log("It exists!");
break;
}
}
Using break loads index 0 assets from the JSON on every image target and without break, it loads the last asset from the JSON. But I want to load a particular asset on a particular image target. I tried the below code but it didn't work.
if (targetAsset[i]["targetid"].Value.Equals(targetAsset[i][0])) {
Debug.Log("It exists!");
if targetAsset[i][0] == uniqueTargetID; # uniqueTargetID is a variable called from SimpleCloudRecoEventHandler class.
break;
}
Here is my JSON file:
[
{
"targetid": "sometargetalphanumericfromvuforia",
"assetbundle":"urlofassetbundle",
"prefab": "Assets/Prefabs/xyz1.prefab",
"AssetName":"xyz1"
},
{
"targetid": "sometargetalphanumericfromvuforia",
"assetbundle":"urlofassetbundle",
"prefab": "Assets/Prefabs/xyz2.prefab",
"AssetName":"xyz2"
}
]
I am using Vuforia's latest version, with Unity 2019 and creating an app for android platform.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
