// Update is called once per frame
        void Update()
        {
            // if you touch the screen
            if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
            {
                // getting touch position and marking time when you touch the screen
                touchTimeStart = Time.time;
                startPos       = Input.GetTouch(0).position;

                init = false;
            }

            // if you release your finger
            if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended)
            {
                // marking time when you release it
                touchTimeFinish = Time.time;

                // calculate swipe time interval
                timeInterval = touchTimeFinish - touchTimeStart;

                // getting release finger position
                endPos = Input.GetTouch(0).position;

                // calculating swipe direction in 2D space
                direction = startPos - endPos;

                // add force to balls rigidbody in 3D space depending on swipe time, direction and throw forces
                rb.isKinematic = false;
                rb.AddForce(-direction.x * throwForceInXandY, -direction.y * throwForceInXandY, throwForceInZ / timeInterval);

                // Destroy ball in 4 seconds
                Destroy(gameObject, 3f);
            }
        }
 // table 셋팅이 끝난 후에 클릭..
 void ObjectSelect()
 {
     if (Input.touchCount == 1)
     {
         RaycastHit hit;
         Ray        ray = FirstPersonCamera.ScreenPointToRay(Input.GetTouch(0).position);
         //Ray ray = FirstPersonCamera.ScreenPointToRay(Input.mousePosition);
         bool bCheck = Physics.Raycast(ray, out hit, 30f);
         if (true == bCheck)
         {
             int iLayer = hit.collider.gameObject.layer;
             if (11 == iLayer)                                                                                               // curry 선택시에
             {
                 //uiManager.SetTestText("Curry Select");
                 CurrySelect();
             }
             else if (12 == iLayer)                                                                                    // Rice Noodle 선택시...
             {
                 //uiManager.SetTestText("Rice Noodle Select");
                 RiceNoodleSelect();
             }
             else if (13 == iLayer)                                                                                      // China Noodle 선택시..
             {
                 //uiManager.SetTestText("China Noodle Select");
                 ChinaNoodleSelect();
             }
             else if (14 == iLayer)                                                                                         // Miso Soup 선택시...
             {
                 //uiManager.SetTestText("Miso Soup Select");
                 MisoSoupSelect();
             }
         }
     }
 }
예제 #3
0
        public void Update()
        {
            _UpdateApplicationLifecycle();

            // If the player has not touched the screen, we are done with this update.
            Touch touch;

            if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).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) && !gameStarted)
            {
                // 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
                {
                    if (!TestPhoneTilt.CheckTilt())
                    {
                        return;
                    }
                    //DetectedPlane myPlane = hit.Trackable as DetectedPlane;
                    //Debug.Log("jj_plane rotation_B: " + myPlane.CenterPose.rotation.eulerAngles);

                    // Instantiate track at the hit pose.
                    trackStart    = hit.Pose.position;
                    trackStart.y += .025f; //raise track a bit off the floor
                    GameObject nextTrack = Instantiate(myTrack[1], trackStart, Quaternion.Euler(0, FirstPersonCamera.transform.rotation.y, 0));
                    nextTrack.name = "Track#" + trackNumber;
                    trackNumber++;

                    // Create an anchor FOR TRACK to allow ARCore to track the hitpoint as understanding of the physical
                    // world evolves.
                    Pose anchorPose = new Pose(trackStart, nextTrack.transform.rotation);
                    anchor = hit.Trackable.CreateAnchor(anchorPose);   //anchorpose

                    // Make track a child of the anchor.
                    nextTrack.transform.parent = anchor.transform;

                    // Instantiate ball at the hit pose.
                    Vector3    nudgedPosition = new Vector3(trackStart.x, trackStart.y + nudgeBallUp, trackStart.z);
                    GameObject newBall        = Instantiate(myBall, nudgedPosition, nextTrack.transform.rotation); //hit.Pose.rotation   (new idea, rotation = camera.forward?)
                    numBallsOnTrack += 1;

                    gameStarted = true;
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Gets the delta touch as a percentage of the screen.
        /// </summary>
        /// <returns>The delta touch as a percentage of the screen.</returns>
        private float _GetTouchDelta()
        {
            Vector2 newTouch      = Input.GetTouch(0).position;
            Vector2 deltaPosition = newTouch - m_PreviousTouch;

            m_PreviousTouch = newTouch;
            if (Input.GetTouch(0).phase == TouchPhase.Began)
            {
                return(0);
            }

            switch (Screen.orientation)
            {
            case ScreenOrientation.LandscapeLeft:
                return(-deltaPosition.x / Screen.width);

            case ScreenOrientation.LandscapeRight:
                return(deltaPosition.x / Screen.width);

            case ScreenOrientation.Portrait:
                return(deltaPosition.y / Screen.height);

            case ScreenOrientation.PortraitUpsideDown:
                return(-deltaPosition.y / Screen.height);

            default:
                return(0);
            }
        }
예제 #5
0
        /// <summary>
        /// The Unity Update() method.
        /// </summary>
        public void Update()
        {
            Touch touch;

            if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began)
            {
                //タップしていなければ何もしない
                return;
            }


            TrackableHit      hit;
            TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon;

            if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit))
            {
                //タップしたら、アンカーを配置
                if ((hit.Trackable is DetectedPlane))
                {
                    if (DRBackground.GetComponent <DRController02>().label.Equals(test01))
                    {
                        var gameObject = Instantiate(ChairModel, hit.Pose.position, hit.Pose.rotation);
                        var anchor     = hit.Trackable.CreateAnchor(hit.Pose);
                        gameObject.transform.parent = anchor.transform;
                    }
                    else if (DRBackground.GetComponent <DRController02>().label.Equals(test02))
                    {
                        var gameObject = Instantiate(LaptopModel, hit.Pose.position, hit.Pose.rotation);
                        gameObject.transform.Rotate(0, 180.0f, 0, Space.Self);
                        var anchor = hit.Trackable.CreateAnchor(hit.Pose);
                        gameObject.transform.parent = anchor.transform;
                    }
                }
            }
        }
예제 #6
0
        /// <summary>
        /// The Unity Update() method.
        /// </summary>
        public void Update()
        {
            _UpdateApplicationLifecycle();

            // If the player has not touched the screen, we are done with this update.
            Touch touch;

            if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).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
                {
                    // Choose the Andy model for the Trackable that got hit.
                    GameObject prefab;
                    if (hit.Trackable is FeaturePoint)
                    {
                        prefab = AndyPointPrefab;
                    }
                    else
                    {
                        prefab = AndyPlanePrefab;
                    }

                    if (!spawned)
                    {
                        // Instantiate Andy model at the hit pose.
                        var andyObject = Instantiate(prefab, hit.Pose.position, hit.Pose.rotation);

                        // andyObject.name = "ReadyPlayerOne";
                        // 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;
                        spawned = true;
                    }
                }
            }
        }
예제 #7
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 the player has not touched the screen, we are done with this update.
            Touch touch;

            if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began)
            {
                return;
            }
        }
        /// <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 the player has not touched the screen, we are done with this update.
            Touch touch;

            if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).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.
                    //var andyObject = Instantiate(AndyAndroidPrefab, hit.Pose.position, hit.Pose.rotation);
                    AndyAndroidPrefab.transform.position = hit.Pose.position;                     //(FirstPersonCamera.transform.position + FirstPersonCamera.transform.forward*2);
                    AndyAndroidPrefab.transform.rotation = hit.Pose.rotation;
                    // Compensate for the hitPose rotation facing away from the raycast (i.e. camera).
                    AndyAndroidPrefab.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.
                    AndyAndroidPrefab.transform.parent = anchor.transform;
                }
            }
        }
