Log in or register to post comments

Asset Bundles on image tracking found/lost

May 25, 2014 - 11:46am #1

Hi there I've been having some trouble trying to get my asset bundle to be initiated when the image target is found and then lost. I read though some of the other forum questions and I found this answer. 

To reference the script, first find the GameObject using GameObject.Find([name]) and then use go.GetComponent<script_name>() to reference the script from that GameObject reference. The boolean can then be set directly using ref.targetIsFound.

but then I try to implement it into the defaulttrackableventhandler I keep getting errors. 

 

can you please help.

 

/*==============================================================================
Copyright (c2010-2014 Qualcomm Connected ExperiencesInc.
All Rights Reserved.
Confidential and Proprietary - Qualcomm Connected ExperiencesInc.
==============================================================================*/

using System;
using UnityEngine;
using System.Collections;

/// <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 AssetBundleAugmenter itargetScript;

    private void OnTrackingFound()
    {
        itargetScript = GetComponent<AssetBundleAugmenter>();

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

        itargetScript.targetisFound = true;
        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;
        }

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

    #endregion // PRIVATE_METHODS
}

 

Asset Bundles on image tracking found/lost

May 28, 2014 - 11:07pm #3

Asset Bundles on image tracking found/lost

May 28, 2014 - 7:46pm #2

There's not much information about the problem in your post. A script component is being retrieved and a boolean value on it is changed. Perhaps the following article will help provide some guidance:

https://developer.vuforia.com/resources/dev-guide/special-options-unity

It is generally recommended to not modify the DefaultTrackableEventHandler, but to instead copy it's general structure to a new script and implement the ITrackableEventHandler methods and add new specific behavior as needed.

 

Log in or register to post comments