/// <summary> /// The PopulateHighlighters method sets up the highlighters on the controller model. /// </summary> public virtual void PopulateHighlighters() { if (actualController != null) { highlighterOptions.Clear(); VRTK_SharedMethods.AddDictionaryValue(highlighterOptions, "resetMainTexture", true, true); autoHighlighter = false; baseHighlighter = GetValidHighlighter(); if (baseHighlighter == null) { autoHighlighter = true; baseHighlighter = actualController.AddComponent <VRTK_MaterialColorSwapHighlighter>(); } SDK_BaseController.ControllerHand currentHand = VRTK_DeviceFinder.GetControllerHand(actualController); baseHighlighter.Initialise(null, actualController, highlighterOptions); AddHighlighterToElement(GetElementTransform(VRTK_SDK_Bridge.GetControllerElementPath(SDK_BaseController.ControllerElements.ButtonOne, currentHand)), baseHighlighter, elementHighlighterOverrides.buttonOne); AddHighlighterToElement(GetElementTransform(VRTK_SDK_Bridge.GetControllerElementPath(SDK_BaseController.ControllerElements.ButtonTwo, currentHand)), baseHighlighter, elementHighlighterOverrides.buttonTwo); AddHighlighterToElement(GetElementTransform(VRTK_SDK_Bridge.GetControllerElementPath(SDK_BaseController.ControllerElements.Body, currentHand)), baseHighlighter, elementHighlighterOverrides.body); AddHighlighterToElement(GetElementTransform(VRTK_SDK_Bridge.GetControllerElementPath(SDK_BaseController.ControllerElements.GripLeft, currentHand)), baseHighlighter, elementHighlighterOverrides.gripLeft); AddHighlighterToElement(GetElementTransform(VRTK_SDK_Bridge.GetControllerElementPath(SDK_BaseController.ControllerElements.GripRight, currentHand)), baseHighlighter, elementHighlighterOverrides.gripRight); AddHighlighterToElement(GetElementTransform(VRTK_SDK_Bridge.GetControllerElementPath(SDK_BaseController.ControllerElements.StartMenu, currentHand)), baseHighlighter, elementHighlighterOverrides.startMenu); AddHighlighterToElement(GetElementTransform(VRTK_SDK_Bridge.GetControllerElementPath(SDK_BaseController.ControllerElements.SystemMenu, currentHand)), baseHighlighter, elementHighlighterOverrides.systemMenu); AddHighlighterToElement(GetElementTransform(VRTK_SDK_Bridge.GetControllerElementPath(SDK_BaseController.ControllerElements.Touchpad, currentHand)), baseHighlighter, elementHighlighterOverrides.touchpad); AddHighlighterToElement(GetElementTransform(VRTK_SDK_Bridge.GetControllerElementPath(SDK_BaseController.ControllerElements.TouchpadTwo, currentHand)), baseHighlighter, elementHighlighterOverrides.touchpadTwo); AddHighlighterToElement(GetElementTransform(VRTK_SDK_Bridge.GetControllerElementPath(SDK_BaseController.ControllerElements.Trigger, currentHand)), baseHighlighter, elementHighlighterOverrides.trigger); } }
protected virtual void OnEnable() { trackedObjects.Clear(); movementList.Clear(); previousYPositions.Clear(); initialGaze = Vector3.zero; currentDirection = Vector3.zero; previousDirection = Vector3.zero; averagePeriod = 60; currentSpeed = 0f; movementEngaged = false; previousEngageButton = engageButton; bodyPhysics = (bodyPhysics != null ? bodyPhysics : FindObjectOfType <VRTK_BodyPhysics>()); controllerLeftHand = VRTK_DeviceFinder.GetControllerLeftHand(); controllerRightHand = VRTK_DeviceFinder.GetControllerRightHand(); SetControllerListeners(controllerLeftHand, leftController, ref leftSubscribed); SetControllerListeners(controllerRightHand, rightController, ref rightSubscribed); headset = VRTK_DeviceFinder.HeadsetTransform(); SetControlOptions(controlOptions); playArea = VRTK_DeviceFinder.PlayAreaTransform(); // Initialize the lists. for (int i = 0; i < trackedObjects.Count; i++) { Transform trackedObj = trackedObjects[i]; VRTK_SharedMethods.AddDictionaryValue(movementList, trackedObj, new List <float>(), true); VRTK_SharedMethods.AddDictionaryValue(previousYPositions, trackedObj, trackedObj.transform.localPosition.y, true); } }
protected virtual void AddToCache() { if (IsValid()) { VRTK_SharedMethods.AddDictionaryValue(controllerReferences, storedControllerIndex, this, true); } }
protected virtual void InternalTriggerHapticPulse(VRTK_ControllerReference controllerReference, float strength, float duration, float pulseInterval) { InternalCancelHapticPulse(controllerReference); float hapticPulseStrength = Mathf.Clamp(strength, 0f, 1f); SDK_ControllerHapticModifiers hapticModifiers = VRTK_SDK_Bridge.GetHapticModifiers(); Coroutine hapticLoop = StartCoroutine(SimpleHapticPulseRoutine(controllerReference, duration * hapticModifiers.durationModifier, hapticPulseStrength, pulseInterval * hapticModifiers.intervalModifier)); VRTK_SharedMethods.AddDictionaryValue(hapticLoopCoroutines, controllerReference, hapticLoop); }
protected virtual void SetDeltaTransformData() { for (int i = 0; i < trackedObjects.Count; i++) { Transform trackedObj = trackedObjects[i]; // Get delta postions and rotations VRTK_SharedMethods.AddDictionaryValue(previousYPositions, trackedObj, trackedObj.transform.localPosition.y, true); } }
protected virtual void InteractableObjectUsed(object sender, InteractableObjectEventArgs e) { if (IsValidInteractingObject(e.interactingObject, validUseInteractingObject)) { GameObject useAffectedObject = (objectToAffect == null ? GetActualController(e.interactingObject) : objectToAffect); CancelRoutines(useAffectedObject); VRTK_SharedMethods.AddDictionaryValue(affectingRoutines, useAffectedObject, StartCoroutine(ToggleStateAfterTime(useAffectedObject, gameObjectActiveOnUse, rendererVisibleOnUse, useAppearanceDelay, VRTK_InteractableObject.InteractionType.Use)), true); } }
protected virtual void InternalTriggerHapticPulse(VRTK_ControllerReference controllerReference, AudioClip clip) { InternalCancelHapticPulse(controllerReference); if (!VRTK_SDK_Bridge.HapticPulse(controllerReference, clip)) { //If the SDK Bridge doesn't support audio clips then defer to a local version Coroutine hapticLoop = StartCoroutine(AudioClipHapticsRoutine(controllerReference, clip)); VRTK_SharedMethods.AddDictionaryValue(hapticLoopCoroutines, controllerReference, hapticLoop); } }
protected virtual void InteractableObjectNearUntouched(object sender, InteractableObjectEventArgs e) { if (IsValidInteractingObject(e.interactingObject, validNearTouchInteractingObject)) { GameObject nearTouchAffectedObject = (objectToAffect == null ? GetActualController(e.interactingObject) : objectToAffect); CancelRoutines(nearTouchAffectedObject); nearTouchingObjects.Remove(nearTouchAffectedObject); VRTK_SharedMethods.AddDictionaryValue(affectingRoutines, nearTouchAffectedObject, StartCoroutine(ToggleStateAfterTime(nearTouchAffectedObject, gameObjectActiveByDefault, rendererVisibleByDefault, nearUntouchAppearanceDelay, VRTK_InteractableObject.InteractionType.NearUntouch)), true); } }
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 override void OnEnable() { if (interactTouch == null) { VRTK_Logger.Error(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.REQUIRED_COMPONENT_MISSING_FROM_PARAMETER, "VRTK_ControllerTrackedCollider", "VRTK_InteractTouch", "Interact Touch")); } else { VRTK_SharedMethods.AddDictionaryValue(VRTK_ObjectCache.registeredTrackedColliderToInteractTouches, interactTouch, this); } base.OnEnable(); }
protected virtual void SetControllerButtonValues(ref Dictionary <ButtonTypes, KeyCode?> touchKeyCodes, ref Dictionary <ButtonTypes, KeyCode?> pressKeyCodes, int joystickIndex, int[] touchCodes, int[] pressCodes) { VRTK_SharedMethods.AddDictionaryValue(touchKeyCodes, ButtonTypes.Trigger, StringToKeyCode(joystickIndex, touchCodes[0]), true); VRTK_SharedMethods.AddDictionaryValue(touchKeyCodes, ButtonTypes.Touchpad, StringToKeyCode(joystickIndex, touchCodes[1]), true); VRTK_SharedMethods.AddDictionaryValue(touchKeyCodes, ButtonTypes.ButtonOne, StringToKeyCode(joystickIndex, touchCodes[2]), true); VRTK_SharedMethods.AddDictionaryValue(touchKeyCodes, ButtonTypes.ButtonTwo, StringToKeyCode(joystickIndex, touchCodes[3]), true); VRTK_SharedMethods.AddDictionaryValue(pressKeyCodes, ButtonTypes.Touchpad, StringToKeyCode(joystickIndex, pressCodes[0]), true); VRTK_SharedMethods.AddDictionaryValue(pressKeyCodes, ButtonTypes.ButtonOne, StringToKeyCode(joystickIndex, pressCodes[1]), true); VRTK_SharedMethods.AddDictionaryValue(pressKeyCodes, ButtonTypes.ButtonTwo, StringToKeyCode(joystickIndex, pressCodes[2]), true); VRTK_SharedMethods.AddDictionaryValue(pressKeyCodes, ButtonTypes.StartMenu, StringToKeyCode(joystickIndex, pressCodes[3]), true); }
protected virtual void InternalTriggerHapticPulse(VRTK_ControllerReference controllerReference, float strength, float duration, float pulseInterval) { InternalCancelHapticPulse(controllerReference); float hapticPulseStrength = Mathf.Clamp(strength, 0f, 1f); SDK_ControllerHapticModifiers hapticModifiers = VRTK_SDK_Bridge.GetHapticModifiers(); //TM: added after the SteamVR 2.2 update SDK_SteamVRInputSource inputSource = controllerReference.actual.GetComponent <SDK_SteamVRInputSource>(); SteamVR_Action_Vibration hapticAction = inputSource.HapticAction; Coroutine hapticLoop = StartCoroutine(SimpleHapticPulseRoutine(inputSource, duration * hapticModifiers.durationModifier, hapticPulseStrength, pulseInterval * hapticModifiers.intervalModifier)); VRTK_SharedMethods.AddDictionaryValue(hapticLoopCoroutines, controllerReference, hapticLoop); }
protected virtual void InternalSetOpacity(GameObject model, float alpha, float transitionDuration = 0f) { if (model && model.activeInHierarchy) { if (transitionDuration == 0f) { ChangeRendererOpacity(model, alpha); } else { CancelSetOpacityCoroutine(model); VRTK_SharedMethods.AddDictionaryValue(setOpacityCoroutines, model, StartCoroutine(TransitionRendererOpacity(model, GetInitialAlpha(model), alpha, transitionDuration))); } } }
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); }
protected virtual void ToggleState(GameObject objectToToggle, bool gameObjectShow, bool rendererShow, VRTK_InteractableObject.InteractionType interactionType) { if (objectToToggle != null) { if (!currentRenderStates.ContainsKey(objectToToggle) || currentRenderStates[objectToToggle] != rendererShow) { VRTK_ObjectAppearance.ToggleRenderer(rendererShow, objectToToggle, ObjectToIgnore()); EmitRenderEvent(objectToToggle, rendererShow, interactionType); } if (!currentGameObjectStates.ContainsKey(objectToToggle) || currentGameObjectStates[objectToToggle] != gameObjectShow) { objectToToggle.SetActive(gameObjectShow); EmitGameObjectEvent(objectToToggle, gameObjectShow, interactionType); } VRTK_SharedMethods.AddDictionaryValue(currentRenderStates, objectToToggle, rendererShow, true); VRTK_SharedMethods.AddDictionaryValue(currentGameObjectStates, objectToToggle, gameObjectShow, true); } }
protected virtual void InteractableObjectUnused(object sender, InteractableObjectEventArgs e) { if (IsValidInteractingObject(e.interactingObject, validUseInteractingObject)) { GameObject useAffectedObject = (objectToAffect == null ? GetActualController(e.interactingObject) : objectToAffect); CancelRoutines(useAffectedObject); if (objectToMonitor.IsGrabbed()) { VRTK_SharedMethods.AddDictionaryValue(affectingRoutines, useAffectedObject, StartCoroutine(ToggleStateAfterTime(useAffectedObject, gameObjectActiveOnGrab, rendererVisibleOnGrab, unuseAppearanceDelay, VRTK_InteractableObject.InteractionType.Unuse)), true); } else if (objectToMonitor.IsTouched()) { VRTK_SharedMethods.AddDictionaryValue(affectingRoutines, useAffectedObject, StartCoroutine(ToggleStateAfterTime(useAffectedObject, gameObjectActiveOnTouch, rendererVisibleOnTouch, unuseAppearanceDelay, VRTK_InteractableObject.InteractionType.Unuse)), true); } else if (objectToMonitor.IsNearTouched()) { VRTK_SharedMethods.AddDictionaryValue(affectingRoutines, useAffectedObject, StartCoroutine(ToggleStateAfterTime(useAffectedObject, gameObjectActiveOnNearTouch, rendererVisibleOnNearTouch, unuseAppearanceDelay, VRTK_InteractableObject.InteractionType.NearTouch)), true); } else { VRTK_SharedMethods.AddDictionaryValue(affectingRoutines, useAffectedObject, StartCoroutine(ToggleStateAfterTime(useAffectedObject, gameObjectActiveByDefault, rendererVisibleByDefault, unuseAppearanceDelay, VRTK_InteractableObject.InteractionType.Unuse)), true); } } }