/// <summary>
        /// Handle the raycastHits to check if one of them touch something
        /// </summary>
        /// <param name="hits">The list of RaycastHits to check</param>
        /// <param name="isOver">the BoolVariable to set if something got hit</param>
        /// <param name="hitPoint">The Hit Point where the raycast collide</param>
        /// <param name="objectOver">The GameEvent to raise with the transform of the hit</param>
        private void HandleOver(List <RaycastHit> hits, BoolVariable isOver, RaycastHitVariable hitPoint, GameEventTransform objectOver)
        {
            //If nothing is hit, we set the hasHit value to false
            if (hits.Count == 0)
            {
                isOver.SetValue(false);
            }
            else
            {
                foreach (var hit in hits)
                {
                    // If something is hit and is not from the Exclusion layer, we set everything and return
                    if (hit.collider.gameObject.layer != pointerRayCast.ExclusionLayer)
                    {
                        var hitTransform = hit.collider.transform;

                        isOver.SetValue(true);

                        hitPoint.SetValue(hit);
                        objectOver.Raise(hitTransform);
                        return;
                    }
                    //If the only hit was on the exclusion layer, we set the hasHit value to false
                    else
                    {
                        isOver.SetValue(false);
                    }
                }
            }
        }
Пример #2
0
        //EMPTY
        #region PUBLIC_METHODS
        #endregion PUBLIC_METHODS


        #region PRIVATE_METHODS
        /// <summary>
        /// Set the size of the line renderer depending on the hit from the RayCast.
        /// </summary>
        /// <param name="hit">The RaycastHitVariable containing the RaycastHit for the controller</param>
        /// <param name="controller">The controller GameObject from which the ray started</param>
        /// <param name="hand">The hand rom which we are checking the raycastHit</param>
        private void SetControllerRayLength(RaycastHitVariable hit, GameObject controller, EHand hand)
        {
            try
            {
                if (!hit.isNull)
                {
                    //Reduce lineRenderer from the controllers position to the object that was hit
                    controller.GetComponent <LineRenderer>().SetPositions(new Vector3[]
                    {
                        new Vector3(0.0f, 0.0f, 0.03f),
                        controller.transform.InverseTransformPoint(hit.Value.point),
                    });
                    return;
                }

                // Checking max distance of Line renderer depending on the Hand Variable
                var maxDistanceLr = (hand == EHand.LEFT
                    ? _controllersParameter.MaxDistancePointerLeft
                    : _controllersParameter.MaxDistancePointerRight);

                //put back lineRenderer to its normal length if nothing was hit
                controller.GetComponent <LineRenderer>().SetPositions(new Vector3[]
                {
                    new Vector3(0.0f, 0.0f, 0.03f),
                    new Vector3(0, 0, maxDistanceLr),
                });
            }
            catch (Exception e)
            {
                Debug.Log("VRSF : VR Components not setup yet, waiting for next frame.\n" + e);
            }
        }
Пример #3
0
 private void CheckHit(RaycastHitVariable hitVar, out bool hasClickSomething, ERayOrigin origin)
 {
     //If nothing is hit, we set the hasClickSomething value to false
     if (hitVar.IsNull)
     {
         hasClickSomething = false;
     }
     else
     {
         hasClickSomething = true;
         new ObjectWasClickedEvent(origin, hitVar.Value.collider.transform);
     }
 }
Пример #4
0
        /// <summary>
        /// Check if the Ray from a controller is hitting something
        /// </summary>
        /// <param name="ray">The ray to check</param>
        /// <param name="distance">The maximum distance to which we raycast</param>
        /// <param name="layerToIgnore">The layer(s) to ignore from raycasting</param>
        /// <param name="hitVariable">The RaycastHitVariable in which we store the hit value</param>
        private void RaycastHandler(Ray ray, float distance, int layerToIgnore, ref RaycastHitVariable hitVariable)
        {
            var hits = Physics.RaycastAll(ray, distance, layerToIgnore);

            if (hits.Length > 0)
            {
                var first3DHit = hits.OrderBy(x => x.distance).First();
                hitVariable.SetValue(first3DHit);
                hitVariable.isNull = false;
            }
            else
            {
                hitVariable.isNull = true;
            }
        }
Пример #5
0
 /// <summary>
 /// Handle the raycastHits to check if one object was clicked
 /// </summary>
 /// <param name="hits">The list of RaycastHits to check</param>
 /// <param name="hasClicked">the BoolVariable to set if something got clicked</param>
 /// <param name="objectClicked">The GameEvent to raise with the transform of the hit</param>
 private void HandleClick(RaycastHitVariable hit, BoolVariable hasClicked, GameEventTransform objectClickedEvent)
 {
     //If nothing is hit, we set the isOver value to false
     if (hit.isNull)
     {
         hasClicked.SetValue(false);
     }
     else
     {
         if (hit.Value.collider != null)
         {
             hasClicked.SetValue(true);
             objectClickedEvent.Raise(hit.Value.collider.transform);
         }
     }
 }
Пример #6
0
        /// <summary>
        /// Handle the raycastHits to check if one of them touch something
        /// </summary>
        /// <param name="isOver">the BoolVariable to set if something got hit</param>
        /// <param name="hit">The Hit Point where the raycast collide</param>
        /// <param name="objectOver">The GameEvent to raise with the transform of the hit</param>
        private void HandleOver(BoolVariable isOver, RaycastHitVariable hit, GameEventTransform objectOver)
        {
            //If nothing is hit, we set the isOver value to false
            if (hit.isNull)
            {
                isOver.SetValue(false);
            }
            else
            {
                if (hit.Value.collider != null)
                {
                    var hitTransform = hit.Value.collider.transform;
                    objectOver.Raise(hitTransform);

                    isOver.SetValue(true);
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Check which RaycastHitVariable is used depending on the RayOrigin specified
        /// </summary>
        private void CheckHit()
        {
            switch (RayOrigin)
            {
            case (EHand.LEFT):
                _hit = _interactionContainer.LeftHit;
                break;

            case (EHand.RIGHT):
                _hit = _interactionContainer.RightHit;
                break;

            case (EHand.GAZE):
                _hit = _interactionContainer.GazeHit;
                break;

            default:
                Debug.LogError("VRSF : You need to specify the RayOrigin for the " + GetType().Name + " script. Disabling the script.");
                this.enabled = false;
                break;
            }
        }
Пример #8
0
 /// <summary>
 /// Handle the raycastHits to check if one of them touch something
 /// </summary>
 private void HandleOver(ref Transform currentHit, ref float3 hitPos, ref bool isOverSomething, ref RaycastHitVariable hitVar, ERayOrigin origin)
 {
     //If nothing is hit, we set the isOver value to false
     if (hitVar.IsNull && isOverSomething)
     {
         currentHit      = null;
         hitPos          = float3.zero;
         isOverSomething = false;
         new ObjectWasHoveredEvent(origin, null);
     }
     //If something is hit, we check that the collider is still "alive", and we check that the new transform hit is not the same as the previous one
     else if (!hitVar.IsNull && hitVar.Value.collider != null)
     {
         hitPos = hitVar.Value.point;
         if (hitVar.Value.collider.transform != currentHit)
         {
             isOverSomething = true;
             var hitTransform = hitVar.Value.collider.transform;
             currentHit = hitTransform;
             new ObjectWasHoveredEvent(origin, hitTransform);
         }
     }
 }