예제 #9
0
        public void _PinchtoZoom()
        {
            if (Input.touchCount == 2)

            {
                // Store both touches.
                Touch touchZero = Input.GetTouch(0);
                Touch touchOne  = Input.GetTouch(1);

                // Find the position in the previous frame of each touch.
                Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
                Vector2 touchOnePrevPos  = touchOne.position - touchOne.deltaPosition;

                // Find the magnitude of the vector (the distance) between the touches in each frame.
                float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
                float touchDeltaMag     = (touchZero.position - touchOne.position).magnitude;

                // Find the difference in the distances between each frame.
                float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;


                float pinchAmount = deltaMagnitudeDiff * 0.02f * Time.deltaTime;
                object1.transform.localScale += new Vector3(pinchAmount, pinchAmount, pinchAmount);
                object2.transform.localScale += new Vector3(pinchAmount, pinchAmount, pinchAmount);
                object3.transform.localScale += new Vector3(pinchAmount, pinchAmount, pinchAmount);
            }
        }
예제 #10
0
        public void Update()
        {
            _UpdateApplicationLifecycle();
            Touch touch = new Touch();

            if (Input.touchCount == 1 && (touch = Input.GetTouch(0)).phase == TouchPhase.Began)
            {
                tapCount++;
            }
            if (tapCount > 0)
            {
                doubleTapTimer += Time.deltaTime;
            }
            if (tapCount >= 2)
            {
                DoStuff(touch);
                doubleTapTimer = 0.0f;
                tapCount       = 0;
            }
            if (doubleTapTimer > 0.5f)
            {
                doubleTapTimer = 0f;
                tapCount       = 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 the player has not touched the screen, we are done with this update.
         *  Touch touch;
         *  if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).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
         *      {
         *          // Choose the Andy model for the Trackable that got hit.
         *          GameObject prefab;
         *          if (hit.Trackable is FeaturePoint)
         *          {
         *              prefab = AndyPointPrefab;
         *          }
         *          else
         *          {
         *              prefab = AndyPlanePrefab;
         *          }
         *
         *          // Instantiate Andy model at the hit pose.
         *          var andyObject = Instantiate(prefab, 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;
         *      }
         *  }
         * }
         */
        public void Update()
        {
            _UpdateApplicationLifecycle();

            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);

            Touch touch;

            if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began)
            {
                return;
            }

            //下記コードによりタップする度にCubeを生成して前え飛ばす。サイズとか勢いは適当
            GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);

            cube.transform.position   = FirstPersonCamera.transform.TransformPoint(0, 0, 0.5f);
            cube.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
            cube.AddComponent <Rigidbody>();
            cube.GetComponent <Rigidbody>().useGravity = false;
            cube.GetComponent <Rigidbody>().AddForce(FirstPersonCamera.transform.TransformDirection(0, 1f, 2f), ForceMode.Impulse);
        }
예제 #12
0
        /// <summary>
        /// The Unity Update() method.
        /// </summary>
        public void Update()
        {
            _UpdateApplicationLifecycle();

            // If the player has not touched the screen, we are done with this update.
            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;
            }

            /*
             * if (Input.touchCount > 0 && (Input.touches[0].phase == TouchPhase.Began) && (GameObject.Find("capsule(Clone)").gameObject.activeSelf == false) && (GameObject.Find("test_capsule").gameObject.activeSelf == false))
             * {
             *  var anchor = Session.CreateAnchor(new Pose(FirstPersonCamera.transform.position, Quaternion.identity));
             *  var tmp_point = GameObject.Instantiate(capsule,new Vector3(0,0,3), Quaternion.identity, anchor.transform);
             * }*/
        }
