Esempio n. 1
0
    private void Raycast()
    {
        GvrPointerPhysicsRaycaster GvrPPR = Camera.main.GetComponent <GvrPointerPhysicsRaycaster>();
        Ray ray = GvrPPR.GetLastRay();

        float dist   = GvrPPR.eventCamera.farClipPlane - GvrPPR.eventCamera.nearClipPlane;
        float radius = GvrPPR.PointerRadius;

        RaycastHit[] hits;

        if (radius > 0.0f)
        {
            hits = Physics.SphereCastAll(ray, radius, dist, GvrPPR.finalEventMask);
        }
        else
        {
            hits = Physics.RaycastAll(ray, dist, GvrPPR.finalEventMask);
        }

        IsAiming = !(hits.Length == 0);
    }
Esempio n. 2
0
        private void handleGvrControllerInput()
        {
            // Get controller ray
            Ray controllerRay = controllerRaycaster.GetLastRay();

            //Debug.DrawRay(controllerRay.origin, controllerRay.direction, Color.green, 0.1f, false);

            // Hide toggleable volumes hit by controller
            hideToggleableVolumesHitByController();

            // Have we picked an object?
            if (pickedObject != null)
            {
                if (GvrController.ClickButtonDown)
                {
                    // Get ray position on design plane
                    RaycastHit designPlaneHit;
                    bool       isPositionOnDesignPlane = designPlane.Raycast(controllerRay, out designPlaneHit, Mathf.Infinity);
                    if (isPositionOnDesignPlane)
                    {
                        // Drop object on design plane
                        Transform droppedObject = pickedObject;
                        pickedObject = null;
                        StartCoroutine(dropObject(droppedObject, designPlaneHit.point));
                    }
                    else
                    {
                        // Put back object to its original position
                        StartCoroutine(animator.playResetPickedObjectAnimation(pickedObject));
                        pickedObject = null;
                    }
                }
            }
            // Are we dragging?
            else if (isDraggingPlacedObject)
            {
                // Get ray position on design plane
                RaycastHit designPlaneHit;
                bool       isPositionOnDesignPlane = designPlane.Raycast(controllerRay, out designPlaneHit, Mathf.Infinity);
                if (isPositionOnDesignPlane)
                {
                    // Move dragged object to mouse position on design plane
                    hoveredPlacedObject.transform.position = designPlaneHit.point;
                    // Check if clicked released (dragging stopped)
                    if (GvrController.ClickButtonUp)
                    {
                        StartCoroutine(stopDragging());
                    }
                }
                else                 // Stop dragging if we are no longer on the floor
                {
                    StartCoroutine(stopDragging());
                }
            }
            else             // Not dragging
            {
                // Get the placed object we are aiming at
                GameObject placedObject      = getObjectTagettedByController(PLACED_OBJECTS_LAYER);
                bool       isPlacedObjectHit = (placedObject != null);
                // Get the available object we are aiming at
                GameObject availableObject = null;
                if (!isPlacedObjectHit)
                {
                    availableObject = getObjectTagettedByController(AVAILABLE_OBJECTS_LAYER);
                }
                bool isAvailableObjectHit = (availableObject != null);

                // Update hovered object
                setHoveredPlacedObject(placedObject);
                setHoveredAvailableObject(availableObject);

                // Did we hit a placed object?
                if (isPlacedObjectHit)
                {
                    // Touchpad clicked while pointing at a placed object (start dragging)
                    if (GvrController.ClickButtonDown)
                    {
                        isDraggingPlacedObject = true;
                        markHoveredObjectAsSelected(true);
                    }
                    // App button clicked while pointing at a placed object (remove object)
                    else if (GvrController.AppButtonDown)
                    {
                        StartCoroutine(removePlacedObject(placedObject));
                        hoveredPlacedObject = null;
                    }
                }
                else if (isAvailableObjectHit)
                {
                    // Touchpad clicked while pointing at an available object (pick up object)
                    if (GvrController.ClickButtonDown)
                    {
                        StartCoroutine(animator.playPickupAnimation(availableObject.transform));
                        pickedObject = availableObject.transform;
                        setHoveredAvailableObject(null);
                    }
                }
            }
        }