Created
November 27, 2017 14:13
-
-
Save nickyeh97/0e1e67c0ddba7e3ee858fdb3a533dab9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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; | |
namespace Vuforia | |
{ | |
/// <summary> | |
/// A custom handler that implements the ITrackableEventHandler interface. | |
/// </summary> | |
public class FoodCheck : MonoBehaviour, | |
ITrackableEventHandler | |
{ | |
public GameSystem GS; | |
public GameObject Food; | |
#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 || | |
newStatus == TrackableBehaviour.Status.EXTENDED_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; | |
} | |
GS.RegisterSceneObject (GameSystem.SceneObjectType.Food, Food); | |
Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found"); | |
} | |
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; | |
} | |
GS.DeRegisterSceneObject (GameSystem.SceneObjectType.Food, Food); | |
Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost"); | |
} | |
#endregion // PRIVATE_METHODS | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment