Exemplo n.º 1
0
    void Update()
    {
        // do not capture events unless the welcome panel is hidden
        if (welcomePanel.activeSelf)
        {
            return;
        }

        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);

            touchPosition = touch.position;

            if (touch.phase == TouchPhase.Began)
            {
                Ray        ray = arCamera.ScreenPointToRay(touch.position);
                RaycastHit hitObject;

                // if we got a hit meaning that it was selected
                if (Physics.Raycast(ray, out hitObject))
                {
                    PlacementObject placementObject             = hitObject.transform.GetComponent <PlacementObject>();
                    MeshRenderer    placementObjectMeshRenderer = placedObject.GetComponent <MeshRenderer>();
                    if (placementObject != null)
                    {
                        placementObject.Selected = true;
                        placementObjectMeshRenderer.material.color = activeColor;

                        if (displayCanvas)
                        {
                            placementObject.ToggleCanvas();
                        }
                    }
                } // nothing selected so set the sphere color to inactive
                else
                {
                    PlacementObject placementObject             = placedObject.GetComponent <PlacementObject>();
                    MeshRenderer    placementObjectMeshRenderer = placedObject.GetComponent <MeshRenderer>();
                    if (placementObject != null)
                    {
                        placementObject.Selected = false;
                        placementObjectMeshRenderer.material.color = inactiveColor;

                        if (displayCanvas)
                        {
                            placementObject.ToggleCanvas();
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 2
0
        /// <summary>
        /// Handles the movement of a marble object
        /// </summary>
        private void MoveMarble(Pose hitPose, float snapDistance)
        {
            //find nearest ramp
            var nearestRamp = Ramp.FindClosestRamp(hitPose.position);

            if (nearestRamp == null)
            {
                lastSelectedObject.transform.position = hitPose.position;
            }
            //if within snap zone, snap to snap zone on ramp
            else
            {
                var   nearestRampDirection          = nearestRamp.transform.position - hitPose.position;
                float nearestRampHorizontalDistance = Mathf.Sqrt(Mathf.Pow(nearestRampDirection.x, 2) + Mathf.Pow(nearestRampDirection.z, 2));
                if (nearestRampHorizontalDistance < snapDistance)
                {
                    lastSelectedObject.transform.position = nearestRamp.transform.Find("SnapZone").position;
                    lastSelectedObject.transform.rotation = nearestRamp.transform.Find("SnapZone").rotation;
                    // Need to freeze Marble after it Snaps into place
                    lastSelectedObject.GetComponent <Rigidbody>().Sleep();
                }
                else
                {
                    lastSelectedObject.transform.position = hitPose.position;
                }
            }
        }
Exemplo n.º 3
0
 void ClearSelection()
 {
     if (lastSelectedObject != null)
     {
         lastSelectedObject.IsSelected = false;
         lastSelectedObject.GetComponent <Outline>().enabled = false;
         onObjectSelected.Raise(false);
     }
     lastSelectedObject = null;
 }
Exemplo n.º 4
0
    void Update()
    {
        lockButton.onClick.AddListener(AnDiss);
        //lockButton.onClick.AddListener(ripple);

        // do not capture events unless the welcome panel is hidden
        if (welcomePanel.activeSelf)
        {
            return;
        }

        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);

            touchPosition = touch.position;

            if (touch.phase == TouchPhase.Began)
            {
                Ray        ray = arCamera.ScreenPointToRay(touch.position);
                RaycastHit hitObject;
                if (Physics.Raycast(ray, out hitObject))
                {
                    PlacementObject placementObject = hitObject.transform.GetComponent <PlacementObject>();
                    if (placementObject != null)
                    {
                        onTouchHold = isLocked ? true : true;
                        placementObject.GetComponent <PlacementObject>().SetOverlayText(isLocked ? " " : "Drag to move around");

                        placementObject.SetMoveIcon(onTouchHold);
                    }
                }
            }

            if (touch.phase == TouchPhase.Ended)
            {
                onTouchHold = false;
            }
        }

        if (arRaycastManager.Raycast(touchPosition, hits, UnityEngine.XR.ARSubsystems.TrackableType.PlaneWithinPolygon))
        {
            hitPose = hits[0].pose;

            if (placedObject == null)
            {
                if (defaultRotation > 0)
                {
                    placedObject = Instantiate(placedPrefab, hitPose.position, Quaternion.identity);
                    placedObject.transform.Rotate(Vector3.up, defaultRotation);
                }
                else
                {
                    placedObject = Instantiate(placedPrefab, hitPose.position, hitPose.rotation);
                }
            }
            else
            {
                if (onTouchHold)
                {
                    placedObject.transform.position = hitPose.position;
                    if (defaultRotation == 0)
                    {
                        placedObject.transform.rotation = hitPose.rotation;
                    }
                }
            }
        }
    }