public override bool JustifiesRequirement(EHand Hand, GestureRequirementData RequirementData)
    {
        DetectionManager.DetectionHand SelectedHand = DetectionManager.Get().GetHand(Hand);
        if (SelectedHand.IsSet())
        {
            Vector3 FingerDirection = SelectedHand.GetFinger(RequirementData.m_FingerValue).GetFingerDirection();

            DetectionManager.DetectionFinger SelectedFinger = SelectedHand.GetFinger(RequirementData.m_FingerValue);

            Vector3 Bone1Dir = SelectedFinger.GetBoneDirection(ESpecificBone.eBone0);
            Vector3 Bone2Dir = SelectedFinger.GetBoneDirection(ESpecificBone.eBone1);
            Vector3 Bone3Dir = SelectedFinger.GetBoneDirection(ESpecificBone.eBone2);

            float boneDot;

            if (RequirementData.m_FingerValue == EFinger.eThumb)
            {
                boneDot = Mathf.Clamp(Vector3.Dot(Bone2Dir, Bone3Dir), 0.0f, 1.0f);
            }
            else
            {
                boneDot = Mathf.Clamp(Vector3.Dot(Bone1Dir, Bone3Dir), 0.0f, 1.0f);
            }

            float percentage = Mathf.Lerp(1.0f, 0.0f, boneDot);

            if (percentage > RequirementData.m_FloatValue)
            {
                return(true);
            }
        }

        return(false);
    }
示例#2
0
    bool JustifiesHand(EHand Hand)
    {
        if (!m_CustomGesture)
        {
            return(false);
        }


        List <GestureRequirementData> GestureRequirements = m_CustomGesture.GetHandRequirements(Hand);

        foreach (GestureRequirementData require in GestureRequirements)
        {
            if (require.m_Requirement.m_DataRequirements.GetRequiresFinger())
            {
                if (require.m_FingerValue == EFinger.eUnknown)
                {
                    Debug.Log("[GestureDetection] Object: " + gameObject.name + ": \"" + require.m_Requirement.GetType().ToString() + "\" Cannot use a Requirement with an unknown finger");
                    return(false);
                }
            }
            if (!require.m_Requirement.JustifiesRequirement(Hand, require))
            {
                return(false);
            }
        }

        return(true);
    }
示例#3
0
 /// <summary>
 /// Called in an update method to check if a click is still down
 /// </summary>
 /// <param name="handHoldingHandle">The hand with with the user is clicking</param>
 /// <param name="clickIsDown">The ClickIsDown BoolVariable Value for the corresponding hand</param>
 public void CheckClickStillDown(ref EHand handHoldingHandle, bool clickIsDown)
 {
     if (!clickIsDown)
     {
         handHoldingHandle = EHand.NONE;
     }
 }
示例#4
0
 public OnHapticRequestedEvent(EHand hand, EHapticDuration hapticDuration, EHapticAmplitude hapticAmplitude = EHapticAmplitude.MEDIUM) : base("Event to call when you want to launch haptic in the controller of the user.")
 {
     Hand            = hand;
     HapticDuration  = GetBaseDuration(hapticDuration);
     HapticAmplitude = GetBaseAmplitude(hapticAmplitude);
     FireEvent(this);
 }
示例#5
0
 public OnHapticRequestedEvent(EHand hand, float hapticDuration = 1.0f, float hapticAmplitude = 1.0f) : base("Event to call when you want to launch haptic in the controller of the user.")
 {
     Hand            = hand;
     HapticDuration  = hapticDuration;
     HapticAmplitude = hapticAmplitude;
     FireEvent(this);
 }
    EDirection GetClosestDirection(ref bool a_bDetected, EHand InHand, EHandAxis InAxis)
    {
        DetectionManager.DetectionHand detectionHand = DetectionManager.Get().GetHand(InHand);

        if (!detectionHand.IsSet())
        {
            a_bDetected = false;
            return(EDirection.eDownwards);
        }

        Vector3 handDirection = detectionHand.GetHandAxis(InAxis);

        float      currentDistance = float.MaxValue;
        EDirection currentDir      = EDirection.eUpwards;

        Dictionary <EDirection, Vector3> directionMap = GetDirections();

        foreach (EDirection dir in directionMap.Keys)
        {
            float newDistance = Vector3.Distance(handDirection, directionMap[dir]);

            if (newDistance < currentDistance)
            {
                currentDistance = newDistance;
                currentDir      = dir;
                a_bDetected     = true;
            }
        }

        return(currentDir);
    }