예제 #13
0
        private void MovePlayer()
        {
            Touch touch;

            if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began)
            {
                return;
            }

            TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon | TrackableHitFlags.FeaturePointWithSurfaceNormal;

            if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit))
            {
                if (hit.Trackable is FeaturePoint || hit.Trackable is DetectedPlane)
                {
                    if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
                    {
                        Debug.Log("Touched position: " + hit.Pose.position);
                        var anchor = hit.Trackable.CreateAnchor(hit.Pose);
                        anchors.Add(anchor);
                        var currentAnchor = anchors[anchors.Count - 1];
                        Player.instance.SetPlayerPosition(currentAnchor.transform.position);
                        StartCoroutine("ClearAnchors");
                    }
                }
            }
        }
예제 #14
0
        /// <summary>
        /// The Unity Update() method.
        /// </summary>
        public void Update()
        {
            _UpdateApplicationLifecycle();

            // If we are not in hosting mode or the user has already placed an anchor then the update
            // is complete.
            //directly return if user already placed an anchor
            if (m_CurrentMode != ApplicationMode.Hosting || m_LastPlacedAnchor != null)
            {
                return;
            }

            // If the player has not touched the screen then the update is complete.
            Touch touch;

            if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began)
            {
                return;
            }

            //create an anchor where the player touched
            // Raycast against the location the player touched to search for planes.
            if (Application.platform != RuntimePlatform.IPhonePlayer)
            {
                TrackableHit hit;
                if (Frame.Raycast(touch.position.x, touch.position.y,
                                  TrackableHitFlags.PlaneWithinPolygon, out hit))
                {
                    m_LastPlacedAnchor = hit.Trackable.CreateAnchor(hit.Pose);
                }
            }
            else
            {
                Pose hitPose;
                if (m_ARKit.RaycastPlane(ARKitFirstPersonCamera, touch.position.x, touch.position.y, out hitPose))
                {
                    m_LastPlacedAnchor = m_ARKit.CreateAnchor(hitPose);
                }
            }

            //if there is already an anchor then create put the object on the anchor
            if (m_LastPlacedAnchor != null)
            {
                // Instantiate Andy model at the hit pose.
                var andyObject = Instantiate(_GetAndyPrefab(), m_LastPlacedAnchor.transform.position,
                                             m_LastPlacedAnchor.transform.rotation);

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

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

                //CmdSpawnMyUnit ();

                // Save cloud anchor.
                _HostLastPlacedAnchor();
            }
        }
예제 #15
0
        public void Update()
        {
            _UpdateApplicationLifecycle();
            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 the player has not touched the screen, we are done with this update.
            Touch touch;

            if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began)
            {
                return;
            }

            if (placedBox)
            {
                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))
            {
                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
                {
                    // Choose the Andy model for the Trackable that got hit.
                    GameObject prefab;

                    prefab = BoxPlanePrefab;

                    var andyObject = Instantiate(prefab, hit.Pose.position, hit.Pose.rotation);


                    var anchor = hit.Trackable.CreateAnchor(hit.Pose);

                    andyObject.transform.parent = anchor.transform;
                    placedBox = true;
                }
            }
        }
예제 #16
0
        private float originalTimeUntilRemove; //a number used to reset the time

        /* Update is called once per frame
         * If the user is tapping, we call AddObject()
         * Then, we call UpdateState to update our counter for deleting objects */
        void Update()
        {
            if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
            {
                AddObject();
            }
            UpdateState();
        }
예제 #17
0
        /// <summary>
        /// The Unity Update() method.
        /// </summary>
        public void Update()
        {
            _UpdateApplicationLifecycle();

            // If the player has not touched the screen, we are done with this update.
            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.
            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
                {
                    if (instantiatedObj != null)
                    {
                        instantiatedObj.transform.position = hit.Pose.position;
                    }
                    else
                    {
                        // Instantiate prefab at the hit pose.
                        instantiatedObj = Instantiate(GameObjectPrefab, hit.Pose.position, hit.Pose.rotation);

                        // Compensate for the hitPose rotation facing away from the raycast (i.e.
                        // camera).
                        instantiatedObj.transform.Rotate(0, k_PrefabRotation, 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 game object a child of the anchor.
                        instantiatedObj.transform.parent = anchor.transform;
                    }
                }
            }
        }
