/// <summary>
        /// Gets the state of the given button key mapping for the press type on the controller index.
        /// </summary>
        /// <param name="index">The index of the controller.</param>
        /// <param name="keyMapping">The key mapping key to check.</param>
        /// <param name="pressType">The type of button press to check.</param>
        /// <returns>Returns true if the button state matches the given data.</returns>
        protected virtual bool GetControllerButtonState(uint index, string keyMapping, ButtonPressTypes pressType)
        {
            KeyCode buttonCode = VRTK_SharedMethods.GetDictionaryValue(keyMappings, keyMapping, KeyCode.None);

            if (pressType == ButtonPressTypes.Touch)
            {
                return(IsButtonPressed(index, ButtonPressTypes.Press, buttonCode));
            }
            else if (pressType == ButtonPressTypes.TouchDown)
            {
                return(IsButtonPressed(index, ButtonPressTypes.PressDown, buttonCode));
            }
            else if (pressType == ButtonPressTypes.TouchUp)
            {
                return(IsButtonPressed(index, ButtonPressTypes.PressUp, buttonCode));
            }
            else if (pressType == ButtonPressTypes.Press)
            {
                return(!IsButtonPressIgnored() && IsButtonPressed(index, ButtonPressTypes.Press, buttonCode));
            }
            else if (pressType == ButtonPressTypes.PressDown)
            {
                return(!IsButtonPressIgnored() && IsButtonPressed(index, ButtonPressTypes.PressDown, buttonCode));
            }
            else if (pressType == ButtonPressTypes.PressUp)
            {
                return(!IsButtonPressIgnored() && IsButtonPressed(index, ButtonPressTypes.PressUp, buttonCode));
            }
            return(false);
        }
Beispiel #2
0
        protected virtual void CancelSetOpacityCoroutine(GameObject model)
        {
            Coroutine currentOpacityRoutine = VRTK_SharedMethods.GetDictionaryValue(setOpacityCoroutines, model);

            if (currentOpacityRoutine != null)
            {
                StopCoroutine(currentOpacityRoutine);
            }
        }
        protected virtual void InternalCancelHapticPulse(VRTK_ControllerReference controllerReference)
        {
            Coroutine currentHapticLoopRoutine = VRTK_SharedMethods.GetDictionaryValue(hapticLoopCoroutines, controllerReference);

            if (currentHapticLoopRoutine != null)
            {
                StopCoroutine(currentHapticLoopRoutine);
                hapticLoopCoroutines.Remove(controllerReference);
            }
        }
Beispiel #4
0
        public static VRTK_ControllerReference GetControllerReference(SDK_BaseController.ControllerHand controllerHand)
        {
            GameObject scriptAlias     = GetValidObjectFromHand(controllerHand);
            uint       controllerIndex = VRTK_SDK_Bridge.GetControllerIndex(scriptAlias);
            VRTK_ControllerReference foundReference = VRTK_SharedMethods.GetDictionaryValue(controllerReferences, controllerIndex);

            if (foundReference != null)
            {
                return(foundReference);
            }
            return(new VRTK_ControllerReference(scriptAlias));
        }
Beispiel #5
0
        protected virtual void EngageButtonReleased(object sender, ControllerInteractionEventArgs e)
        {
            // If the button is released, clear all the lists.
            for (int i = 0; i < trackedObjects.Count; i++)
            {
                Transform trackedObj = trackedObjects[i];
                VRTK_SharedMethods.GetDictionaryValue(movementList, trackedObj, new List <float>()).Clear();
            }
            initialGaze = Vector3.zero;

            movementEngaged   = false;
            engagedController = null;
        }
Beispiel #6
0
 public static VRTK_ControllerReference GetControllerReference(uint controllerIndex)
 {
     if (controllerIndex < uint.MaxValue)
     {
         VRTK_ControllerReference foundReference = VRTK_SharedMethods.GetDictionaryValue(controllerReferences, controllerIndex);
         if (foundReference != null)
         {
             return(foundReference);
         }
         return(new VRTK_ControllerReference(controllerIndex));
     }
     return(null);
 }
