Hi,I was testing Augmented Image example scene .The problem I faced was I cannot hide the Prefab once it comes.When I show mu camera to Augmented Image which I set ,the prefab instantiates. Once it comes, It wont go even after I remove the image.How to stop that.I only want the prefab to come when the corresponding image is present.
namespace GoogleARCore.Examples.AugmentedImage
{
using System.Collections.Generic;
using System.Runtime.InteropServices;
using GoogleARCore;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// Controller for AugmentedImage example.
/// </summary>
public class AugmentedImageExampleController : MonoBehaviour
{
/// <summary>
/// A prefab for visualizing an AugmentedImage.
/// </summary>
// public AugmentedImageVisualizer AugmentedImageVisualizerPrefab;
public List<AugmentVisualize> prefabs = new List<AugmentVisualize>();
/// <summary>
/// The overlay containing the fit to scan user guide.
/// </summary>
public GameObject FitToScanOverlay;
private Dictionary<int, AugmentVisualize> m_Visualizers
= new Dictionary<int, AugmentVisualize>();
private List<AugmentedImage> m_TempAugmentedImages = new List<AugmentedImage>();
/// <summary>
/// The Unity Update method.
/// </summary>
public void Update()
{
// Exit the app when the 'back' button is pressed.
if (Input.GetKey(KeyCode.Escape))
{
Application.Quit();
}
// Check that motion tracking is tracking.
if (Session.Status != SessionStatus.Tracking)
{
return;
}
// Get updated augmented images for this frame.
Session.GetTrackables<AugmentedImage>(m_TempAugmentedImages, TrackableQueryFilter.Updated);
// Create visualizers and anchors for updated augmented images that are tracking and do not previously
// have a visualizer. Remove visualizers for stopped images.
foreach (var image in m_TempAugmentedImages)
{
AugmentVisualize visualizer = null;
m_Visualizers.TryGetValue(image.DatabaseIndex, out visualizer);
if (image.TrackingState == TrackingState.Tracking && visualizer == null)
{
// Create an anchor to ensure that ARCore keeps tracking this augmented image.
Anchor anchor = image.CreateAnchor(image.CenterPose);
visualizer = (AugmentVisualize)Instantiate(prefabs[image.DatabaseIndex], anchor.transform);
visualizer.Image = image;
m_Visualizers.Add(image.DatabaseIndex, visualizer);
}
else if (image.TrackingState == TrackingState.Stopped && visualizer != null)
{
m_Visualizers.Remove(image.DatabaseIndex);
GameObject.Destroy(visualizer.gameObject);
}
}
// Show the fit-to-scan overlay if there are no images that are Tracking.
foreach (var visualizer in m_Visualizers.Values)
{
if (visualizer.Image.TrackingState == TrackingState.Tracking)
{
FitToScanOverlay.SetActive(false);
return;
}
}
FitToScanOverlay.SetActive(true);
}
}
}
public class AugmentVisualize : MonoBehaviour {
public AugmentedImage Image;
public GameObject [] Listprefabs;
public Text Showtext;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (Image == null || Image.TrackingState == TrackingState.Paused)
{
//Listprefabs[Image.DatabaseIndex].SetActive(false);
Listprefabs[0].SetActive(false);
Listprefabs[1].SetActive(false);
Showtext.text = "Paused";
return;
}
else if(Image == null || Image.TrackingState == TrackingState.Stopped)
{
//Listprefabs[Image.DatabaseIndex].SetActive(false);
Listprefabs[0].SetActive(false);
Listprefabs[1].SetActive(false);
Showtext.text = "Stopped";
return;
}
else if (Image == null || Image.TrackingState != TrackingState.Tracking)
{
//Listprefabs[Image.DatabaseIndex].SetActive(false);
Listprefabs[0].SetActive(false);
Listprefabs[1].SetActive(false);
Showtext.text = "not tracking";
return;
}
else if(Image == null || Image.TrackingState == TrackingState.Tracking)
{
Listprefabs[Image.DatabaseIndex].SetActive(true);
Showtext.text = "Prefab showing";
}
}
}