Log in or register to post comments

Inheriting the DefaultTrackableEventHandler

June 28, 2018 - 10:38am #1

I have a game object that scales to size after the image target is found. However, I would like to reset that size every time the image target is lost. I was trying to inherit the OnTrackableStateChanged(), OnTrackingLost(), and OnTrackingFound(). Whenever I run the program, it seems to ignore anything I write in OnTrackingFound() or OnTrackingLost(), I think it has something to do with the inheritance, but I would take any advice, thank you



public class ScaleUp : DefaultTrackableEventHandler

{

    private TrackableBehaviour mTrackableBehaviour;

    private float max_size;

    private Vector3 curr_size;

    // Use this for initialization

    void Start ()

    {

        max_size = 0.002F;

        curr_size = transform.localScale;

        mTrackableBehaviour = GetComponent<TrackableBehaviour>();

        if (mTrackableBehaviour)

            mTrackableBehaviour.RegisterTrackableEventHandler(this);

    }

    // Update is called once per frame

    void Update()

    {

        if (curr_size[0] <= max_size)

        {

            transform.localScale += new Vector3(0.00003F, 0.00003F, 0.00003F);

            curr_size = transform.localScale;

        }

    }

    public void OnTrackableStateChanged(

        TrackableBehaviour.Status previousStatus,

        TrackableBehaviour.Status newStatus)

    {

        Debug.Log("In State Change");

        if (newStatus == TrackableBehaviour.Status.DETECTED ||

            newStatus == TrackableBehaviour.Status.TRACKED ||

            newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)

        {

            Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");

            OnTrackingFound();

        }

        else if (previousStatus == TrackableBehaviour.Status.TRACKED &&

                 newStatus == TrackableBehaviour.Status.NO_POSE)

        {

            Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");

            OnTrackingLost();

        }

        else

        {

            // For combo of previousStatus=UNKNOWN + newStatus=UNKNOWN|NOT_FOUND

            // Vuforia is starting, but tracking has not been lost or found yet

            // Call OnTrackingLost() to hide the augmentations

            OnTrackingLost();

        }

    }

    private void OnTrackingFound()

    {

        transform.localScale = new Vector3(0F, 0F, 0F);

    }



    private void OnTrackingLost()

    {

    }

}

Inheriting the DefaultTrackableEventHandler

June 29, 2018 - 12:32pm #3

That makes a lot of sense, I'll give it a shot. Thanks

Inheriting the DefaultTrackableEventHandler

June 28, 2018 - 7:26pm #2

I usually rewrite this particular event handler.

 

ex. public class MyTargetRecognizedEventHandler : MonoBehaviour, ITrackableEventHandler {

[copy the contents from DefaultTrackableEventHandler and implement your modifications]

}

 

Attach it instead of the default one.

Log in or register to post comments