示例#7
0
 public void BurgerIsFinished()
 {
     Destroy(currentBurger);
     GameManager.Instance.scoreManager.IncrementScore();
     audioSource.PlayOneShot(eatSounds[Random.Range(0, eatSounds.Length)]);
     currentHand = currentHand == EHand.Right ? EHand.Left : EHand.Right;
     GenerateBurger();
 }
示例#8
0
    public static bool JustifiesRequirement(EHand Hand, string InRequirement)
    {
        if (InRequirement == "ThumbExtended")
        {
            return(ThumbExtended(Hand));
        }

        return(false);
    }
    Vector3 GetHandPosition(EHand a_Hand)
    {
        if (DetectionManager.Get().IsHandSet(m_Hand))
        {
            return(DetectionManager.Get().GetHand(a_Hand).GetRelativeHandPosition());
        }

        return(Vector3.zero);
    }
    public override bool JustifiesRequirement(EHand Hand, GestureRequirementData RequirementData)
    {
        if (DetectionManager.Get().IsHandSet(Hand))
        {
            return(DetectionManager.Get().GetHand(Hand).IsPinching());
        }

        return(false);
    }
    public Vector3 GetHandAxis(EHand a_Hand)
    {
        if (DetectionManager.Get().IsHandSet(m_Hand))
        {
            return(DetectionManager.Get().GetHand(a_Hand).GetHandAxis(EHandAxis.eFingerDirection));
        }

        return(Vector3.zero);
    }
示例#12
0
        /// <summary>
        /// We check which hand correspond to the Action Button that was choosen
        /// </summary>
        private void CheckButtonHand()
        {
            EControllersInput gazeClick = GetGazeClick();

            // If we use the Gaze Button but the Controllers are inactive
            if (UseGazeButton && !_controllersParameters.UseControllers)
            {
                this.enabled = false;
                throw new Exception("The Button Action Choser parameters for the " + this.GetType().Name + " script are invalid.\n" +
                                    "If you want to use the Gaze Click, please activate the Controllers by setting the UseControllers bool in the Window VRSF/Controllers Parameters to true.\n" +
                                    "Disabling the script.");
            }
            // If we use the Gaze Button but the chosen gaze button is None
            else if (UseGazeButton && gazeClick == EControllersInput.NONE)
            {
                this.enabled = false;
                throw new Exception("The Button Action Choser parameters for the " + this.GetType().Name + " script are invalid.\n" +
                                    "Please specify a GazeButton in the Gaze Parameters Window to use the Gaze Click feature. Disabling the script.");
            }

            // if the Action Button is set to the Wheel Button (SIMULATOR SPECIFIC)
            else if (ActionButton == EControllersInput.WHEEL_BUTTON)
            {
                _isUsingWheelButton = true;
            }

            // if the Action Button is set to the A, B or Right Thumbrest option (OCULUS SPECIFIC)
            else if (ActionButton == EControllersInput.A_BUTTON || ActionButton == EControllersInput.B_BUTTON || ActionButton == EControllersInput.RIGHT_THUMBREST)
            {
                _isUsingOculusButton = true;
                _buttonHand          = EHand.RIGHT;
            }
            // if the Action Button is set to the X, Y or Left Thumbrest option (OCULUS SPECIFIC)
            else if (ActionButton == EControllersInput.X_BUTTON || ActionButton == EControllersInput.Y_BUTTON || ActionButton == EControllersInput.LEFT_THUMBREST)
            {
                _isUsingOculusButton = true;
                _buttonHand          = EHand.LEFT;
            }

            // if the Action Button is set to the Right Menu option (VIVE AND SIMULATOR SPECIFIC)
            else if (ActionButton == EControllersInput.RIGHT_MENU)
            {
                _isUsingViveButton = true;
                _buttonHand        = EHand.RIGHT;
            }

            // If non of the previous solution was chosen, we just check if the button is on the right or left controller
            else if (ActionButton.ToString().Contains("RIGHT"))
            {
                _buttonHand = EHand.RIGHT;
            }
            else if (ActionButton.ToString().Contains("LEFT"))
            {
                _buttonHand = EHand.LEFT;
            }
        }
示例#13
0
    static bool ThumbExtended(EHand Hand)
    {
        DetectionManager.DetectionHand CurrentHand = DetectionManager.sInstance.GetHand(Hand);
        if (CurrentHand.IsSet())
        {
            return(CurrentHand.GetFinger(EFinger.eIndex).IsExtended());
        }

        return(false);
    }
 public void AddRequirement(EHand Hand, GestureRequirement Requirement)
 {
     if (Hand == EHand.eRightHand)
     {
         RightHandRequirements.Add(new GestureRequirementData(Requirement));
     }
     else
     {
         LeftHandRequirements.Add(new GestureRequirementData(Requirement));
     }
 }
