public override void StartReaction(object o, EventArgs e) { InteractableObjectEventArgs interactionArgs = (InteractableObjectEventArgs)e; if (interactionArgs != null) { partsToActivate = null; if (VRTK_SDK_Bridge.IsControllerLeftHand(interactionArgs.interactingObject) || VRTK_SDK_Bridge.GetHandSDK().GetLeftHand() == interactionArgs.interactingObject) { partsToActivate = leftBodyParts; } else if (VRTK_SDK_Bridge.IsControllerRightHand(interactionArgs.interactingObject) || VRTK_SDK_Bridge.GetHandSDK().GetRightHand() == interactionArgs.interactingObject) { partsToActivate = rightBodyParts; } if (partsToActivate != null) { foreach (HumanBodyBones bodyPart in partsToActivate) { hapticManager.PlayPattern(bodyPart, hapticPattern); } } } }
public virtual bool IsGestureOccuring(SDK_BaseGestureLibrary.Hand handToCheck) { // if not detected, it cannot be gesturing if (!VRTK_SDK_Bridge.GetHandSDK().GetGestureLibrary().IsHandDetected(handToCheck)) { return(false); } bool isGestureOccuring = true; if (handSpecific && specificHand != handToCheck) { return(false); } for (int gestureConditionIndex = 0; gestureConditionIndex < gestureConditionList.Count; gestureConditionIndex++) { GestureCondition condition = gestureConditionList[gestureConditionIndex]; bool thisConditionIsMet = true; thisConditionIsMet = GetBoolValue(condition.featureToCheck, handToCheck) == condition.featureValue; isGestureOccuring = isGestureOccuring && thisConditionIsMet; // Quick return, if at any time one is false, then it would not execute if (!isGestureOccuring) { return(isGestureOccuring); } } return(isGestureOccuring); }
public override bool IsGestureOccuring(SDK_BaseGestureLibrary.Hand specificHand) { // if not detected, it cannot be gesturing if (!VRTK_SDK_Bridge.GetHandSDK().GetGestureLibrary().IsHandDetected(specificHand)) { return(false); } // OpenMG has a habit of claiming gestures are occuring at the start of the scene before hands are even detected. // this delay ensures that no gesture fire until the system is fully started if (Time.time < startupDelayTime) { return(false); } if (!allowedWhileHoldingObjects) { if (IsHoldingObject(SDK_BaseGestureLibrary.Hand.Left) || IsHoldingObject(SDK_BaseGestureLibrary.Hand.Right)) { return(false); } } bool isCooldownActive = Time.time <= (gestureCooldownStartTime + gestureCooldown); bool isCurrentStateOccuring = advancedGestureStateList[currentGestureStateIndex].coreGesture.IsGestureOccuring(specificHand); foreach (AdvancedGestureCondition advCondition in advancedGestureStateList[currentGestureStateIndex].AdvancedGestureConditionList) { isCurrentStateOccuring = isCurrentStateOccuring && advCondition.IsConditionOccuring(specificHand, this); } if (isCurrentStateOccuring && advancedGestureStateList.Count == currentGestureStateIndex + 1) { if (isCooldownActive == false) { gestureCooldownStartTime = Time.time; } return(true); } else if (isCurrentStateOccuring) { currentGestureStateIndex++; gestureStartTime = Time.time; prevLeftPalmPosition = GetLeftHandPosition(); prevRightPalmPosition = GetRightHandPosition(); } else { if (advancedGestureStateList[currentGestureStateIndex].holdTime != 0 && advancedGestureStateList[currentGestureStateIndex].holdTime + gestureStartTime <= Time.time) { ResetGestureChain(); } } return(isCooldownActive); }
/// <summary> /// Returns true if the specified hand is holding an object and false otherwise. /// </summary> public bool IsHoldingObject(SDK_BaseGestureLibrary.Hand hand) { Transform handRoot = VRTK_SDK_Bridge.GetHandSDK().GetRootTransform(); if (handRoot == null) { // if the hand is not visible, the user isn't holding an object return(false); } if (hand == SDK_BaseGestureLibrary.Hand.Left && IsInteractGrabValid(cachedLeftHandGrabber)) { // if not null, an object is being held return(cachedLeftHandGrabber.GetGrabbedObject() != null); } if (hand == SDK_BaseGestureLibrary.Hand.Right && IsInteractGrabValid(cachedRightHandGrabber)) { // if not null, an object is being held return(cachedRightHandGrabber.GetGrabbedObject() != null); } // either caches aren't set up, or hands are no longer being tracked VRTK_InteractGrab[] handGrabbers = handRoot.GetComponentsInChildren <VRTK_InteractGrab>(); foreach (VRTK_InteractGrab grabber in handGrabbers) { if (!IsInteractGrabValid(grabber)) { continue; } if (grabber.controllerEvents is GestureControllerEvent) { GestureControllerEvent gestureController = (GestureControllerEvent)grabber.controllerEvents; if (gestureController.controllerHandId == SDK_BaseGestureLibrary.Hand.Left) { cachedLeftHandGrabber = grabber; } else if (gestureController.controllerHandId == SDK_BaseGestureLibrary.Hand.Right) { cachedRightHandGrabber = grabber; } if (gestureController.controllerHandId == hand) { return(grabber.GetGrabbedObject() != null); } } } // fell through because hand was not found return(false); }
public override bool IsGestureOccuring(SDK_BaseGestureLibrary.Hand specificHand) { // if not detected, it cannot be gesturing if (VRTK_SDK_Bridge.GetHandSDK().GetGestureLibrary() != null && !VRTK_SDK_Bridge.GetHandSDK().GetGestureLibrary().IsHandDetected(specificHand)) { return(false); } // OpenMG has a habit of claiming gestures are occuring at the start of the scene before hands are even detected. // this delay ensures that no gesture fire until the system is fully started if (Time.time < startupDelayTime) { return(false); } // If this is not the specified hand, then the gesture cannot be occuring if (advancedGestureStateList[currentGestureStateIndex].coreGesture.handSpecific && advancedGestureStateList[currentGestureStateIndex].coreGesture.specificHand != specificHand) { return(false); } if (!allowedWhileHoldingObjects) { if (IsHoldingObject(SDK_BaseGestureLibrary.Hand.Left) || IsHoldingObject(SDK_BaseGestureLibrary.Hand.Right)) { return(false); } } bool isCooldownActive = Time.time <= (gestureCooldownStartTime + gestureCooldown); // Condition for cooldown has not been met if (!isCooldownActive) { cooldownHasStarted = false; } // Check core gesture first bool isCurrentStateOccuring = advancedGestureStateList[currentGestureStateIndex].coreGesture.IsGestureOccuring(specificHand); // If the core gesture is occuring, then start checking the rest of the avanced gesture states if (isCurrentStateOccuring) { if (!gestureHasStarted) { gestureHasStarted = true; gestureStartTime = Time.time; } // Check every Advanced Gesture Condition for the current Gesture State foreach (AdvancedGestureCondition advCondition in advancedGestureStateList[currentGestureStateIndex].AdvancedGestureConditionList) { isCurrentStateOccuring = isCurrentStateOccuring && advCondition.IsConditionOccuring(specificHand, this); } // Core gesture and all advanced Gesture States have been satisifed if (isCurrentStateOccuring && advancedGestureStateList.Count == currentGestureStateIndex + 1) { // Gesture hasn't triggered the cool down yet, after this frame, that will change if (!isCooldownActive && !cooldownHasStarted) { gestureCooldownStartTime = Time.time; cooldownHasStarted = true; return(true); } // Gesture is in cooldown, but the user hasn't released the first occurrence of the gesture else if (gestureStartTime <= gestureCooldownStartTime) { return(true); } // Gesture is in cooldown, so the gesture cannot occur else { return(false); } } // Core gesture has occured, but not every Gesture State has occured yet else if (isCurrentStateOccuring) { currentGestureStateIndex++; prevLeftPalmPosition = GetLeftHandPosition(); prevRightPalmPosition = GetRightHandPosition(); } else { if (advancedGestureStateList[currentGestureStateIndex].holdTime != 0 && advancedGestureStateList[currentGestureStateIndex].holdTime + gestureStartTime <= Time.time) { ResetGestureChain(); } return(false); } } // Core gesture is not occuring else { gestureHasStarted = false; return(false); } // The advanced gesture is not occuring return(false); }