Ejemplo n.º 1
0
        /// <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)
            {
                AugmentedImageVisualizer 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       = Instantiate(AugmentedImageVisualizerPrefab, 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);
                }
            }
        }
        /// <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();
            }

            // Only allow the screen to sleep when not tracking.
            if (Session.Status != SessionStatus.Tracking)
            {
                Screen.sleepTimeout = SleepTimeout.SystemSetting;
            }
            else
            {
                Screen.sleepTimeout = SleepTimeout.NeverSleep;
            }

            // 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)
            {
                AugmentedImageVisualizer 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.
                    if (image.Name == "лево")
                    {
                        Anchor anchor = image.CreateAnchor(image.CenterPose);
                        visualizer = (AugmentedImageVisualizer)Instantiate(
                            left, anchor.transform);
                        visualizer.Image = image;
                        m_Visualizers.Add(image.DatabaseIndex, visualizer);
                    }
                    if (image.Name == "старт")
                    {
                        Anchor anchor = image.CreateAnchor(image.CenterPose);
                        visualizer = (AugmentedImageVisualizer)Instantiate(
                            start, anchor.transform);
                        visualizer.Image = image;
                        m_Visualizers.Add(image.DatabaseIndex, visualizer);
                    }
                    if (image.Name == "прямо")
                    {
                        Anchor anchor = image.CreateAnchor(image.CenterPose);
                        visualizer = (AugmentedImageVisualizer)Instantiate(
                            forward, anchor.transform);
                        visualizer.Image = image;
                        m_Visualizers.Add(image.DatabaseIndex, visualizer);
                    }
                    if (image.Name == "право")
                    {
                        Anchor anchor = image.CreateAnchor(image.CenterPose);
                        visualizer = (AugmentedImageVisualizer)Instantiate(
                            right, anchor.transform);
                        visualizer.Image = image;
                        m_Visualizers.Add(image.DatabaseIndex, visualizer);
                    }
                    if (image.Name == "петляВВ")
                    {
                        Anchor anchor = image.CreateAnchor(image.CenterPose);
                        visualizer = (AugmentedImageVisualizer)Instantiate(
                            loopup, anchor.transform);
                        visualizer.Image = image;
                        m_Visualizers.Add(image.DatabaseIndex, visualizer);
                    }
                    if (image.Name == "петляВ")
                    {
                        Anchor anchor = image.CreateAnchor(image.CenterPose);
                        visualizer = (AugmentedImageVisualizer)Instantiate(
                            loopdown, anchor.transform);
                        visualizer.Image = image;
                        m_Visualizers.Add(image.DatabaseIndex, visualizer);
                    }
                    if (image.Name == "road")
                    {
                        Anchor anchor = image.CreateAnchor(image.CenterPose);
                        visualizer = (AugmentedImageVisualizer)Instantiate(
                            road, 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);
        }
Ejemplo n.º 3
0
        /// <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);
            imageCount.text = "Images: " + m_TempAugmentedImages.Count;
            if (planeGenerator != null) //may be null due to known issue: after resetting ARCore session, Plane Generator stops working, so we set it to null and only use it the first time.
            {
                planeGenerator.SendMessage("ChangeShader", occlusionShader);
            }

            // 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)
            {
                AugmentedImageVisualizer 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);
                    m_anchors.Add(anchor);

                    visualizer = (AugmentedImageVisualizer)Instantiate(prefabs[image.DatabaseIndex], anchor.transform);
                    visualizer.gameObject.SetActive(true);
                    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);
                    resetButton.gameObject.SetActive(true);
                    return;
                }
            }

            FitToScanOverlay.SetActive(true);
            resetButton.gameObject.SetActive(false);

            if (planeGenerator != null)
            {
                planeGenerator.SendMessage("ChangeShader", planeFindingShader);
            }
        }
        /// <summary>
        /// The Unity Update method.
        /// </summary>
        protected override void Update()
        {
            base.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;
            }

            if (!HasTriggerImages)
            {
                return;
            }

            // Get updated augmented images for this frame.
            Session.GetTrackables <AugmentedImage>(_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 _tempAugmentedImages)
            {
                AugmentedImageVisualizer visualizer = null;
                _visualizers.TryGetValue(image.DatabaseIndex, out visualizer);
                if (image.TrackingState == TrackingState.Tracking && visualizer == null)
                {
                    TriggerObject triggerObject = null;
                    if (!TriggerObjects.TryGetValue(image.DatabaseIndex, out triggerObject))
                    {
                        ErrorMessage = "No trigger object for database index " + image.DatabaseIndex;
                    }

                    // Create an anchor to ensure that ARCore keeps tracking this augmented image.
                    Anchor anchor = image.CreateAnchor(image.CenterPose);
                    visualizer               = Instantiate(AugmentedImageVisualizerPrefab, anchor.transform);
                    visualizer.Image         = image;
                    visualizer.TriggerObject = triggerObject;
                    visualizer.ArBehaviour   = this;

                    _visualizers.Add(image.DatabaseIndex, visualizer);
                }
                else if (image.TrackingState == TrackingState.Stopped && visualizer != null)
                {
                    _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 _visualizers.Values)
            {
                if (visualizer.Image.TrackingState == TrackingState.Tracking)
                {
                    FitToScanOverlay.SetActive(false);
                    return;
                }
            }

            FitToScanOverlay.SetActive(true);
        }
        /// <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;
            }

            if (borrar)
            {
                oldRoom = -1;
                room    = -1;

                oldCharacter = -1;
                character    = -1;

                oldGun = -1;
                gun    = -1;

                GameLogic.sol.SetRoom(GameLogic.Hab.Emp);
                GameLogic.sol.SetCharacter(GameLogic.Car.Emp);
                GameLogic.sol.SetGun(GameLogic.Arm.Emp);

                if (BoardVisualizer.scanwrong)
                {
                    GameLogic.turnFinished = true;
                }

                borrar = false;

                ButtonsController.primeraVezScan = false;

                Scene scene = SceneManager.GetActiveScene();
                SceneManager.LoadScene(scene.name);
            }

            if (!scan)
            {
                GameLogic.sol.SetRoom(GameLogic.Hab.Emp);
                GameLogic.sol.SetCharacter(GameLogic.Car.Emp);
                GameLogic.sol.SetGun(GameLogic.Arm.Emp);
            }

            // 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 (AugmentedImage image in m_TempAugmentedImages)
            {
                AugmentedImageVisualizer 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);
                    if (image.Name == "tablero")
                    {
                        visualizer = (BoardVisualizer)Instantiate(AugmentedBoardVisualizerPrefab, anchor.transform);
                    }
                    else if (scan)
                    {
                        visualizer = (CardsVisualizer)Instantiate(AugmentedCardsVisualizerPrefab, anchor.transform);

                        if (image.Name == "rojo" || image.Name == "amarillo" || image.Name == "azul" || image.Name == "verde" || image.Name == "morado" || image.Name == "rosa")
                        {
                            oldCharacter = character;
                            character    = image.DatabaseIndex;

                            if (oldCharacter != -1)
                            {
                                AugmentedImageVisualizer tmp = m_Visualizers[oldCharacter];
                                GameObject.Destroy(tmp.gameObject);
                                m_Visualizers.Remove(oldCharacter);
                            }
                        }
                        else if (image.Name == "candelabro" || image.Name == "cuerda" || image.Name == "herramienta" || image.Name == "knife" || image.Name == "pistola" || image.Name == "tuberia")
                        {
                            oldGun = gun;
                            gun    = image.DatabaseIndex;

                            if (oldGun != -1)
                            {
                                AugmentedImageVisualizer tmp = m_Visualizers[oldGun];
                                GameObject.Destroy(tmp.gameObject);
                                m_Visualizers.Remove(oldGun);
                            }
                        }
                        else if (image.Name == "cocina" || image.Name == "comedor" || image.Name == "vestibulo" || image.Name == "estudio" || image.Name == "invernadero" || image.Name == "salabaile" || image.Name == "salabillar" || image.Name == "biblioteca" || image.Name == "salon")
                        {
                            oldRoom = room;
                            room    = image.DatabaseIndex;

                            if (oldRoom != -1)
                            {
                                AugmentedImageVisualizer tmp = m_Visualizers[oldRoom];
                                GameObject.Destroy(tmp.gameObject);
                                m_Visualizers.Remove(oldRoom);
                            }
                        }
                    }
                    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);
        }
        /// <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();
            }

            // Only allow the screen to sleep when not tracking.
            if (Session.Status != SessionStatus.Tracking)
            {
                Screen.sleepTimeout = SleepTimeout.SystemSetting;
            }
            else
            {
                Screen.sleepTimeout = SleepTimeout.NeverSleep;
            }

            // 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.
            //for (int i = 0; i< m_TempAugmentedImages.Count;  i++)// image in m_TempAugmentedImages)
            //{
            //    var image1 = m_TempAugmentedImages[0];
            //    AugmentedImageVisualizer visualizer1 = null;
            //    m_Visualizers.TryGetValue(image1.DatabaseIndex, out visualizer1);

            //    if (image1.TrackingState == TrackingState.Tracking && visualizer1 == null)
            //    {
            //        Create an anchor to ensure that ARCore keeps tracking this augmented image.
            //        Anchor anchor = image1.CreateAnchor(image1.CenterPose);
            //        visualizer1 = (AugmentedImageVisualizer)Instantiate(
            //            ImageVisualizerPrefab1, anchor.transform);
            //        visualizer1.Image = image1;
            //        m_Visualizers.Add(image1.DatabaseIndex, visualizer1);
            //    }
            //    else if (image1.TrackingState == TrackingState.Stopped && visualizer1 != null)
            //    {
            //        m_Visualizers.Remove(image1.DatabaseIndex);
            //        GameObject.Destroy(visualizer1.gameObject);
            //    }

            //    var image2 = m_TempAugmentedImages[1];
            //    AugmentedImageVisualizer visualizer2 = null;
            //    m_Visualizers.TryGetValue(image2.DatabaseIndex, out visualizer2);

            //    if (image2.TrackingState == TrackingState.Tracking && visualizer2 == null)
            //    {
            //        Create an anchor to ensure that ARCore keeps tracking this augmented image.
            //    Anchor anchor = image2.CreateAnchor(image2.CenterPose);
            //        visualizer2 = (AugmentedImageVisualizer)Instantiate(
            //            ImageVisualizerPrefab1, anchor.transform);
            //        visualizer2.Image = image2;
            //        m_Visualizers.Add(image2.DatabaseIndex, visualizer2);
            //    }
            //    else if (image2.TrackingState == TrackingState.Stopped && visualizer2 != null)
            //    {
            //        m_Visualizers.Remove(image2.DatabaseIndex);
            //        GameObject.Destroy(visualizer2.gameObject);
            //    }
            //}

            foreach (var image in m_TempAugmentedImages)
            {
                int i = image.DatabaseIndex;
                AugmentedImageVisualizer visualizer = null;
                m_Visualizers.TryGetValue(image.DatabaseIndex, out visualizer);
                if (image.TrackingMethod == AugmentedImageTrackingMethod.FullTracking && visualizer == null)
                {
                    // Create an anchor to ensure that ARCore keeps tracking this augmented image.
                    Anchor anchor = image.CreateAnchor(image.CenterPose);

                    visualizer = (AugmentedImageVisualizer)Instantiate(
                        AugmentedImageVisualizerPrefab[i], 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);
        }
Ejemplo n.º 7
0
        public void Update()
        {
            // Only allow the screen to sleep when not tracking.
            if (Session.Status != SessionStatus.Tracking)
            {
                Screen.sleepTimeout = SleepTimeout.SystemSetting;
            }
            else
            {
                Screen.sleepTimeout = SleepTimeout.NeverSleep;
            }

            if (!isfinished)
            {
                // Debug.Log("Is not finished " + Time.realtimeSinceStartup);
                // 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.
                if (!SimulateWithMouse)
                {
                    foreach (var image in m_TempAugmentedImages)
                    {
                        AugmentedImageVisualizer visualizer = null;
                        GameObject fapsMachine = null;
                        m_Visualizers.TryGetValue(image.DatabaseIndex, out visualizer);
                        if ((FloorSurface_Machine != null) && (image.TrackingState == TrackingState.Tracking && visualizer == null))
                        {
                            // Create FAPS Machine GameObject and the image fully tracked
                            if (fapsMachine == null && image.TrackingMethod == AugmentedImageTrackingMethod.FullTracking)
                            {
                                User_GUI.GUI_Debug("Found Image now");
                                // Create an anchor to ensure that ARCore keeps tracking this augmented image.
                                Anchor anchor = image.CreateAnchor(image.CenterPose);
                                visualizer = (AugmentedImageVisualizer)Instantiate(
                                    AugmentedImageVisualizerPrefab, anchor.transform);
                                visualizer.Image = image;
                                m_Visualizers.Add(image.DatabaseIndex, visualizer);

                                StartCoroutine(InstantiateWithDelay(image));
                                isfinished = true;
                                User_GUI.GUI_Debug("Image: " + database[image.DatabaseIndex].Name);
                            }
                            else
                            {
                                User_GUI.GUI_Debug("Image isnt tracked right");
                            }
                        }
                        else if (image.TrackingState == TrackingState.Stopped && visualizer != null)
                        {
                            User_GUI.GUI_Debug("Destroying");
                            m_Visualizers.Remove(image.DatabaseIndex);
                            GameObject.Destroy(visualizer.gameObject);
                        }
                        // else User_GUI.GUI_Debug("Hit surface first");
                    }
                }
                else if (Input.GetMouseButtonDown(1))
                {
                    GameObject fapsMachine = null;
                    if (FloorSurface_Machine != null && fapsMachine == null)
                    {
                        StartCoroutine(InstantiateWithDelay(null));
                        isfinished = true;
                        FitToScanOverlay.SetActive(false);
                    }
                }

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

                if (!FitToScanOverlay.activeInHierarchy && FloorSurface_Machine != null)
                {
                    User_GUI.Set_HelperMsg("Now Scan your reference image in order to auto - create the CAD machine");
                    FitToScanOverlay.SetActive(true);
                }
            }


            ///////////////////////////////// Handling of Touch Interactions

            if (!isfinished && !SimulateWithMouse && !UserGUI.EnableCloud)
            {
                Touch touch;
                if ((Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began))
                {
                    return;
                }

                // Should not handle input if the player is pointing on UI.
                if (EventSystem.current.IsPointerOverGameObject(touch.fingerId))
                {
                    return;
                }

                // Raycast against the location the player touched to search for planes.

                TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon | TrackableHitFlags.FeaturePointWithSurfaceNormal;

                if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit))
                {
                    // Use hit pose and camera pose to check if hittest is from the
                    // back of the plane, if it is, no need to create the anchor.
                    if ((hit.Trackable is DetectedPlane))
                    {
                        if (FloorSurface_Machine == null)
                        {
                        }

                        FloorSurface_Machine = hit.Trackable;
                        User_GUI.GUI_Debug("Hit detected Plane");
                    }
                    else
                    {
                        User_GUI.GUI_Debug("Hit something");
                    }
                }
            }
            else if (!UserGUI.EnableCloud)
            {
                if (!isfinished && Input.GetMouseButtonDown(0))
                {
                    TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon | TrackableHitFlags.FeaturePointWithSurfaceNormal;

                    if (Frame.Raycast(Input.mousePosition.x, Input.mousePosition.z, raycastFilter, out hit))
                    {
                        if ((hit.Trackable is DetectedPlane))
                        {
                            if (FloorSurface_Machine == null)
                            {
                            }

                            FloorSurface_Machine = hit.Trackable;
                            User_GUI.GUI_Debug("Hit detected Plane");
                        }
                        else
                        {
                            User_GUI.GUI_Debug("Hit something");
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public void setAugmentedImage(AugmentedImage image, AugmentedImageVisualizer visualizer, AugmentedImageVisualizer prefab)
        {
            Anchor anchor = image.CreateAnchor(image.CenterPose);

            visualizer       = (AugmentedImageVisualizer)Instantiate(prefab, anchor.transform);
            visualizer.Image = image;
            m_Visualizers.Add(image.DatabaseIndex, visualizer);
        }
        /// The Unity Update method.
        /// </summary>
        public void Update()
        {
            print("Print Start");
            Debug.Log("log Start");
            // 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 (Touch touch in Input.touches)
            {
                Input.GetTouch(0);
                print(touch.tapCount);
                print("Hello");
                Debug.Log("Touching");
            }
            foreach (var image in m_TempAugmentedImages)
            {
                AugmentedImageVisualizer visualizer = null;
                m_Visualizers.TryGetValue(image.DatabaseIndex, out visualizer);
                if (image.TrackingState == TrackingState.Tracking && visualizer == null)
                {
                    AugmentedImageVisualizerPrefab.gameObject.SetActive(true);
                    // Create an anchor to ensure that ARCore keeps tracking this augmented image.
                    Anchor anchor = image.CreateAnchor(image.CenterPose);
                    //visualizer = (AugmentedImageVisualizer)Instantiate(AugmentedImageVisualizerPrefab, anchor.transform);

                    visualizer = (AugmentedImageVisualizer)Instantiate(prefabs[image.DatabaseIndex], anchor.transform);


                    visualizer.Image = image;
                    m_Visualizers.Add(image.DatabaseIndex, visualizer);
                }
                if (Input.touchCount > 0)
                {
                    Touch touch = Input.GetTouch(0);
                    m_Visualizers.Remove(image.DatabaseIndex);
                    GameObject.Destroy(visualizer.gameObject);
                }
                else if ((image.TrackingState == TrackingState.Stopped || image.TrackingState == TrackingState.Paused) && 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);
        }
Ejemplo n.º 10
0
        /// <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();
            }

            // Only allow the screen to sleep when not tracking.
            if (Session.Status != SessionStatus.Tracking)
            {
                Screen.sleepTimeout = SleepTimeout.SystemSetting;
            }
            else
            {
                Screen.sleepTimeout = SleepTimeout.NeverSleep;
            }

            // Get updated augmented images for this frame.
            Session.GetTrackables <AugmentedImage>(
                _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 _tempAugmentedImages)
            {
                AugmentedImageVisualizer visualizer = null;
                _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 = (AugmentedImageVisualizer)Instantiate(
                        AugmentedImageVisualizerPrefab, anchor.transform);
                    visualizer.Image = image;
                    LateImage        = image;
                    _visualizers.Add(image.DatabaseIndex, visualizer);
                    //最後に読み取ったvisualizerを保存

                    CurrentVisualizer = visualizer;
                }
                else if (image.TrackingState == TrackingState.Stopped && visualizer != null)
                {
                    _visualizers.Remove(image.DatabaseIndex);
                    GameObject.Destroy(visualizer.gameObject);
                }
            }
            if (Distination == 0 && NaviFlag == false && GoalFlag == false && CurrentVisualizer != null)
            {
                DebugText.text = "目的地を\n選択してください";
            }
            if (_visualizers.Count >= 2)
            {
                //最初にスポーンさせたオブジェクトを非表示にする
                _visualizers.First().Value.gameObject.SetActive(false);

                //そのオブジェクトの情報を持つ要素を削除
                _visualizers.Remove(_visualizers.First().Key);

                //最後のオブジェクトを現在のオブジェクトにする
                CurrentVisualizer = _visualizers.First().Value;

                //最新の現在地からルートを再計算
                if (NaviFlag == true && int.Parse(CurrentVisualizer.Image.Name.Substring(1, CurrentVisualizer.Image.Name.Length - 1)) != Distination)
                {
                    Navigate(Distination);
                }
            }

            if (NaviFlag == true)
            {
                DebugText.text = "方角表示に従って\n移動してください";
                //DebugText.text = "現在地:"+CurrentVisualizer.Image.Name.Substring(1,CurrentVisualizer.Image.Name.Length - 1);
                //DebugText.text += "@"+Distination.ToString();
                foreach (var rt in result.cost)
                {
                    //DebugText.text += "[" + rt.ToString()+"]";
                }
                if (int.Parse(CurrentVisualizer.Image.Name.Substring(1, CurrentVisualizer.Image.Name.Length - 1)) == Distination)
                {
                    DebugText.text = "目的地に到着しました";
                    _visualizers.First().Value.gameObject.transform.position = CurrentVisualizer.Image.CenterPose.position;
                    //目的地についたので初期化
                    Distination = 0;
                    NaviFlag    = false;
                    GoalFlag    = true;
                    //次のチェックポイントにマーカーを設置する(しなおす)
                    _visualizers.TryGetValue(LateImage.DatabaseIndex, out visualizer2);
                    visualizer2.gameObject.transform.position = CurrentVisualizer.DistinationMarker.transform.localPosition;
                    return;
                }
                //経路結果から設置すべき座標をオブジェクトの座標に更新する
                else if (result.cost.Count >= 2)
                {
                    //まだ目的地に着いていないので次のチェックポイントへ
                    ConvCoodinate(result.cost[1], Yanomuki, CurrentVisualizer.DistinationMarker.transform);
                }

                //次のチェックポイントに方角表示オブジェクトを向ける
                arrowController();
            }


            // Show the fit-to-scan overlay if there are no images that are Tracking.
            foreach (var visualizer in _visualizers.Values)
            {
                if (visualizer.Image.TrackingState == TrackingState.Tracking)
                {
                    FitToScanOverlay.SetActive(false);
                    return;
                }
            }

            FitToScanOverlay.SetActive(true);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// The Unity Update method.
        /// </summary>
        public void Update()
        {
            // Exit the app when the 'back' button is pressed.
            if (Input.GetKey(KeyCode.Escape))
            {
                SceneManager.LoadScene("Menu_Scene");
                //Application.Quit();
            }

            // Only allow the screen to sleep when not tracking.
            if (Session.Status != SessionStatus.Tracking)
            {
                Screen.sleepTimeout = SleepTimeout.SystemSetting;
            }
            else
            {
                Screen.sleepTimeout = SleepTimeout.NeverSleep;
            }

            // 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)
            {
                AugmentedImageVisualizer visualizer = null;
                m_Visualizers.TryGetValue(image.DatabaseIndex, out visualizer);


                if (image.TrackingState == TrackingState.Tracking && visualizer == null)
                {
                    if (image.TrackingMethod == AugmentedImageTrackingMethod.FullTracking)
                    {
                        Anchor anchor = image.CreateAnchor(image.CenterPose);
                        visualizer = (AugmentedImageVisualizer)Instantiate(
                            AugmentedImageVisualizerPrefab, anchor.transform);
                        visualizer.Image = image;

                        m_Visualizers.Add(image.DatabaseIndex, visualizer);
                    }
                }
                else
                {
                    if (image.TrackingMethod == AugmentedImageTrackingMethod.LastKnownPose)
                    {
                        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);
        }
Ejemplo n.º 12
0
        /// <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();
            }

            // 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)
            {
                AugmentedImageVisualizer 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 = (AugmentedImageVisualizer)Instantiate(
                        AugmentedImageVisualizerPrefab, 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);
                    if (visualizer.Image.Name == "Earth")
                    {
                    }
                    return;
                }
            }

            FitToScanOverlay.SetActive(true);

            //detect gem taps
            //RaycastHit Hit;
            if (Physics.Raycast(transform.position, transform.forward, 2))
            {
                Ray        raycast = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
                RaycastHit raycastHit;
                if (Physics.Raycast(raycast, out raycastHit))
                {
                    Debug.Log("Something Hit");

                    if (raycastHit.collider.CompareTag("DivergentGem"))
                    {
                        raycastHit.collider.gameObject.transform.GetChild(0).gameObject.SetActive(true);
                    }

                    if (raycastHit.collider.CompareTag("SubductingGem"))
                    {
                        raycastHit.collider.gameObject.transform.GetChild(0).gameObject.SetActive(true);
                    }

                    if (raycastHit.collider.CompareTag("TransformGem"))
                    {
                        raycastHit.collider.gameObject.transform.GetChild(0).gameObject.SetActive(true);
                    }
                }
            }
        }
Ejemplo n.º 13
0
        private void _UpdateApplicationLifecycle()
        {
            // Exit the app when the 'back' button is pressed.
            if (Input.GetKey(KeyCode.Escape))
            {
                Application.Quit();
            }

            // Only allow the screen to sleep when not tracking.
            if (Session.Status != SessionStatus.Tracking)
            {
                Screen.sleepTimeout = SleepTimeout.SystemSetting;
            }
            else
            {
                Screen.sleepTimeout = SleepTimeout.NeverSleep;
            }

            if (m_IsQuitting)
            {
                return;
            }

            if (Session.Status == SessionStatus.ErrorPermissionNotGranted)
            {
                _ShowAndroidToastMessage("Camera permission is needed to run this application.");
                m_IsQuitting = true;
                Invoke("_DoQuit", 0.5f);
            }
            else if (Session.Status.IsError())
            {
                _ShowAndroidToastMessage(
                    "ARCore encountered a problem connecting.  Please start the app again.");
                m_IsQuitting = true;
                Invoke("_DoQuit", 0.5f);
            }

            // 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)
            {
                AugmentedImageVisualizer 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);
                    _imageAnchor = anchor;

                    _imageAnchor.transform.forward = anchor.transform.forward;

                    visualizer = (AugmentedImageVisualizer)Instantiate(
                        AugmentedImageVisualizerPrefab, 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 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)
            {
                AugmentedImageVisualizer visualizer = null;
                m_Visualizers.TryGetValue(image.DatabaseIndex, out visualizer);
                if (image.TrackingState == TrackingState.Tracking && visualizer == null)
                {
                    AugmentedImageVisualizerPrefab.gameObject.SetActive(true);
                    // Create an anchor to ensure that ARCore keeps tracking this augmented image.
                    Anchor anchor = image.CreateAnchor(image.CenterPose);
                    visualizer       = (AugmentedImageVisualizer)Instantiate(AugmentedImageVisualizerPrefab, anchor.transform);
                    visualizer.Image = image;
                    m_Visualizers.Add(image.DatabaseIndex, visualizer);
                    fitFlag = false;
                }
                else if (image.TrackingState == TrackingState.Stopped && visualizer != null)
                {
                    m_Visualizers.Remove(image.DatabaseIndex);
                    GameObject.Destroy(visualizer.gameObject);
                    fitFlag = false;
                }
            }

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

            if (!fitFlag)
            {
                fitTime = Time.time;
                fitFlag = true;
            }


            if ((Time.time >= 30) && fitTime != 0)
            {
                SceneManager.LoadScene("AugmentedImage");
            }
            else
            {
                FitToScanOverlay.SetActive(true);
            }
        }
        /// <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)
            {
                AugmentedImageVisualizer visualizer = null;
                //Camera.current;
                m_Visualizers.TryGetValue(image.DatabaseIndex, out visualizer);
                if (image.TrackingState == TrackingState.Tracking && currImage != image.Name)
                {
                    currImage      = image.Name;
                    imageText.text = image.Name;
                    //imageText.text = "image" + image.Name;
                    visualizer.Destroy();
                    m_Visualizers.Clear();
                    GameObject.Destroy(visualizer.gameObject);

                    float  halfWidth  = image.ExtentX / 2;
                    float  halfHeight = image.ExtentZ / 2;
                    Anchor anchor     = image.CreateAnchor(image.CenterPose);

                    visualizer = (AugmentedImageVisualizer)Instantiate(
                        AugmentedImageVisualizerPrefab, anchor.transform);
                    visualizer.Image         = image;
                    visualizer.position      = new float[] { 0.1f, 0.1f, 0.1f };
                    visualizer.text          = text;
                    visualizer.positionsList = positionsList;
                    visualizer.spheresList   = spheresList;
                    visualizer.fireList      = fireList;
                    visualizer.MusicClip     = MusicClip;
                    m_Visualizers.Add(image.DatabaseIndex, visualizer);

                    FirebaseDatabase.DefaultInstance
                    .GetReference("audio")
                    .GetValueAsync().ContinueWith(task => {
                        if (task.IsFaulted)
                        {
                            // Handle the error...
                        }
                        else if (task.IsCompleted)
                        {
                            DataSnapshot snapshot      = task.Result;
                            DataSnapshot imageSnapshot = snapshot.Child(currImage);
                            foreach (DataSnapshot c in imageSnapshot.Children)
                            {
                                double value0 = (double)c.Child("0").Value;
                                double value1 = (double)c.Child("1").Value;
                                double value2 = (double)c.Child("2").Value;
                                positionsList.Add(new float[] { (float)value0, (float)value1, (float)value2 });
                                keysList.Add(c.Key);
                            }
                        }
                    });
                }
                if (image.TrackingState == TrackingState.Tracking && visualizer == null)
                {
                    // Create an anchor to ensure that ARCore keeps tracking this augmented image.
                    float  halfWidth  = image.ExtentX / 2;
                    float  halfHeight = image.ExtentZ / 2;
                    Anchor anchor     = image.CreateAnchor(image.CenterPose);

                    visualizer = (AugmentedImageVisualizer)Instantiate(
                        AugmentedImageVisualizerPrefab, anchor.transform);
                    visualizer.Image         = image;
                    visualizer.position      = new float[] { 0.1f, 0.1f, 0.1f };
                    visualizer.text          = text;
                    visualizer.positionsList = positionsList;
                    visualizer.spheresList   = spheresList;
                    visualizer.fireList      = fireList;
                    visualizer.keysList      = keysList;
                    visualizer.MusicClip     = MusicClip;
                    m_Visualizers.Add(image.DatabaseIndex, visualizer);
                    if (currImage != image.Name)
                    {
                        visualizer.Destroy();
                        m_Visualizers.Clear();
                        GameObject.Destroy(visualizer.gameObject);
                        //GameObject.Destroy(visualizer.gameObject);
                    }
                    currImage      = image.Name;
                    imageText.text = image.Name;

                    // You can convert it back to an array if you would like to


                    FirebaseDatabase.DefaultInstance
                    .GetReference("audio")
                    .GetValueAsync().ContinueWith(task => {
                        if (task.IsFaulted)
                        {
                            // Handle the error...
                        }
                        else if (task.IsCompleted)
                        {
                            DataSnapshot snapshot = task.Result;
                            foreach (DataSnapshot c in snapshot.Children)
                            {
                                double value0 = (double)c.Child("0").Value;
                                double value1 = (double)c.Child("1").Value;
                                double value2 = (double)c.Child("2").Value;
                                positionsList.Add(new float[] { (float)value0, (float)value1, (float)value2 });
                                keysList.Add(c.Key);
                            }
                        }
                    });



                    //text.text = text.text + " hello";
                    foreach (var device in Microphone.devices)
                    {
                        text.text = text.text + " " + device;
                    }

                    //}
                }
                else if (image.TrackingState == TrackingState.Stopped && visualizer != null)
                {
                    m_Visualizers.Remove(image.DatabaseIndex);
                    GameObject.Destroy(visualizer.gameObject);
                    //visualizer.Destroy();
                }
            }
            // 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);
        }
Ejemplo n.º 16
0
        /// <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();
            }

            // Only allow the screen to sleep when not tracking.
            if (Session.Status != SessionStatus.Tracking)
            {
                Screen.sleepTimeout = SleepTimeout.SystemSetting;
            }
            else
            {
                Screen.sleepTimeout = SleepTimeout.NeverSleep;
            }

            // 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)
            {
                AugmentedImageVisualizer 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 = (AugmentedImageVisualizer)Instantiate(
                 *      AugmentedImageVisualizerPrefab, 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);
                 * }// */

                if (image.TrackingState == TrackingState.Tracking && visualizer == null && image.TrackingMethod == AugmentedImageTrackingMethod.FullTracking)
                {
                    // Create an anchor to ensure that ARCore keeps tracking this augmented image.
                    Anchor anchor = image.CreateAnchor(image.CenterPose);
                    visualizer = (AugmentedImageVisualizer)Instantiate(
                        AugmentedImageVisualizerPrefab, anchor.transform);
                    visualizer.Image = image;
                    m_Visualizers.Add(image.DatabaseIndex, visualizer);

                    //var nativeSession = GoogleARCoreInternal.LifecycleManager.Instance.NativeSession;
                    //if (nativeSession == null)
                    //{
                    //    //return new CameraIntrinsics();
                    //}
                    //var cameraHandle = nativeSession.FrameApi.AcquireCamera();

                    //CameraIntrinsics result =
                    //    nativeSession.CameraApi.GetImageIntrinsics(cameraHandle);
                }

                //marker is not tracked in camera output
                else if (image.TrackingMethod == AugmentedImageTrackingMethod.LastKnownPose && 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);
        }
        /// <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();
            }

            // Only allow the screen to sleep when not tracking.
            if (Session.Status != SessionStatus.Tracking)
            {
                Screen.sleepTimeout = SleepTimeout.SystemSetting;
            }
            else
            {
                Screen.sleepTimeout = SleepTimeout.NeverSleep;
            }

            // 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)
            {
                AugmentedImageVisualizer visualizer = null;
                //Object3d obj3d=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 = (AugmentedImageVisualizer)Instantiate(
                        AugmentedImageVisualizerPrefab, anchor.transform);

                    //obj3d=(Object3d)Instantiate(Object3dPrefab,anchor.transform);

                    visualizer.Image = image;
                    visualizer.transform.localScale = new Vector3(image.ExtentX * 10, 1, image.ExtentZ * 10);
                    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);
        }