示例#15
0
    void AddItem(object requirement, EHand Hand)
    {
        GestureRequirement[] AllRequirements = TargetGesture.GetListOfAllRequirements();
        foreach (GestureRequirement Gesture in AllRequirements)
        {
            if (Gesture.GetType().ToString() == requirement.GetType().ToString())
            {
                TargetGesture.AddRequirement(Hand, Gesture);

                break;
            }
        }
    }
示例#16
0
    public override bool JustifiesRequirement(EHand Hand, GestureRequirementData RequirementData)
    {
        DetectionManager.DetectionHand SelectedHand = DetectionManager.Get().GetHand(Hand);
        if (SelectedHand.IsSet())
        {
            if (RequirementData.m_BoolValue == SelectedHand.GetFinger(RequirementData.m_FingerValue).IsExtended())
            {
                return(true);
            }
        }

        return(false);
    }
    public override bool JustifiesRequirement(EHand Hand, GestureRequirementData RequirementData)
    {
        EDirection Dir = EDirection.eOutwards;

        if (IsSwiping(ref Dir, RequirementData.m_FloatValue, Hand))
        {
            if (Dir == RequirementData.m_DirectionValue)
            {
                return(true);
            }
        }

        return(false);
    }
        /// <summary>
        /// Give the Exclusion Layer(s) depending on the IgnoreOnlyExclusionLayer bools and the specified exclusion layers
        /// </summary>
        /// <param name="hand">The hand to which the exclusion layer is set (LEFT OR RIGHT)</param>
        /// <returns>the exclusion layers as an int</returns>
        public LayerMask GetExclusionsLayer(EHand hand)
        {
            switch (hand)
            {
            case (EHand.LEFT):
                return(~LeftExclusionLayer);

            case (EHand.RIGHT):
                return(~RightExclusionLayer);

            default:
                Debug.LogError("No Hand provided, returning -1");
                return(-1);
            }
        }
    public override bool JustifiesRequirement(EHand Hand, GestureRequirementData RequirementData)
    {
        bool       bDetected = false;
        EDirection Direction = GetClosestDirection(ref bDetected, Hand, RequirementData.m_HandAxisValue);

        if (bDetected)
        {
            if (RequirementData.m_DirectionValue == Direction)
            {
                return(true);
            }
        }

        return(false);
    }
    bool IsSwiping(ref EDirection a_swipeDirection, float InVelocity, EHand InHand)
    {
        DetectionManager.DetectionHand detectHand = DetectionManager.Get().GetHand(InHand);

        if (!detectHand.IsSet())
        {
            a_swipeDirection = EDirection.eOutwards;
            return(false);
        }

        Vector3 velocity = detectHand.GetVelocity();

        velocity = Camera.main.transform.InverseTransformDirection(velocity);

        if (velocity.x >= InVelocity) //right
        {
            a_swipeDirection = EDirection.eRight;
            return(true);
        }
        else if (velocity.x <= -InVelocity)//left
        {
            a_swipeDirection = EDirection.eLeft;
            return(true);
        }
        else if (velocity.y >= InVelocity) //up
        {
            a_swipeDirection = EDirection.eUpwards;
            return(true);
        }
        else if (velocity.y <= -InVelocity)//down
        {
            a_swipeDirection = EDirection.eDownwards;
            return(true);
        }
        else if (velocity.z >= InVelocity) //forward
        {
            a_swipeDirection = EDirection.eOutwards;
            return(true);
        }
        else if (velocity.z <= -InVelocity)//back
        {
            a_swipeDirection = EDirection.eInWards;
            return(true);
        }

        return(false);
    }
示例#21
0
 private Transform GetNextHand()
 {
     if (m_last == EHand.NONE)
     {
         m_last = EHand.LEFT;
         return(m_leftHand);
     }
     else if (m_last == EHand.LEFT)
     {
         m_last = EHand.RIGHT;
         return(m_rightHand);
     }
     else
     {
         m_last = EHand.LEFT;
         return(m_leftHand);
     }
 }
 void HandPunch(EHand InHand)
 {
     DetectionManager.DetectionHand DetectHand = DetectionManager.Get().GetHand(InHand);
     if (DetectHand.IsSet())
     {
         if (rb)
         {
             rb.useGravity = true;
             PunchBagCollider.isTrigger = false;
             rb.AddForce(DetectHand.GetVelocity() * 200);
             CurrentPunchState = EPunchingBagState.PunchState;
             if (SpawnedBy)
             {
                 SpawnedBy.StartSpawnTimer();
             }
         }
     }
 }
