Exemple #1
0
        public void DropHamper()
        {
#if !UNITY_EDITOR
            if (Input.GetTouch(0).phase == TouchPhase.Began)
#endif
            if (Application.isEditor && Input.GetMouseButtonDown(0))
            {
                GameObject hamper;
                hamper = Instantiate(hamperPrefab, FirstPersonCamera.transform.position, Quaternion.identity);
                Debug.Log("Dropped hamper");
            }
        }
Exemple #2
0
 public void MuthuFunc()
 {
     if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
     {
         RaycastHit hit;
         Ray        ray = FirstPersonCamera.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(ray, out hit, rayLength, layer))
         {
             for (int i = 0; i < a.Length; i++)
             {
                 if (hit.collider.name == "Pic" + i)
                 {
                     a[i].gameObject.SetActive(true);
                 }
                 a[i].gameObject.SetActive(false);
             }
         }
     }
 }
Exemple #3
0
        /// <summary>
        /// The Unity Update() method.
        /// </summary>
        public void Update()
        {
            _UpdateApplicationLifecycle();

            // Hide snackbar when currently tracking at least one plane.
            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;
                }
            }

            SearchingForPlaneUI.SetActive(showSearchingUI);


            // if there is phone input....
            Touch touch;

            if (Input.touchCount < 0)
            {
                touch = Input.GetTouch(0);
                if (touch.phase != TouchPhase.Began)
                {
                    return;
                }
                // 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))
                {
                    // 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) &&
                        Vector3.Dot(FirstPersonCamera.transform.position - hit.Pose.position,
                                    hit.Pose.rotation * Vector3.up) < 0)
                    {
                        Debug.Log("Hit at back of the current DetectedPlane");
                    }
                    else
                    {
                        // Instantiate Andy model at the hit pose.
                        // todo do things here
                        //var andyObject = Instantiate(CoinsPrefab, hit.Pose.position, hit.Pose.rotation);
                        var andyObject = Instantiate(AndyAndroidPrefab, hit.Pose.position, hit.Pose.rotation);

                        // Compensate for the hitPose rotation facing away from the raycast (i.e. camera).
                        andyObject.transform.Rotate(0, k_ModelRotation, 0, Space.Self);

                        // Create an anchor to allow ARCore to track the hitpoint as understanding of the physical
                        // world evolves.
                        var anchor = hit.Trackable.CreateAnchor(hit.Pose);

                        // Make Andy model a child of the anchor.
                        andyObject.transform.parent = anchor.transform;
                    }
                }
            }
            else if (Input.GetMouseButtonDown(0))
            {
                TrackableHit      hit;
                TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon |
                                                  TrackableHitFlags.FeaturePointWithSurfaceNormal;

                if (Frame.Raycast(Input.mousePosition.x, Input.mousePosition.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) &&
                        Vector3.Dot(FirstPersonCamera.transform.position - hit.Pose.position,
                                    hit.Pose.rotation * Vector3.up) < 0)
                    {
                        Debug.Log("Hit at back of the current DetectedPlane");
                    }
                    else
                    {
                        // Instantiate Andy model at the hit pose.
                        // todo do things here
                        //var andyObject = Instantiate(CoinsPrefab, hit.Pose.position, hit.Pose.rotation);
                        var andyObject = Instantiate(CoinsPrefab, hit.Pose.position, hit.Pose.rotation);

                        // Compensate for the hitPose rotation facing away from the raycast (i.e. camera).
                        andyObject.transform.Rotate(0, k_ModelRotation, 0, Space.Self);

                        // Create an anchor to allow ARCore to track the hitpoint as understanding of the physical
                        // world evolves.
                        var anchor = hit.Trackable.CreateAnchor(hit.Pose);

                        // Make Andy model a child of the anchor.
                        andyObject.transform.parent = anchor.transform;
                    }
                }
            }
        }