Ejemplo n.º 18
0
        public void addVisualizerImage(AugmentedImage image, AugmentedImageVisualizer visualizer)
        {
            // Create an anchor to ensure that ARCore keeps tracking this augmented image.
            switch (image.Name)
            {
            case "cat":
                setAugmentedImage(image, visualizer, prefabs[0]);
                break;

            case "duck":
                setAugmentedImage(image, visualizer, prefabs[1]);
                break;

            case "frog":
                setAugmentedImage(image, visualizer, prefabs[2]);
                break;

            case "horse":
                setAugmentedImage(image, visualizer, prefabs[3]);
                break;

            case "koala":
                setAugmentedImage(image, visualizer, prefabs[4]);
                break;

            case "monkey":
                setAugmentedImage(image, visualizer, prefabs[5]);
                break;

            case "parrot":
                setAugmentedImage(image, visualizer, prefabs[6]);
                break;

            case "seahorse":
                setAugmentedImage(image, visualizer, prefabs[7]);
                break;

            case "shark":
                setAugmentedImage(image, visualizer, prefabs[8]);
                break;

            case "turtle":
                setAugmentedImage(image, visualizer, prefabs[9]);
                break;

            case "deer":
                setAugmentedImage(image, visualizer, prefabs[10]);
                break;

            case "dog":
                setAugmentedImage(image, visualizer, prefabs[11]);
                break;

            case "fish":
                setAugmentedImage(image, visualizer, prefabs[12]);
                break;

            case "kangaroo":
                setAugmentedImage(image, visualizer, prefabs[13]);
                break;

            case "panda":
                setAugmentedImage(image, visualizer, prefabs[14]);
                break;

            case "sheep":
                setAugmentedImage(image, visualizer, prefabs[15]);
                break;

            default:
                break;
            }
        }