예제 #18
0
        void screenTouched()
        {
            // If the player has not touched the screen, we are done with this update.
            Touch touch = Input.GetTouch(0);
            //if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).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
                {
                    if (hit.Trackable is DetectedPlane)
                    {
                        DetectedPlane plane = (DetectedPlane)hit.Trackable;
                        if (plane.PlaneType == DetectedPlaneType.Vertical)
                        {
                            //Set target to point
                            circleTarget.transform.position = hit.Pose.position;
                            Quaternion targetQuaternion = Quaternion.Euler(90,//hit.Pose.rotation.eulerAngles.x,
                                                                           hit.Pose.rotation.eulerAngles.y,
                                                                           hit.Pose.rotation.eulerAngles.z
                                                                           );

                            circleTarget.transform.rotation = targetQuaternion;

                            // 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 target model a child of the anchor.
                            circleTarget.transform.parent = anchor.transform;
                            circleTarget.transform.Rotate(90, 180, 0);
                        }
                        else
                        {
                            //Cannot place dartboard on floor
                        }
                    }
                }
            }
        }
예제 #19
0
        /// <summary>
        /// The Unity Update() method.
        /// </summary>
        public void Update()
        {
            _UpdateApplicationLifecycle();

            if (placeMap)
            {
                ShowMapPlaceholder();
            }

            // If the player has not touched the screen, we are done with this update.
            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;
            }

            Debug.Log("TAPPPPPPPPP");

            if (placeMap && mapInstance != null)
            {
                placeMap = false;
                // Hide AR planes
                GameObject.Find("Plane Generator").SetActive(false);

                // Hide panel and show StartButton if user is HOST
                PlaceMapPanel.SetActive(false);
                NetworkManagerWakaMole networkManager = NetworkManagerWakaMole.singleton as NetworkManagerWakaMole;
                foreach (GameObject gamePlayer in networkManager.GamePlayers)
                {
                    PlayerScript player = gamePlayer.GetComponent <PlayerScript>();
                    if (player.isLocalPlayer && player.isHost)
                    {
                        StartGameButton.SetActive(true);
                    }
                }

                return;
            }

            // Raycast against the location the player touched to search for objects
            RaycastHit hit = new RaycastHit();
            Ray        ray = FirstPersonCamera.ScreenPointToRay(touch.position);

            if (Physics.Raycast(ray, out hit))
            {
                hit.transform.gameObject.SendMessage("OnTouchDetected");
            }
        }
        public void Update()
        {
            _UpdateApplicationLifecycle();

            // If the player has not touched the screen, we are done with this update.
            Touch touch;

            if (!(Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began))
            //if (Input.GetMouseButton(0))
            {
                Ray        ray = Camera.main.ScreenPointToRay(touch.position);
                RaycastHit hit;

                if (Physics.Raycast(ray, out hit, 100))
                {
                    if (!selectedObjects.Contains(hit.transform.gameObject))
                    {
                        hit.transform.GetComponent <Renderer>().material.color = Color.blue;
                        selectedObjects.Add(hit.transform.gameObject);
                        hit.transform.GetChild(0).GetComponent <TextMesh>().color = Color.blue;
                    }
                    else
                    {
                        hit.transform.GetComponent <Renderer>().material.color = originalColor;
                        selectedObjects.Remove(hit.transform.gameObject);
                        hit.transform.transform.GetChild(0).GetComponent <TextMesh>().color = originalColor;
                    }

                    Debug.Log("Object is hit");
                }
            }

            // Get updated augmented images for this frame.
            Session.GetTrackables <AugmentedImage>(m_TempAugmentedImages, TrackableQueryFilter.Updated);

            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);
                }
            }
        }
예제 #21
0
        public void _Rotate()
        {
            Touch touch;

            touch = Input.GetTouch(0);
            if (Input.touchCount == 1 && touch.phase == TouchPhase.Moved)
            {
                ARObject.transform.Rotate(Vector3.forward * rotateSpeed * Time.deltaTime * touch.deltaPosition.y, Space.Self);
                Debug.Log("Delta Touch is " + touch.deltaPosition);
            }
        }
예제 #22
0
        /// <summary>
        /// The Unity Update() method.
        /// </summary>
        public void Update()
        {
            _UpdateApplicationLifecycle();

            Session.GetTrackables <DetectedPlane>(m_AllPlanes);



            // If the player has not touched the screen, we are done with this update.
            Touch touch;

            if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began)
            {
                return;
            }

            // Raycast against the location the player touched to search for planes.
            TrackableHit      hit;
            TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinInfinity |
                                              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)
                {
                }
                else
                {
                    // ange spelobjektet prefab till spelplanets prefab
                    GameObject prefab = PlaceGameScenePrefab;;

                    // Placera spelplan var användaren rör på planet, gör detta endast en gång
                    if (!isSpawned)
                    {
                        // meddella spelkontrollen att spel planet har placerats för att initiera att splet har börjat
                        gamecontroller.gamesceneSet = true;

                        // initiera spel planet
                        var GamePlane = Instantiate(prefab, hit.Pose.position, hit.Pose.rotation);

                        // placera en ankare på platsen som spelaren rört
                        var anchor = hit.Trackable.CreateAnchor(hit.Pose);
                        // placera spelplanet på ankaret
                        GamePlane.transform.parent = anchor.transform;

                        isSpawned = true;
                    }
                }
            }
        }
예제 #23
0
        /// <summary>
        /// The Unity Update() method.
        /// </summary>
        public void Update()
        {
            _UpdateApplicationLifecycle();

            // If the player has not touched the screen, we are done with this update.
            Touch touch;

            if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began)
            {
                return;
            }
        }
예제 #24
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");
            }
        }
예제 #25
0
        void Move()
        {
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);

            // The GameObject this script attached should be on layer "Surface"
            if (Physics.Raycast(ray, out hit, 30.0f, LayerMask.GetMask("Surface")))
            {
                instantiatedObj.transform.position = new Vector3(hit.point.x,
                                                                 transform.position.y,
                                                                 hit.point.z);
            }
        }
예제 #26
0
        public void _InstantiateOnTouch()
        {
            Touch touch;

            touch = Input.GetTouch(0);


            if (Input.touchCount != 0)
            {
                _SpawnARObject();
                _PinchtoZoom();
                _Rotate();
            }
        }
        /// <summary>
        /// The Unity Update() method.
        /// </summary>
        public void Update()
        {
            _UpdateApplicationLifecycle();

            // If the player has not touched the screen then the update is complete.
            Touch touch;

            if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began)
            {
                return;
            }
            // Raycast against the location the player touched to search for planes.
            if (Application.platform != RuntimePlatform.IPhonePlayer)
            {
                TrackableHit hit;
                if (Frame.Raycast(touch.position.x, touch.position.y,
                                  TrackableHitFlags.PlaneWithinPolygon, out hit))
                {
                    m_LastPlacedAnchor = hit.Trackable.CreateAnchor(hit.Pose);
                }
            }
            else
            {
                Pose hitPose;
                if (m_ARKit.RaycastPlane(ARKitFirstPersonCamera, touch.position.x, touch.position.y, out hitPose))
                {
                    m_LastPlacedAnchor = m_ARKit.CreateAnchor(hitPose);
                }
            }

            if (m_LastPlacedAnchor != null)
            {
                SearchingForPlaneUI.SetActive(false);
                btnCamera.SetActive(true);
                spawnOBJ.SetActive(true);

                // Instantiate Andy model at the hit pose.
                //var andyObject = Instantiate(_GetAndyPrefab(), m_LastPlacedAnchor.transform.position,
                //    m_LastPlacedAnchor.transform.rotation);
                ARKitAndyAndroidPrefab.transform.position = m_LastPlacedAnchor.transform.position;
                ARKitAndyAndroidPrefab.transform.rotation = m_LastPlacedAnchor.transform.rotation;

                // Compensate for the hitPose rotation facing away from the raycast (i.e. camera).
                //andyObject.transform.Rotate(0, k_ModelRotation, 0, Space.Self);
                ARKitAndyAndroidPrefab.transform.Rotate(0, k_ModelRotation, 0, Space.Self);
                // Make Andy model a child of the anchor.
                ARKitAndyAndroidPrefab.transform.parent = m_LastPlacedAnchor.transform;
                //andyObject.transform.parent = m_LastPlacedAnchor.transform;
            }
        }
예제 #28
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;
            DetectedPlane anchorPlane     = null;

            for (int i = 0; i < m_AllPlanes.Count; i++)
            {
                if (m_AllPlanes[i].TrackingState == TrackingState.Tracking)
                {
                    anchorPlane     = m_AllPlanes[i];
                    showSearchingUI = false;
                    break;
                }
            }

            SearchingForPlaneUI.SetActive(showSearchingUI);

            if (showSearchingUI)
            {
                return;
            }

            // If the player has not touched the screen, we are done with this update.
            Touch touch;

            if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began)
            {
                return;
            }


            // Instantiate the object to display the server response.
            Vector3 position = FirstPersonCamera.transform.position + FirstPersonCamera.transform.forward * 0.5f;
            var     anchor   = Session.CreateAnchor(new Pose(position, FirstPersonCamera.transform.rotation), anchorPlane);

            // Make the text object a child of the anchor.
            GameObject prefab      = resultPrefab;
            var        responseObj = Instantiate(prefab, position, FirstPersonCamera.transform.rotation);

            responseObj.transform.parent = anchor.transform;

            byte[] jpg = TextureReaderWrapper.FrameTexture.EncodeToJPG();

            // Start query (request to the server)
            responseObj.GetComponent <ApiRequester>().startQuery(jpg);
        }
예제 #29
0
        public void Update()
        {
            _UpdateApplicationLifecycle();

            // If the player has not touched the screen, we are done with this update.
            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.
            TrackableHit      hit;
            TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon |
                                              TrackableHitFlags.FeaturePointWithSurfaceNormal;

            if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit))
            {
                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
                {
                    GameObject prefab;
                    if (hit.Trackable is FeaturePoint)
                    {
                        prefab = AndyPointPrefab;
                    }
                    else
                    {
                        prefab = AndyPlanePrefab;
                    }

                    var andyObject = Instantiate(prefab, hit.Pose.position, hit.Pose.rotation);
                    andyObject.transform.Rotate(0, k_ModelRotation, 0, Space.Self);
                    var anchor = hit.Trackable.CreateAnchor(hit.Pose);
                    andyObject.transform.parent = anchor.transform;
                }
            }
        }
        /// <summary>
        /// The Unity Update() method.
        /// </summary>
        public void Update()
        {
            _UpdateApplicationLifecycle();

            if (hasToPlaceAnimal)
            {
                PlaceAnimal();
            }

            // Check time from last animal was placed
            timer += Time.deltaTime;
            if (timer % 60 > maxTime)
            {
                hasToPlaceAnimal = true;
            }

            // If the player has not touched the screen, we are done with this update.
            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;
            }

            //Check if there is an animal on scene
            if (currentAnimal == null)
            {
                return;
            }

            // Raycast against the location the player touched to search for planes.
            RaycastHit hit = new RaycastHit();
            Ray        ray = FirstPersonCamera.ScreenPointToRay(touch.position);

            if (Physics.Raycast(ray, out hit))
            {
                if (hit.transform.gameObject.GetComponent <AnimalController>() != null)
                {
                    currentAnimal.SendMessage("OnTouchDetected");
                    currentAnimal = null;
                }
            }
        }