Пример #1
0
        public void Update()
        {
            if (Input.GetKey(KeyCode.Escape))
            {
                Application.Quit();
            }

            _QuitOnConnectionErrors();

            // Check that motion tracking is tracking.
            if (Session.Status != SessionStatus.Tracking)
            {
                const int lostTrackingSleepTimeout = 15;
                Screen.sleepTimeout = lostTrackingSleepTimeout;
                if (!m_IsQuitting && Session.Status.IsValid())
                {
                    // statusText.text = "Looking for surfaces";
                    //  SearchingForPlaneUI.SetActive(true);
                }

                return;
            }

            Screen.sleepTimeout = SleepTimeout.NeverSleep;

            // Iterate over planes found in this frame and instantiate corresponding GameObjects to visualize them.
            Session.GetTrackables <DetectedPlane>(m_NewPlanes, TrackableQueryFilter.New);
            for (int i = 0; i < m_NewPlanes.Count; i++)
            {
                // Instantiate a plane visualization prefab and set it to track the new plane. The transform is set to
                // the origin with an identity rotation since the mesh for our prefab is updated in Unity World
                // coordinates.
                GameObject planeObject = Instantiate(TrackedPlanePrefab, Vector3.zero, Quaternion.identity,
                                                     transform);
                planeObject.GetComponent <DetectedPlaneVisualizer>().Initialize(m_NewPlanes[i]);
            }

            // Disable the snackbar UI when no planes are valid.
            Session.GetTrackables <DetectedPlane>(m_AllPlanes);
            // bool showSearchingUI = true;
            for (int i = 0; i < m_AllPlanes.Count; i++)
            {
                if (m_AllPlanes[i].TrackingState == TrackingState.Tracking)
                {
                    // showSearchingUI = false;
                    break;
                }
            }



            if (placeState != PlaceState.SHOW && placeState != PlaceState.START)
            {
                Touch touch;
                if (Input.touchCount > 0)

                {
                    touch = Input.GetTouch(0);
                    numTouches++;
                    if (touch.phase == TouchPhase.Began)
                    {
                        //statusText.text = "num touches:" + numTouches.ToString();
                        // Raycast against the location the player touched to search for planes.


                        TrackableHit      hit;
                        TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon |
                                                          TrackableHitFlags.FeaturePointWithSurfaceNormal;

                        if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit))
                        {
                            //  statusText.text = "hit pos:" + hit.Pose.position.ToString();

                            // first touch, place the anchor
                            if (placeState == PlaceState.PLACE_ANCHOR)
                            {
                                roomStuffObject.SetActive(true);
                                // Create an anchor to allow ARCore to track the hitpoint as understanding of the physical
                                // world evolves.
                                anchor = hit.Trackable.CreateAnchor(hit.Pose);

                                roomStuffObject.transform.position = hit.Pose.position;
                                anchorPos = hit.Pose.position;
                                roomStuffObject.transform.parent = anchor.transform;
                                // statusText.text = utilObject.ReportLocation();
                                placeState    = PlaceState.PLACE_HEADING;
                                dataText.text = "Place 2nd Anchor";
                            } // if placestate.anch
                            else if (placeState == PlaceState.PLACE_HEADING)
                            {
                                orientPos = hit.Pose.position;
                                Quaternion newRot = Quaternion.LookRotation(anchorPos - orientPos, Vector3.up);
                                roomStuffObject.transform.rotation = newRot;
                                placeState    = PlaceState.SHOW;
                                dataText.text = "";
                                placeButton.gameObject.SetActive(false);
                                navMeshBuilder.BuildNavMeshes();

                                TourGuide.SetActive(true);
                            }
                        }
                        else
                        {
                            // statusText.text = "No Hit";
                        }
                    }
                }
            }
        }