Log in or register to post comments

On traking Lost help...

December 24, 2014 - 6:01am #1
How can be modified this script, to pause the animation of the game object on tracking lost, and restart from the place where it stop, on tracking found, and not from the begining.


/*==============================================================================
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);


//     *** Additional animation code
//        Animation[] animationComponents = GetComponentsInChildren<Animation>();
//        
//        foreach (Animation component in animationComponents)
//        {
//            component.Play();  
//        }
//     *** end of animation code

        Animation[] animationComponents = GetComponentsInChildren<Animation>();
        
        foreach (Animation animation in animationComponents)
        {
            foreach (AnimationState animState in animation)
            {
                animState.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)
            {
                animState.speed = 0f;
                animation.Stop();
            }
        }



        // 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
}

 

On traking Lost help...

December 24, 2014 - 6:49am #2

I have one animation attach to the Gameobject, and one 3d animation imported from maya, inside the GameObject. I need the first animatin work just when the image track is found,  and not restart on image track lost and found.

cause is the first animation from the game, and can no t be restarted every time.

How can i fix that?

Log in or register to post comments