Log in or register to post comments

Unable to display specific ScrollView Image for specific ImageTarget

July 12, 2017 - 6:18pm #1

Hi to anyone who could help,

To begin with, I'm a noob when it comes to vuforia and unity having picked it up 2 weeks ago. I'm an amateur when it comes to coding in C# scripts so please pardon my ignorance if I don't even know simple stuff. I'm currently making an AR app that has multiple Image Targets, each meant as the marker. If I were to focus my ARcamera on an image target, it should display a Scroll View image that is created out from an image within a canvas. My hierarchy is attached where I'm supposed to display ScrollView_S1 for ImageTarget_S1 and ScrollView_S2 for ImageTarget_S2.

Problem is this, as I'm supposed to display specific Scroll View image for specific image targets but as of this point in time, I can only display 1 single Scroll View image i.e. ScrollView_S2 for all image targets which is not I want.

I've read about several solutions in the forum about trackables and stuff (especially those from AlessandroB) and have implemented it to some extent but the display of specific Scroll View for specific image targets is not happening. I have a TrackCanvas.cs script which I used for tracking but somehow or rather, it's not performing my requirements.

Please help to see where I went wrong. Many thanks in advance.

My TrackCanvas.cs script is as follows:

 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using Vuforia;

public class TrackCanvas : MonoBehaviour, ITrackableEventHandler

{

    private TrackableBehaviour mTrackableBehaviour;

   

    // Use this for initialization

    void Start()

    {

        mTrackableBehaviour = GetComponent<TrackableBehaviour>();

        if (mTrackableBehaviour)

        {

            mTrackableBehaviour.RegisterTrackableEventHandler(this);

        }

    }

    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();          

        }

    }

    private void OnTrackingFound()

    {

        Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);

        Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);

        //enable canvas

        Canvas canvasObject = (Canvas)FindObjectOfType(typeof(Canvas));

        {

            canvasObject.enabled = true;

            StateManager sm = TrackerManager.Instance.GetStateManager();

            // Query the StateManager to retrieve the list of

            // currently 'active' trackables

            //(i.e. the ones currently being tracked by Vuforia)

            IEnumerable<TrackableBehaviour> activeTrackables = sm.GetActiveTrackableBehaviours();

            // Iterate through the list of active trackables

            Debug.Log("List of trackables currently active (tracked): ");

            foreach (TrackableBehaviour tb in activeTrackables)

            {

                if (GameObject.FindWithTag("S1").name == "ScrollView_S1")

                {

                    GameObject.FindGameObjectWithTag("S1").SetActive(true);

                    GameObject.FindGameObjectWithTag("S2").SetActive(false);

                    //GameObject.Find("ScrollView_S1").SetActive(true);

                    //GameObject.Find("ScrollView_S2").SetActive(false);

                    //GameObject.FindGameObjectWithTag("S1").SetActive(true);

                }

                else if (GameObject.FindWithTag("S2").name == "ScrollView_S2")

                {

                    GameObject.Find("ScrollView_S2").SetActive(true);

                    GameObject.Find("ScrollView_S1").SetActive(false);

                    //GameObject.FindGameObjectWithTag("S2").SetActive(true);

                }

            }



        }

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



        //disable canvas

        Canvas canvasObject = (Canvas)FindObjectOfType(typeof(Canvas));

        {

            canvasObject.enabled = false;

        }

        // 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");

    }

 

    // Update is called once per frame

    void Update ()

    {

       

    }

}

AttachmentSize
Image icon Hierarchy.jpg28.43 KB
Log in or register to post comments