示例#23
0
        /// <summary>
        /// Move the Scrollable component when the user is holding the handle.
        /// </summary>
        /// <param name="handHoldingHandle">The hand that is holding the Scrollable element</param>
        /// <param name="minPosTransform">The min position of the scrollable element, set at runtime</param>
        /// <param name="maxPosTransform">The max position of the scrollable element, set at runtime</param>
        /// <param name="raycastHitDictionary">The dictionary containing references to the RaycastHitVariable of the controllers</param>
        /// <param name="direction">The direction of the scrollable element</param>
        /// <returns>The new value of the scrollable</returns>
        public float MoveComponent(EHand handHoldingHandle, Transform minPosTransform, Transform maxPosTransform, Dictionary <string, RaycastHitVariable> raycastHitDictionary)
        {
            switch (handHoldingHandle)
            {
            case (EHand.GAZE):
                return(SetComponentNewValue(raycastHitDictionary["Gaze"].Value.point, minPosTransform, maxPosTransform));

            case (EHand.LEFT):
                return(SetComponentNewValue(raycastHitDictionary["Left"].Value.point, minPosTransform, maxPosTransform));

            case (EHand.RIGHT):
                return(SetComponentNewValue(raycastHitDictionary["Right"].Value.point, minPosTransform, maxPosTransform));

            default:
                Debug.LogError("Error in MoveComponent method");
                return(0);
            }
        }
示例#24
0
    void DrawCustomGestureDropdown(List <GestureRequirementData> Requirements, EHand Hand, SerializedProperty InHandProp)
    {
        GUIStyle BorderStyle = new GUIStyle(EditorStyles.helpBox);

        GUI.backgroundColor = Color.gray;
        EditorGUILayout.BeginVertical(BorderStyle);

        int index = 0;

        foreach (GestureRequirementData requirement in Requirements.ToArray())
        {
            SerializedProperty ReqArrayElem = InHandProp.GetArrayElementAtIndex(index);

            DrawCustomGestureWidget(requirement, Hand, ReqArrayElem);

            ++index;
        }

        EditorGUILayout.EndVertical();
    }
示例#25
0
 /// <summary>
 /// Check which hand is holding clicking on the scrollbar
 /// </summary>
 private void CheckHandClickingScrollbar()
 {
     // Next if statements are to check which click was used on the slider
     if (_rightTriggerDown.Value && _ListenersDictionary["Right"].Value == transform)
     {
         _HandHoldingHandle = EHand.RIGHT;
     }
     else if (_leftTriggerDown.Value && _ListenersDictionary["Left"].Value == transform)
     {
         _HandHoldingHandle = EHand.LEFT;
     }
     else if (_gazeParameter.UseGaze && _inputContainer.GazeIsCliking.Value && _ListenersDictionary["Gaze"].Value == transform)
     {
         _HandHoldingHandle = EHand.GAZE;
     }
     else
     {
         Debug.LogError("Couldn't find reference to the Click Listener on the slider.");
     }
 }
示例#26
0
        /// <summary>
        /// Get the color of the Hand pointers by getting the Controllers Parameters
        /// </summary>
        /// <param name="hand">the Hand to check</param>
        /// <param name="on">The color for the On State</param>
        /// <param name="off">The color for the Off State</param>
        /// <param name="selectable">The color for the Selectable State</param>
        private void GetColor(EHand hand, ref Color on, ref Color off, ref Color selectable)
        {
            switch (hand)
            {
            case (EHand.RIGHT):
                on         = _controllersParameters.ColorMatOnRight;
                off        = _controllersParameters.ColorMatOffRight;
                selectable = _controllersParameters.ColorMatSelectableRight;
                break;

            case (EHand.LEFT):
                on         = _controllersParameters.ColorMatOnLeft;
                off        = _controllersParameters.ColorMatOffLeft;
                selectable = _controllersParameters.ColorMatSelectableLeft;
                break;

            default:
                Debug.LogError("The hand wasn't specified, setting pointer color to white.");
                break;
            }
        }
