Created
September 13, 2013 01:34
-
-
Save nuttt/6545931 to your computer and use it in GitHub Desktop.
Vuforia picture detection game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*============================================================================== | |
Copyright (c) 2010-2013 QUALCOMM Austria Research Center GmbH. | |
All Rights Reserved. | |
Confidential and Proprietary - QUALCOMM Austria Research Center GmbH. | |
==============================================================================*/ | |
using UnityEngine; | |
/// <summary> | |
/// A custom handler that implements the ITrackableEventHandler interface. | |
/// </summary> | |
public class DefaultTrackableEventHandler : MonoBehaviour, | |
ITrackableEventHandler | |
{ | |
#region PRIVATE_MEMBER_VARIABLES | |
private TrackableBehaviour mTrackableBehaviour; | |
#endregion // PRIVATE_MEMBER_VARIABLES | |
#region UNTIY_MONOBEHAVIOUR_METHODS | |
void Start() | |
{ | |
mTrackableBehaviour = GetComponent<TrackableBehaviour>(); | |
if (mTrackableBehaviour) | |
{ | |
mTrackableBehaviour.RegisterTrackableEventHandler(this); | |
} | |
} | |
#endregion // UNTIY_MONOBEHAVIOUR_METHODS | |
#region PUBLIC_METHODS | |
/// <summary> | |
/// Implementation of the ITrackableEventHandler function called when the | |
/// tracking state changes. | |
/// </summary> | |
public void OnTrackableStateChanged( | |
TrackableBehaviour.Status previousStatus, | |
TrackableBehaviour.Status newStatus) | |
{ | |
if (newStatus == TrackableBehaviour.Status.DETECTED || | |
newStatus == TrackableBehaviour.Status.TRACKED) | |
{ | |
OnTrackingFound(); | |
} | |
else | |
{ | |
OnTrackingLost(); | |
} | |
} | |
#endregion // PUBLIC_METHODS | |
#region PRIVATE_METHODS | |
private void OnTrackingFound() | |
{ | |
Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true); | |
Collider[] colliderComponents = GetComponentsInChildren<Collider>(true); | |
// Enable rendering: | |
foreach (Renderer component in rendererComponents) | |
{ | |
component.enabled = true; | |
} | |
// Enable colliders: | |
foreach (Collider component in colliderComponents) | |
{ | |
component.enabled = true; | |
} | |
//Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found"); | |
GameObject o = GameObject.Find("GameObject"); | |
MyScript s = (MyScript)o.GetComponent("MyScript"); | |
s.checkImage(mTrackableBehaviour.TrackableName); | |
} | |
private void OnTrackingLost() | |
{ | |
Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true); | |
Collider[] colliderComponents = GetComponentsInChildren<Collider>(true); | |
// Disable rendering: | |
foreach (Renderer component in rendererComponents) | |
{ | |
component.enabled = false; | |
} | |
// Disable colliders: | |
foreach (Collider component in colliderComponents) | |
{ | |
component.enabled = false; | |
} | |
Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost"); | |
} | |
#endregion // PRIVATE_METHODS | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class MyScript : MonoBehaviour { | |
public Texture[] images; | |
public string[] names; | |
public int num; | |
private int current_score = 0; | |
private int current_image; | |
// Use this for initialization | |
void Start () { | |
current_image = 0; | |
} | |
void OnGUI () { | |
GUI.DrawTexture(new Rect(10,10,100,100), images[current_image]); | |
GUI.Label(new Rect(10,130,100,100), "Score: " + current_score); | |
} | |
// Update is called once per frame | |
void Update () { | |
} | |
public void checkImage(string imageName) { | |
Debug.Log("Camera Image: " + imageName + " | Current Image: " + names[current_image]); | |
if(imageName == names[current_image]){ | |
changeImage(); | |
} | |
} | |
public void changeImage() { | |
int old = current_image; | |
while(true){ | |
current_image = Random.Range(0, num); | |
if(current_image != old) break; | |
} | |
current_score++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment