void Update()
    {
        var        center = new Vector2(Screen.width * ScreenPosition.x, Screen.height * ScreenPosition.y);
        Ray        mRay   = Camera.main.ScreenPointToRay(center);
        RaycastHit hit;

        if (Physics.Raycast(mRay, out hit))
        {
            if (hit.transform.CompareTag("DetectedPlane") || hit.transform.CompareTag("Domino"))
            {
                reticle.transform.position = hit.point;
                Vector3 targetPostition = new Vector3(target.position.x,
                                                      this.transform.position.y,
                                                      target.position.z);
                this.transform.LookAt(targetPostition);


                if ((Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended) || Input.GetMouseButtonUp(0))
                {
                    if (IsPointerOverUIObject())
                    {
                        return;
                    }


                    GameObject gameObject = Instantiate(prefab, reticle.transform.position, reticle.transform.rotation);
                    print("PPOS " + gameObject.transform.position);
                    pointSpwaner.points.Add(gameObject.transform);
                    count += 1;
                    print(count);
                    if (count == 1)
                    {
                        pointSpwaner.PointA = gameObject.transform;
                    }
                    else if (count == 2)
                    {
                        pointSpwaner.PointB = gameObject.transform;

                        if (pointSpwaner.isLine)
                        {
                            pointSpwaner.DrawLine();
                        }
                        else if (pointSpwaner.isCircle)
                        {
                            pointSpwaner.DrawCircle();
                        }
                        else if (pointSpwaner.isRectangle)
                        {
                            pointSpwaner.DrawRectangle();
                        }
                    }
                }
            }
        }
    }
Beispiel #2
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
                {
                    // Choose the prefab based on the Trackable that got hit.
                    GameObject prefab;
                    if (hit.Trackable is FeaturePoint)
                    {
                        prefab = GameObjectPointPrefab;
                    }
                    else if (hit.Trackable is DetectedPlane)
                    {
                        DetectedPlane detectedPlane = hit.Trackable as DetectedPlane;
                        if (detectedPlane.PlaneType == DetectedPlaneType.Vertical)
                        {
                            prefab = GameObjectVerticalPlanePrefab;
                        }
                        else
                        {
                            prefab = GameObjectHorizontalPlanePrefab;
                        }
                    }
                    else
                    {
                        prefab = GameObjectHorizontalPlanePrefab;
                    }

                    // Instantiate prefab at the hit pose.
                    var gameObject = Instantiate(prefab, hit.Pose.position, hit.Pose.rotation);
                    print("PPOS " + gameObject.transform.position);
                    pointSpawner.points.Add(gameObject.transform);
                    count += 1;
                    print(count);
                    if (count == 1)
                    {
                        pointSpawner.PointA = gameObject.transform;
                    }
                    else if (count == 2)
                    {
                        pointSpawner.PointB = gameObject.transform;

                        if (pointSpawner.isLine)
                        {
                            pointSpawner.DrawLine();
                        }
                        else if (pointSpawner.isCircle)
                        {
                            pointSpawner.DrawCircle();
                        }
                        else if (pointSpawner.isRectangle)
                        {
                            pointSpawner.DrawRectangle();
                        }
                    }

                    // Compensate for the hitPose rotation facing away from the raycast (i.e.
                    // camera).
                    gameObject.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.
                    gameObject.transform.parent = anchor.transform;
                }
            }
        }