Beispiel #7
0
        protected virtual Transform GetElementTransform(string path)
        {
            if (path == null)
            {
                return(null);
            }

            if (actualModelContainer == null && VRTK_SharedMethods.GetDictionaryValue(cachedElements, path) == null)
            {
                VRTK_Logger.Error(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.SDK_OBJECT_NOT_FOUND, "Controller Model", "Controller SDK"));
                return(null);
            }

            return(VRTK_SharedMethods.GetDictionaryValue(cachedElements, path, actualModelContainer.transform.Find(path), true));
        }
        /// <summary>
        /// The GetControllerButtonState method is used to determine if the given controller button for the given press type on the given controller reference is currently taking place.
        /// </summary>
        /// <param name="buttonType">The type of button to check for the state of.</param>
        /// <param name="pressType">The button state to check for.</param>
        /// <param name="controllerReference">The reference to the controller to check the button state on.</param>
        /// <returns>Returns true if the given button is in the state of the given press type on the given controller reference.</returns>
        public override bool GetControllerButtonState(ButtonTypes buttonType, ButtonPressTypes pressType, VRTK_ControllerReference controllerReference)
        {
            if (!VRTK_ControllerReference.IsValid(controllerReference))
            {
                return(false);
            }

            bool isRightController = (controllerReference.hand == ControllerHand.Right);

            KeyCode?touchButton = VRTK_SharedMethods.GetDictionaryValue((isRightController ? rightControllerTouchKeyCodes : leftControllerTouchKeyCodes), buttonType);
            KeyCode?pressButton = VRTK_SharedMethods.GetDictionaryValue((isRightController ? rightControllerPressKeyCodes : leftControllerPressKeyCodes), buttonType);

            switch (buttonType)
            {
            case ButtonTypes.Trigger:
                switch (pressType)
                {
                case ButtonPressTypes.Touch:
                case ButtonPressTypes.TouchDown:
                case ButtonPressTypes.TouchUp:
                    return(IsButtonPressed(pressType, touchButton, pressButton));

                case ButtonPressTypes.Press:
                case ButtonPressTypes.PressDown:
                case ButtonPressTypes.PressUp:
                    return(IsMouseAliasPress(isRightController, buttonType, pressType) || IsAxisButtonPress(controllerReference, buttonType, pressType));
                }
                break;

            case ButtonTypes.Grip:
                return(IsMouseAliasPress(isRightController, buttonType, pressType) || IsAxisButtonPress(controllerReference, buttonType, pressType));

            case ButtonTypes.Touchpad:
                return(IsButtonPressed(pressType, touchButton, pressButton));

            case ButtonTypes.ButtonOne:
                return(IsButtonPressed(pressType, touchButton, pressButton));

            case ButtonTypes.ButtonTwo:
                return(IsButtonPressed(pressType, touchButton, pressButton));

            case ButtonTypes.StartMenu:
                return(IsButtonPressed(pressType, touchButton, pressButton));
            }
            return(false);
        }
Beispiel #9
0
        protected virtual float CalculateListAverage()
        {
            float listAverage = 0;

            for (int i = 0; i < trackedObjects.Count; i++)
            {
                Transform trackedObj = trackedObjects[i];
                // Get the amount of Y movement that's occured since the last update.
                float previousYPosition = VRTK_SharedMethods.GetDictionaryValue(previousYPositions, trackedObj);
                float deltaYPostion     = Mathf.Abs(previousYPosition - trackedObj.transform.localPosition.y);

                // Convenience code.
                List <float> trackedObjList = VRTK_SharedMethods.GetDictionaryValue(movementList, trackedObj, new List <float>(), true);

                // Cap off the speed.
                if (deltaYPostion > sensitivity)
                {
                    VRTK_SharedMethods.AddListValue(trackedObjList, sensitivity);
                }
                else
                {
                    VRTK_SharedMethods.AddListValue(trackedObjList, deltaYPostion);
                }

                // Keep our tracking list at m_averagePeriod number of elements.
                if (trackedObjList.Count > averagePeriod)
                {
                    trackedObjList.RemoveAt(0);
                }

                // Average out the current tracker's list.
                float sum = 0;
                for (int j = 0; j < trackedObjList.Count; j++)
                {
                    float diffrences = trackedObjList[j];
                    sum += diffrences;
                }
                float avg = sum / averagePeriod;

                // Add the average to the the list average.
                listAverage += avg;
            }

            return(listAverage);
        }
