Log in or register to post comments

OnTrackingLost Help anim

February 24, 2015 - 11:34am #1
I have an animation, with play automatically checked.
With the cilindrical target work fine, the animation play just once on OnTrackingFound, But with imagetarget, the animation always restart on OnTrackingLost and restar on OnTrackingFound. 
I have use the same DefaultTrackableEventHandler.
I need the animation works like in cilincrical target, OnTrackingFound the animation start and stay, then never restart What can i do to fix that in order to play once just on OnTrackingFound.
Heres the code.
 
I would like to now if its possible to fix that, or not. For me dont waste time on that.
 
 
/*==============================================================================
Copyright (c) 2010-2014 Qualcomm Connected Experiences, Inc.
All Rights Reserved.
Confidential and Proprietary - Qualcomm Connected Experiences, Inc.
==============================================================================*/
 
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 ||
            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);
 
 
        Animation[] animationComponents = GetComponentsInChildren<Animation>();
         
        foreach (Animation animation in animationComponents)
        {
            foreach (AnimationState animState in animation)
            {
                animation["inicioBrete"].speed = 1F;
                animation.Play();
            }
        }
 
         
         
         
        // 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");
    }
     
     
    private void OnTrackingLost()
    {
        Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
        Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);
         
         
        Animation[] animationComponents = GetComponentsInChildren<Animation>();
         
        foreach (Animation animation in animationComponents)
        {
            foreach (AnimationState animState in animation)
            {
                animation["inicioBrete"].speed = 0F;
                animation.Play();
            }
        }
 
         
         
        // 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
}

 

OnTrackingLost Help anim

February 25, 2015 - 6:25am #2

HERE IS THE VIDEO SHOWING THE PROBLEM

 

http://nabilfx.eu.pn/HELP.mp4

Log in or register to post comments