daily pastebin goal
25%
SHARE
TWEET

Untitled

a guest Jun 13th, 2018 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*==============================================================================
  2. Copyright (c) 2010-2014 Qualcomm Connected Experiences, Inc.
  3. All Rights Reserved.
  4. Confidential and Proprietary - Protected under copyright and other laws.
  5. ==============================================================================*/
  6.  
  7. using UnityEngine;
  8.  
  9. namespace Vuforia
  10. {
  11.     /// <summary>
  12.     /// A custom handler that implements the ITrackableEventHandler interface.
  13.     /// </summary>
  14.     public class MyTrackableEventHandler : MonoBehaviour,
  15.                                                 ITrackableEventHandler
  16.     {
  17.         #region PRIVATE_MEMBER_VARIABLES
  18.  
  19.         private TrackableBehaviour mTrackableBehaviour;
  20.         public bool isTracking;
  21.         public GameObject[] receivers;
  22.    
  23.         #endregion // PRIVATE_MEMBER_VARIABLES
  24.  
  25.  
  26.  
  27.         #region UNTIY_MONOBEHAVIOUR_METHODS
  28.    
  29.         void Start()
  30.         {
  31.             mTrackableBehaviour = GetComponent<TrackableBehaviour>();
  32.             if (mTrackableBehaviour)
  33.             {
  34.                 mTrackableBehaviour.RegisterTrackableEventHandler(this);
  35.             }
  36.         }
  37.  
  38.         #endregion // UNTIY_MONOBEHAVIOUR_METHODS
  39.  
  40.  
  41.  
  42.         #region PUBLIC_METHODS
  43.  
  44.         /// <summary>
  45.         /// Implementation of the ITrackableEventHandler function called when the
  46.         /// tracking state changes.
  47.         /// </summary>
  48.         public void OnTrackableStateChanged(
  49.                                         TrackableBehaviour.Status previousStatus,
  50.                                         TrackableBehaviour.Status newStatus)
  51.         {
  52.             if (newStatus == TrackableBehaviour.Status.DETECTED ||
  53.                 newStatus == TrackableBehaviour.Status.TRACKED ||
  54.                 newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
  55.             {
  56.                 OnTrackingFound();
  57.             }
  58.             else
  59.             {
  60.                 OnTrackingLost();
  61.             }
  62.         }
  63.  
  64.         #endregion // PUBLIC_METHODS
  65.  
  66.  
  67.  
  68.         #region PRIVATE_METHODS
  69.  
  70.  
  71.         private void OnTrackingFound()
  72.         {
  73.             isTracking = true;
  74.             for (int i = 0; i < receivers.Length; i++) {
  75.                 if (receivers [i] != null)
  76.                     receivers [i].SendMessage ("OnTrackingFound", SendMessageOptions.DontRequireReceiver);
  77.             }
  78.             Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
  79.             Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);
  80.  
  81.             // Enable rendering:
  82.             foreach (Renderer component in rendererComponents)
  83.             {
  84.                 component.enabled = true;
  85.             }
  86.  
  87.             // Enable colliders:
  88.             foreach (Collider component in colliderComponents)
  89.             {
  90.                 component.enabled = true;
  91.             }
  92.  
  93.             Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");
  94.         }
  95.  
  96.  
  97.         private void OnTrackingLost()
  98.         {
  99.             isTracking = false;
  100.             for (int i = 0; i < receivers.Length; i++) {
  101.                 if (receivers [i] != null)
  102.                     receivers [i].SendMessage ("OnTrackingLost", SendMessageOptions.DontRequireReceiver);
  103.             }
  104.             Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
  105.             Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);
  106.  
  107.             // Disable rendering:
  108.             foreach (Renderer component in rendererComponents)
  109.             {
  110.                 component.enabled = false;
  111.             }
  112.  
  113.             // Disable colliders:
  114.             foreach (Collider component in colliderComponents)
  115.             {
  116.                 component.enabled = false;
  117.             }
  118.  
  119.             Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");
  120.         }
  121.  
  122.         #endregion // PRIVATE_METHODS
  123.     }
  124. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top