Log in or register to post comments

AR Books with multiple scenes

March 19, 2018 - 8:15pm #1

Hi, I am new in Vuforia and Unity,

I am trying to develop an AR book with multiple pages. Theoretically, someone can just view two pages of a book at the same time, and to reduce the memory usage I like to split the books on several pages. Each page as a single scene with image target and 3D object. Now, I need a script that can run on the main scene to –

  1.     Load the corresponding scene when a specific image target is found (i.e. ImageTarget_01 for Scene_01, and ImageTarget_02 for Scene_02 etc.)
  2.     Unload/kill any previously loaded scene/s from the memory, at the same time.
  3.  If  aren’t tracking something attached to a scene then unload the current scene.

Is there anyone can help me to write this script? or can advice any resource to follow.

AR Books with multiple scenes

November 20, 2018 - 1:40am #3

Thanks dpizzle for your time and effort. I have managed to solve the issue, anyway.

AR Books with multiple scenes

March 20, 2018 - 2:15pm #2

Here's some code I pulled form a project.  You'd replace DefaultTrackableEventHandler on your image targets with something like this.  Unfortunatly I don't have time to explain it, hopefully it can help.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;

public class MyDefaultTrackableEventHandler : DefaultTrackableEventHandler
{
private static bool appIsPaused = false;
private static bool loaded = false;
public static bool working = false;
public static bool lostQueued = false;
string currentTrackable = "";

protected override  void OnTrackingFound()
{
  base.OnTrackingFound ();
  if (!appIsPaused)
  {
   if (working || loaded || lostQueued)
    return;
   working = true;
   loaded = true;
 
   string loadName = mTrackableBehaviour.TrackableName;
   StartCoroutine (LoadLevel (loadName));
  }
}

protected override void OnTrackingLost()
{
  if (working) {
   lostQueued = true;
   return;
  }

  lostQueued = false;
  working = true;

  base.OnTrackingLost ();

  string loadName = mTrackableBehaviour.TrackableName;
  DestroyLevelData (loadName);

  System.GC.Collect ();

  working = false;
  loaded = false;
}

IEnumerator LoadLevel(string levelName)
{
  AsyncOperation async = Application.LoadLevelAdditiveAsync(levelName);

  yield return async;

  GameObject go = GameObject.Find(levelName);
  if (go != null)
  {
   BaseScript script = go.GetComponent<BaseScript>();
   if (script != null)
   {
    script.begin();
   }
  }
  working = false;
}

private void DestroyLevelData(string objectName)
{
  GameObject go = GameObject.Find(objectName);

  if (go != null)
  {
   BaseScript script = go.GetComponent<BaseScript>();
   if (script != null)
   {
    script.end();
   }

   Destroy(go);
  }

  Resources.UnloadUnusedAssets();
}

void OnApplicationPause(bool pauseState)
{
  appIsPaused = pauseState;
}
}
Log in or register to post comments