Beispiel #10
0
        public static string GetCommonMessage(CommonMessageKeys messageKey, params object[] parameters)
        {
            CreateIfNotExists();

            string returnMessage = "";
            string outputMessage = VRTK_SharedMethods.GetDictionaryValue(commonMessages, messageKey);

            if (outputMessage != null)
            {
                int outputMessageParts = VRTK_SharedMethods.GetDictionaryValue(commonMessageParts, messageKey);
                if (parameters.Length != outputMessageParts)
                {
                    Array.Resize(ref parameters, outputMessageParts);
                }
                returnMessage = string.Format(outputMessage, parameters);
            }
            return(returnMessage);
        }
        protected virtual bool IsAxisOnHandButtonPress(Dictionary <ButtonTypes, bool> axisHandState, ButtonTypes buttonType, ButtonPressTypes pressType, Vector2 axisValue)
        {
            bool previousAxisState = VRTK_SharedMethods.GetDictionaryValue(axisHandState, buttonType);

            if (pressType == ButtonPressTypes.PressDown && !previousAxisState)
            {
                bool currentAxisState = GetAxisPressState(previousAxisState, axisValue.x);
                VRTK_SharedMethods.AddDictionaryValue(axisHandState, buttonType, currentAxisState, true);
                return(currentAxisState);
            }
            if (pressType == ButtonPressTypes.PressUp && previousAxisState)
            {
                bool currentAxisState = GetAxisPressState(previousAxisState, axisValue.x);
                VRTK_SharedMethods.AddDictionaryValue(axisHandState, buttonType, currentAxisState, true);
                return(!currentAxisState);
            }
            return(false);
        }
Beispiel #12
0
        public static VRTK_ControllerReference GetControllerReference(GameObject controllerObject)
        {
            //Try and get the index from either the actual or alias
            uint controllerIndex = VRTK_SDK_Bridge.GetControllerIndex(controllerObject);

            //If not found then try and get index from the model object
            if (controllerIndex >= uint.MaxValue)
            {
                controllerIndex = VRTK_SDK_Bridge.GetControllerIndex(GetValidObjectFromHand(VRTK_SDK_Bridge.GetControllerModelHand(controllerObject)));
            }

            VRTK_ControllerReference foundReference = VRTK_SharedMethods.GetDictionaryValue(controllerReferences, controllerIndex);

            if (foundReference != null)
            {
                return(foundReference);
            }
            return(new VRTK_ControllerReference(controllerIndex));
        }
Beispiel #13
0
 protected virtual void CancelRoutines(GameObject currentAffectingObject = null)
 {
     if (currentAffectingObject != null)
     {
         Coroutine currentAffectingRoutine = VRTK_SharedMethods.GetDictionaryValue(affectingRoutines, currentAffectingObject);
         if (currentAffectingRoutine != null)
         {
             StopCoroutine(currentAffectingRoutine);
         }
     }
     else
     {
         foreach (KeyValuePair <GameObject, Coroutine> affectingRouting in affectingRoutines)
         {
             if (currentAffectingObject == affectingRouting.Key && affectingRouting.Value != null)
             {
                 StopCoroutine(affectingRouting.Value);
             }
         }
     }
 }
        protected virtual void ManageTouchCollision(VRTK_InteractTouch touchToIgnore, bool ignore)
        {
            Collider[] interactTouchColliders = touchToIgnore.ControllerColliders();
            VRTK_ControllerTrackedCollider trackedColliderValue = VRTK_SharedMethods.GetDictionaryValue(VRTK_ObjectCache.registeredTrackedColliderToInteractTouches, touchToIgnore);

            if (trackedColliderValue != null)
            {
                Collider[] trackedColliders = trackedColliderValue.TrackedColliders();
                interactTouchColliders = interactTouchColliders.Concat(trackedColliders).ToArray();
            }

            for (int touchCollidersIndex = 0; touchCollidersIndex < interactTouchColliders.Length; touchCollidersIndex++)
            {
                for (int localCollidersIndex = 0; localCollidersIndex < localColliders.Length; localCollidersIndex++)
                {
                    if (localColliders[localCollidersIndex] != null && interactTouchColliders[touchCollidersIndex] != null && !ShouldExclude(localColliders[localCollidersIndex].transform))
                    {
                        Physics.IgnoreCollision(localColliders[localCollidersIndex], interactTouchColliders[touchCollidersIndex], ignore);
                    }
                }
            }
        }
Beispiel #15
0
 /// <summary>
 /// The GetPointerLength method retrieves the maximum UI Pointer length for the given pointer ID.
 /// </summary>
 /// <param name="pointerId">The pointer ID for the UI Pointer to recieve the length for.</param>
 /// <returns>The maximum length the UI Pointer will cast to.</returns>
 public static float GetPointerLength(int pointerId)
 {
     return(VRTK_SharedMethods.GetDictionaryValue(pointerLengths, pointerId, float.MaxValue));
 }
 /// <summary>
 /// whether or not the hair touch modifier is currently pressed
 /// if so, pressing a key on the keyboard will only emit touch and hair touch events,
 /// but not a real press.
 /// </summary>
 /// <returns>whether or not the HairTouchModifier is active</returns>
 protected virtual bool IsHairTouchModifierPressed()
 {
     return(Input.GetKey(VRTK_SharedMethods.GetDictionaryValue(keyMappings, "HairTouchModifier", KeyCode.None)));
 }