protected virtual bool IsValidInteractingObject(GameObject givenObject, ValidInteractingObject givenInteractingObjectValidType) { if (gameObject.activeInHierarchy) { VRTK_ControllerReference controllerReference = VRTK_ControllerReference.GetControllerReference(givenObject); switch (givenInteractingObjectValidType) { case ValidInteractingObject.Anything: return(true); case ValidInteractingObject.EitherController: return(VRTK_ControllerReference.IsValid(controllerReference)); case ValidInteractingObject.NeitherController: return(!VRTK_ControllerReference.IsValid(controllerReference)); case ValidInteractingObject.LeftControllerOnly: return(VRTK_ControllerReference.IsValid(controllerReference) && controllerReference.hand == SDK_BaseController.ControllerHand.Left); case ValidInteractingObject.RightControllerOnly: return(VRTK_ControllerReference.IsValid(controllerReference) && controllerReference.hand == SDK_BaseController.ControllerHand.Right); } } return(false); }
/// <summary> /// The GetButtonAxis method retrieves the current X/Y axis values for the given button type on the given controller reference. /// </summary> /// <param name="buttonType">The type of button to check for the axis on.</param> /// <param name="controllerReference">The reference to the controller to check the button axis on.</param> /// <returns>A Vector2 of the X/Y values of the button axis. If no axis values exist for the given button, then a Vector2.Zero is returned.</returns> public override Vector2 GetButtonAxis(ButtonTypes buttonType, VRTK_ControllerReference controllerReference) { if (!VRTK_ControllerReference.IsValid(controllerReference)) { return(Vector2.zero); } bool isRightController = (controllerReference.hand == ControllerHand.Right); if ((isRightController && cachedRightTracker == null) || (!isRightController && cachedLeftTracker == null)) { return(Vector2.zero); } switch (buttonType) { case ButtonTypes.Trigger: return(new Vector2(GetAxisValue((isRightController ? cachedRightTracker.triggerAxisName : cachedLeftTracker.triggerAxisName)), 0f)); case ButtonTypes.Grip: return(new Vector2(GetAxisValue((isRightController ? cachedRightTracker.gripAxisName : cachedLeftTracker.gripAxisName)), 0f)); case ButtonTypes.Touchpad: return(new Vector2(GetAxisValue((isRightController ? cachedRightTracker.touchpadHorizontalAxisName : cachedLeftTracker.touchpadHorizontalAxisName)), GetAxisValue((isRightController ? cachedRightTracker.touchpadVerticalAxisName : cachedLeftTracker.touchpadVerticalAxisName)))); } return(Vector2.zero); }
/// <summary> /// The PointerExit method emits a DestinationMarkerExit event when the pointer leaves a previously entered object. /// </summary> /// <param name="givenHit">The previous valid collision.</param> public virtual void PointerExit(RaycastHit givenHit) { ResetHoverSelectionTimer(givenHit.collider); if (givenHit.transform != null && (!ControllerRequired() || VRTK_ControllerReference.IsValid(controllerReference))) { OnDestinationMarkerExit(SetDestinationMarkerEvent(givenHit.distance, givenHit.transform, givenHit, givenHit.point, controllerReference, false, GetCursorRotation())); StopUseAction(); } }
protected virtual void CancelOn(GameObject givenObject) { VRTK_ControllerReference controllerReference = VRTK_ControllerReference.GetControllerReference(givenObject); if (VRTK_ControllerReference.IsValid(controllerReference)) { CancelHaptics(controllerReference); } }
protected virtual void UseHaptics(object sender, InteractableObjectEventArgs e) { VRTK_ControllerReference controllerReference = VRTK_ControllerReference.GetControllerReference(e.interactingObject); if (VRTK_ControllerReference.IsValid(controllerReference)) { HapticsOnUse(controllerReference); } }
/// <summary> /// The SetStateByControllerReference method sets the object state based on the controller type of the given controller reference. /// </summary> /// <param name="controllerReference">A controller reference to check for the controller type of.</param> public virtual void SetStateByControllerReference(VRTK_ControllerReference controllerReference) { if (VRTK_ControllerReference.IsValid(controllerReference)) { SDK_BaseController.ControllerType foundControllerType = VRTK_DeviceFinder.GetCurrentControllerType(controllerReference); if (foundControllerType != SDK_BaseController.ControllerType.Undefined && controllerType == foundControllerType) { ToggleObject(); } } }
protected virtual void LateUpdate() { if (controller != null) { pointerEventData.pointerId = (int)VRTK_ControllerReference.GetRealIndex(controllerReference); } if (controllerRenderModel == null && VRTK_ControllerReference.IsValid(controllerReference)) { controllerRenderModel = VRTK_SDK_Bridge.GetControllerRenderModel(controllerReference); } }
protected virtual Transform GetPointerOriginTransform() { VRTK_ControllerReference controllerReference = GetControllerReference(attachedTo); if (VRTK_ControllerReference.IsValid(controllerReference) && (cachedAttachedHand != controllerReference.hand || cachedPointerAttachPoint == null)) { cachedPointerAttachPoint = controllerReference.model.transform.Find(VRTK_SDK_Bridge.GetControllerElementPath(SDK_BaseController.ControllerElements.AttachPoint, controllerReference.hand)); cachedAttachedHand = controllerReference.hand; } return(cachedPointerAttachPoint != null ? cachedPointerAttachPoint : transform); }
protected override void ControllerReady(VRTK_ControllerReference controllerReference) { if (VRTK_ControllerReference.IsValid(controllerReference)) { VRTK_InteractTouch foundTouch = controllerReference.scriptAlias.GetComponentInChildren <VRTK_InteractTouch>(); if (interactTouchToIgnore.Contains(foundTouch)) { disableControllerCollidersRoutine = StartCoroutine(DisableControllerColliderAtEndOfFrame(foundTouch)); } } }
protected virtual void LateUpdate() { if (controllerEvents != null) { pointerEventData.pointerId = (int)VRTK_ControllerReference.GetRealIndex(GetControllerReference()); VRTK_SharedMethods.AddDictionaryValue(pointerLengths, pointerEventData.pointerId, maximumLength, true); } if (controllerRenderModel == null && VRTK_ControllerReference.IsValid(GetControllerReference())) { controllerRenderModel = VRTK_SDK_Bridge.GetControllerRenderModel(GetControllerReference()); } }
protected virtual GameObject GetActualController(GameObject givenObject) { VRTK_ControllerReference controllerReference = VRTK_ControllerReference.GetControllerReference(givenObject); if (VRTK_ControllerReference.IsValid(controllerReference)) { return(controllerReference.actual); } else { return(givenObject); } }
/// <summary> /// The GetAngularVelocity method is used to determine the current angular velocity of the tracked object on the given controller reference. /// </summary> /// <param name="controllerReference">The reference to the tracked object to check for.</param> /// <returns>A Vector3 containing the current angular velocity of the tracked object.</returns> public override Vector3 GetAngularVelocity(VRTK_ControllerReference controllerReference) { if (VRTK_ControllerReference.IsValid(controllerReference)) { if (controllerReference.hand == ControllerHand.Left && cachedLeftVelocityEstimator != null) { return(cachedLeftVelocityEstimator.GetAngularVelocityEstimate()); } else if (controllerReference.hand == ControllerHand.Right && cachedRightVelocityEstimator != null) { return(cachedRightVelocityEstimator.GetAngularVelocityEstimate()); } } return(Vector3.zero); }
protected virtual void AttemptSecondaryGrab(VRTK_InteractableObject grabbableObject) { if (attemptSecondaryGrab) { SDK_BaseController.ControllerHand currentHand = VRTK_DeviceFinder.GetControllerHand(interactTouch.gameObject); VRTK_ControllerReference oppositeControllerReference = VRTK_ControllerReference.GetControllerReference(VRTK_DeviceFinder.GetOppositeHand(currentHand)); if (VRTK_ControllerReference.IsValid(oppositeControllerReference)) { secondaryInteractTouch = (secondaryInteractTouch == null ? oppositeControllerReference.scriptAlias.GetComponentInChildren <VRTK_InteractTouch>() : secondaryInteractTouch); secondaryInteractGrab = (secondaryInteractGrab == null ? oppositeControllerReference.scriptAlias.GetComponentInChildren <VRTK_InteractGrab>() : secondaryInteractGrab); secondaryInteractTouch.ForceStopTouching(); secondaryInteractTouch.ForceTouch(grabbableObject.gameObject); secondaryInteractGrab.AttemptGrab(); } } }
protected virtual Transform GetPointerOriginTransform() { VRTK_ControllerReference controllerReference = GetControllerReference((controllingPointer != null ? controllingPointer.attachedTo : null)); if (VRTK_ControllerReference.IsValid(controllerReference) && (cachedAttachedHand != controllerReference.hand || cachedPointerAttachPoint == null)) { cachedPointerAttachPoint = controllerReference.model.transform.Find(VRTK_SDK_Bridge.GetControllerElementPath(SDK_BaseController.ControllerElements.AttachPoint, controllerReference.hand)); cachedAttachedHand = controllerReference.hand; //adding debug for hand //Debug.DrawRay(controllerReference.actual.transform.position, controllerReference.actual.transform.forward * 2, Color.red); pointerOriginTransformFollow.gameObject.SetActive(false); } return(cachedPointerAttachPoint != null ? cachedPointerAttachPoint : transform); }
/// <summary> /// The PointerEnter method emits a DestinationMarkerEnter event when the pointer first enters a valid object, it emits a DestinationMarkerHover for every following frame that the pointer stays over the valid object. /// </summary> /// <param name="givenHit">The valid collision.</param> public virtual void PointerEnter(RaycastHit givenHit) { if (enabled && givenHit.transform != null && (!ControllerRequired() || VRTK_ControllerReference.IsValid(controllerReference))) { SetHoverSelectionTimer(givenHit.collider); DestinationMarkerEventArgs destinationEventArgs = SetDestinationMarkerEvent(givenHit.distance, givenHit.transform, givenHit, givenHit.point, controllerReference, false, GetCursorRotation()); if (pointerRenderer != null && givenHit.collider != pointerRenderer.GetDestinationHit().collider) { OnDestinationMarkerEnter(destinationEventArgs); } else { OnDestinationMarkerHover(destinationEventArgs); } StartUseAction(givenHit.transform); } }
/// <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); }
protected virtual void CheckControllersReady() { RegisterLeftControllerReady(); RegisterRightControllerReady(); VRTK_ControllerReference leftRef = VRTK_DeviceFinder.GetControllerReferenceLeftHand(); VRTK_ControllerReference rightRef = VRTK_DeviceFinder.GetControllerReferenceRightHand(); if (VRTK_ControllerReference.IsValid(leftRef)) { ControllerReady(leftRef); } if (VRTK_ControllerReference.IsValid(rightRef)) { ControllerReady(rightRef); } }
protected virtual void Ungrab(bool carryMomentum, VRTK_ControllerReference controllerReference, GameObject target) { if (bodyPhysics == null) { return; } isClimbing = false; if (positionRewind != null && IsHeadsetColliding()) { positionRewind.RewindPosition(); } if (IsBodyColliding() && !IsHeadsetColliding()) { bodyPhysics.ForceSnapToFloor(); } bodyPhysics.enableBodyCollisions = true; if (carryMomentum) { Vector3 velocity = Vector3.zero; if (VRTK_ControllerReference.IsValid(controllerReference)) { velocity = -VRTK_DeviceFinder.GetControllerVelocity(controllerReference); if (usePlayerScale) { velocity = playArea.TransformVector(velocity); } else { velocity = playArea.TransformDirection(velocity); } } bodyPhysics.ApplyBodyVelocity(velocity, true, true); } grabbingController = null; climbingObject = null; OnPlayerClimbEnded(SetPlayerClimbEvent(controllerReference, target)); }
protected virtual void Rotate() { if (!rotationActivated) { return; } if (rotationTrackingController == TrackingController.BothControllers && VRTK_ControllerReference.IsValid(leftControllerReference) && VRTK_ControllerReference.IsValid(rightControllerReference)) { Vector2 currentRotationAngle = GetControllerRotation(); float newAngle = Vector2.Angle(currentRotationAngle, previousRotationAngle) * Mathf.Sign(Vector3.Cross(currentRotationAngle, previousRotationAngle).z); RotateByAngle(newAngle); previousRotationAngle = currentRotationAngle; } else { float leftControllerAngle = (TrackingControllerEnabled(rotationTrackingController, TrackingController.LeftController, rotationLeftControllerActivated) ? VRTK_DeviceFinder.GetControllerAngularVelocity(leftControllerReference).y : 0f); float rightControllerAngle = (TrackingControllerEnabled(rotationTrackingController, TrackingController.RightController, rotationRightControllerActivated) ? VRTK_DeviceFinder.GetControllerAngularVelocity(rightControllerReference).y : 0f); RotateByAngle(leftControllerAngle + rightControllerAngle); } }
protected virtual Vector3 GetRightControllerPosition() { return(VRTK_ControllerReference.IsValid(rightControllerReference) ? rightControllerReference.actual.transform.localPosition : Vector3.zero); }
// Token: 0x06001959 RID: 6489 RVA: 0x00087174 File Offset: 0x00085374 public virtual void PointerEnter(RaycastHit givenHit) { if (base.enabled && givenHit.transform != null && (!this.ControllerRequired() || VRTK_ControllerReference.IsValid(this.controllerReference))) { this.SetHoverSelectionTimer(givenHit.collider); DestinationMarkerEventArgs e = this.SetDestinationMarkerEvent(givenHit.distance, givenHit.transform, givenHit, givenHit.point, this.controllerReference, false, this.GetCursorRotation()); if (this.pointerRenderer != null && givenHit.collider != this.pointerRenderer.GetDestinationHit().collider) { this.OnDestinationMarkerEnter(e); } else { this.OnDestinationMarkerHover(e); } this.StartUseAction(givenHit.transform); } }
protected override void ControllerReady(VRTK_ControllerReference passedControllerReference) { if (sdkManager != null && sdkManager.loadedSetup != null && gameObject.activeInHierarchy && VRTK_ControllerReference.IsValid(passedControllerReference)) { Cleanup(true); controllerReference = passedControllerReference; controllerEvents = (controllerEvents == null ? controllerReference.scriptAlias.GetComponentInChildren <VRTK_ControllerEvents>() : controllerEvents); ManageActivationListeners(true); SetupRigidbody(); SetupColliders(); SetupFollower(); ToggleColliders(activationButton == VRTK_ControllerEvents.ButtonAlias.Undefined); } }
protected virtual VRTK_ControllerReference GetRightThenLeftReference() { VRTK_ControllerReference controllerReference = VRTK_ControllerReference.GetControllerReference(SDK_BaseController.ControllerHand.Right); return(VRTK_ControllerReference.IsValid(controllerReference) ? controllerReference : VRTK_ControllerReference.GetControllerReference(SDK_BaseController.ControllerHand.Left)); }