Exemplo n.º 1
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;
                    }
                }
            }
        }
    }