示例#27
0
        /// <summary>
        /// Display the Controllers Pointer Parameters
        /// </summary>
        private void ShowPointerParameters(EHand hand)
        {
            Undo.RecordObject(_controllersParameters, "Modifiying pointer");

            switch (hand)
            {
            case (EHand.RIGHT):
                _controllersParameters.RightPointerState = (EPointerState)EditorGUILayout.EnumPopup("Right Pointer State", _controllersParameters.RightPointerState);

                LayerMask rightTempMask = EditorGUILayout.MaskField("Excluded layer Right", InternalEditorUtility.LayerMaskToConcatenatedLayersMask(_controllersParameters.RightExclusionLayer), InternalEditorUtility.layers);
                _controllersParameters.RightExclusionLayer = InternalEditorUtility.ConcatenatedLayersMaskToLayerMask(rightTempMask);

                _controllersParameters.ColorMatOnRight         = EditorGUILayout.ColorField("Color On Right", _controllersParameters.ColorMatOnRight);
                _controllersParameters.ColorMatOffRight        = EditorGUILayout.ColorField("Color Off Right", _controllersParameters.ColorMatOffRight);
                _controllersParameters.ColorMatSelectableRight = EditorGUILayout.ColorField("Color Selectable Right", _controllersParameters.ColorMatSelectableRight);

                _controllersParameters.MaxDistancePointerRight = EditorGUILayout.FloatField("Max Distance Right Pointer", _controllersParameters.MaxDistancePointerRight);
                break;

            case (EHand.LEFT):
                _controllersParameters.LeftPointerState = (EPointerState)EditorGUILayout.EnumPopup("Left Pointer State", _controllersParameters.LeftPointerState);

                LayerMask leftTempMask = EditorGUILayout.MaskField("Excluded layer Left", InternalEditorUtility.LayerMaskToConcatenatedLayersMask(_controllersParameters.LeftExclusionLayer), InternalEditorUtility.layers);
                _controllersParameters.LeftExclusionLayer = InternalEditorUtility.ConcatenatedLayersMaskToLayerMask(leftTempMask);

                _controllersParameters.ColorMatOnLeft         = EditorGUILayout.ColorField("Color On Left", _controllersParameters.ColorMatOnLeft);
                _controllersParameters.ColorMatOffLeft        = EditorGUILayout.ColorField("Color Off Left", _controllersParameters.ColorMatOffLeft);
                _controllersParameters.ColorMatSelectableLeft = EditorGUILayout.ColorField("Color Selectable Left", _controllersParameters.ColorMatSelectableLeft);

                _controllersParameters.MaxDistancePointerLeft = EditorGUILayout.FloatField("Max Distance Left Pointer", _controllersParameters.MaxDistancePointerLeft);
                break;

            default:
                Debug.LogError("Error in ShowPointerParameters, the hand wasn't recognized.");
                break;
            }

            Undo.FlushUndoRecordObjects();
        }
示例#28
0
        /// <summary>
        /// Method called when the user release the slider bar
        /// </summary>
        private void HandleUp()
        {
            // If the bar was filled and the user is releasing it, we invoke the OnBarReleased event
            if (_barFilled)
            {
                OnBarReleased.Invoke();
                _barFilled = false;
            }

            // If the coroutine has been started (and thus we have a reference to it) stop it.
            if (_fillBarRoutine != null)
            {
                StopCoroutine(_fillBarRoutine);
                _fillBarRoutine = null;
            }

            // Reset the timer and bar values.
            _timer = 0f;
            value  = 0.0f;

            // Set the Hand filling at null
            _handFilling = EHand.NONE;
        }
示例#29
0
 /// <summary>
 /// Check which hand is clicking on the Slider
 /// </summary>
 private void CheckHandClicking()
 {
     // Next if statements are to check which click was used on the slider
     if (_rightIsClicking.Value && _overListenersDictionary["Right"].Value == transform)
     {
         _handFilling    = EHand.RIGHT;
         _fillBarRoutine = StartCoroutine(FillBar());
     }
     else if (_leftIsClicking.Value && _overListenersDictionary["Left"].Value == transform)
     {
         _handFilling    = EHand.LEFT;
         _fillBarRoutine = StartCoroutine(FillBar());
     }
     else if (_gazeParameter.UseGaze && _inputContainer.GazeIsCliking.Value && _overListenersDictionary["Gaze"].Value == transform)
     {
         _handFilling    = EHand.GAZE;
         _fillBarRoutine = StartCoroutine(FillBar());
     }
     else
     {
         Debug.LogError("VRSF : Couldn't find reference to the Click Listener on the slider.");
     }
 }
 public void RemoveRequirement(EHand Hand, GestureRequirement Requirement)
 {
     if (Hand == EHand.eRightHand)
     {
         foreach (GestureRequirementData item in RightHandRequirements)
         {
             if (item.m_Requirement == Requirement)
             {
                 RightHandRequirements.Remove(item);
             }
         }
     }
     else
     {
         foreach (GestureRequirementData item in LeftHandRequirements)
         {
             if (item.m_Requirement == Requirement)
             {
                 LeftHandRequirements.Remove(item);
                 return;
             }
         }
     }
 }