I'm using Unity and Vuforia to make a secret project for my tabletop RPG group. Right now I'm running into an issue of lack of references and removed web pages on Vuforia's site.
Currently, my issue is this: I want to track up to 5 target images and, when scanned, have each of them to create their own individual GUI Window that tracks with the image in the UI. I have part of it working, I can track all the images, but only 1 window appears at a time. I know the actual images work because I have placeholder 3d objects included for debugging.
The script I used for the base for the GUI Windows: https://developer.vuforia.com/forum/faq/unity-how-can-i-popup-gui-button-when-target-detected
I think my problem lies in the OnTrackableStateChanged() (Lines 19-32 link; 28-43 my code below). I need to alter it so it can take into account multiple target images. Then again I could be SUPER wrong because any references on Vuforia's API site or forums has been removed. Does anyone have a possible idea on what I can do to accomplish my goal? I'm currently thinking using the getID() function and then, somehow, having OnTrackableStateChange() check if the changed ID was different than the original idea. But again, I could be overlooking a simpler solution.
If this isn't clear I can try to be elaborate a bit more. Below is the code I'm using that uses components from the link above. Thank you for the help. :
using UnityEngine;
using System.Collections;
public class ButtonPopup : MonoBehaviour, Vuforia.ITrackableEventHandler
{
private Vuforia.TrackableBehaviour mTrackableBehaviour;
private bool mShowGUIWindow = false;
private TargetScreenCoords coordinateScript;
public int ID;
private Rect mWindowRect;
public string Name;
public int Health;
public string Status;
public bool Villain;
void Start()
{
mTrackableBehaviour = GetComponent<Vuforia.TrackableBehaviour>();
if (mTrackableBehaviour)
{
mTrackableBehaviour.RegisterTrackableEventHandler(this);
}
}
public void OnTrackableStateChanged(
Vuforia.TrackableBehaviour.Status previousStatus,
Vuforia.TrackableBehaviour.Status newStatus)
{
if (newStatus == Vuforia.TrackableBehaviour.Status.DETECTED ||
newStatus == Vuforia.TrackableBehaviour.Status.TRACKED)
{
mShowGUIWindow = true;
}
else
{
mShowGUIWindow = false;
}
}
void OnGUI()
{
coordinateScript = GetComponent<TargetScreenCoords>();
mWindowRect = new Rect(coordinateScript.screenPoint.x, Mathf.Abs(coordinateScript.screenPoint.y), 120, 100);
if (Villain == true)
{
GUI.backgroundColor = Color.red;
}
if (Villain == false)
{
GUI.backgroundColor = Color.green;
}
if (mShowGUIWindow)
{
mWindowRect = GUI.Window(ID, mWindowRect, DoMyWindow, "ID:" + ID);
}
}
void DoMyWindow(int windowID)
{
GUI.Label(new Rect(10, 20, 100, 60), new GUIContent("Name: " + Name + "\nHealth: " + Health + "\nStatus: " + Status));
if (GUI.Button(new Rect(10, 70, 100, 20), "Edit Button"))
{
print("Got a click");
Villain = !Villain;
}
}
}
Thanks again for the help/ideas.