private void UpdateUICanvas() { // Get updated augmented images for this frame. Session.GetTrackables <AugmentedImage>(m_TempAugmentedImages, TrackableQueryFilter.Updated); //bool CanvasActive = false; // 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) { AugmentedImageController visualizer = null; m_Visualizers.TryGetValue(image.DatabaseIndex, out visualizer); if (image.TrackingState == TrackingState.Tracking && visualizer == null) { Debug.Log("Found image " + image.DatabaseIndex.ToString() + ". Setting up ui canvas"); // Create an anchor to ensure that ARCore keeps tracking this augmented image. Anchor anchor = image.CreateAnchor(image.CenterPose); visualizer = (AugmentedImageController)Instantiate(AugmentedImageVisualizerPrefab, anchor.transform); if (visualizer == null) { Debug.Log("Visualizer is still null"); } visualizer.transform.RotateAround(visualizer.transform.position, visualizer.transform.right, 90); visualizer.gameObject.SetActive(true); visualizer.DebugString = "House " + image.DatabaseIndex.ToString(); visualizer.Image = image; m_Visualizers.Add(image.DatabaseIndex, visualizer); //CanvasActive = true; //Vector3 testPos = Camera.main.WorldToScreenPoint(anchor.transform.position); //Debug.Log("Test pos: " + testPos.ToString()); //UICanvas.transform.position = testPos; } else if (image.TrackingState == TrackingState.Stopped && visualizer != null) { m_Visualizers.Remove(image.DatabaseIndex); GameObject.Destroy(visualizer.gameObject); } } foreach (var visualizer in m_Visualizers.Values) { if (visualizer.Image.TrackingState == TrackingState.Tracking) { FitToScanOverlay.SetActive(false); return; } } FitToScanOverlay.SetActive(true); //UICanvas.gameObject.SetActive(CanvasActive); }
private void UpdateDebug() { // Get updated augmented images for this frame. Session.GetTrackables <AugmentedImage>(m_TempAugmentedImages, TrackableQueryFilter.Updated); //bool CanvasActive = false; // 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) { AugmentedImageController visualizer = null; m_Visualizers.TryGetValue(image.DatabaseIndex, out visualizer); if (image.TrackingState == TrackingState.Tracking && visualizer == null) { Debug.Log("Found image " + image.DatabaseIndex.ToString() + ". Setting up ui canvas"); // Create an anchor to ensure that ARCore keeps tracking this augmented image. Anchor anchor = image.CreateAnchor(image.CenterPose); GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube); cube.AddComponent <Rigidbody>(); cube.GetComponent <Rigidbody>().useGravity = false; cube.transform.position = anchor.transform.position; } } foreach (var visualizer in m_Visualizers.Values) { if (visualizer.Image.TrackingState == TrackingState.Tracking) { FitToScanOverlay.SetActive(false); return; } } FitToScanOverlay.SetActive(true); //UICanvas.gameObject.SetActive(CanvasActive); }