/// <summary> /// Update hand state based on keyboard and mouse input /// </summary> private void SimulateUserInput(MouseDelta mouseDelta) { float time = Time.time; if (KeyInputSystem.GetKeyDown(profile.ToggleLeftHandKey)) { IsAlwaysVisibleLeft = !IsAlwaysVisibleLeft; } if (KeyInputSystem.GetKeyDown(profile.ToggleRightHandKey)) { IsAlwaysVisibleRight = !IsAlwaysVisibleRight; } if (!Application.isFocused) { isSimulatingLeft = false; isSimulatingRight = false; } else { if (KeyInputSystem.GetKeyDown(profile.LeftHandManipulationKey)) { isSimulatingLeft = true; if (lastSimulationLeft > 0.0f && time - lastSimulationLeft <= profile.DoublePressTime) { IsAlwaysVisibleLeft = !IsAlwaysVisibleLeft; } lastSimulationLeft = time; } if (KeyInputSystem.GetKeyUp(profile.LeftHandManipulationKey)) { isSimulatingLeft = false; } if (KeyInputSystem.GetKeyDown(profile.RightHandManipulationKey)) { isSimulatingRight = true; if (lastSimulationRight > 0.0f && time - lastSimulationRight <= profile.DoublePressTime) { IsAlwaysVisibleRight = !IsAlwaysVisibleRight; } lastSimulationRight = time; } if (KeyInputSystem.GetKeyUp(profile.RightHandManipulationKey)) { isSimulatingRight = false; } } mouseRotation.Update(profile.HandRotateButton, cancelRotationKey, false); SimulateHandInput(ref lastHandTrackedTimestampLeft, HandStateLeft, isSimulatingLeft, IsAlwaysVisibleLeft, mouseDelta, mouseRotation.IsRotating); SimulateHandInput(ref lastHandTrackedTimestampRight, HandStateRight, isSimulatingRight, IsAlwaysVisibleRight, mouseDelta, mouseRotation.IsRotating); float gestureAnimDelta = profile.HandGestureAnimationSpeed * Time.deltaTime; HandStateLeft.GestureBlending += gestureAnimDelta; HandStateRight.GestureBlending += gestureAnimDelta; }
/// <summary> /// Update controller state based on keyboard and mouse input /// </summary> protected virtual void SimulateUserInput(MouseDelta mouseDelta) { float time = Time.time; if (KeyInputSystem.GetKeyDown(profile.ToggleLeftControllerKey)) { IsAlwaysVisibleLeft = !IsAlwaysVisibleLeft; } if (KeyInputSystem.GetKeyDown(profile.ToggleRightControllerKey)) { IsAlwaysVisibleRight = !IsAlwaysVisibleRight; } if (!Application.isFocused && !KeyInputSystem.SimulatingInput) { IsSimulatingLeft = false; IsSimulatingRight = false; } else { if (KeyInputSystem.GetKeyDown(profile.LeftControllerManipulationKey)) { IsSimulatingLeft = true; if (lastSimulationLeft > 0.0f && time - lastSimulationLeft <= profile.DoublePressTime) { IsAlwaysVisibleLeft = !IsAlwaysVisibleLeft; } lastSimulationLeft = time; } if (KeyInputSystem.GetKeyUp(profile.LeftControllerManipulationKey)) { IsSimulatingLeft = false; } if (KeyInputSystem.GetKeyDown(profile.RightControllerManipulationKey)) { IsSimulatingRight = true; if (lastSimulationRight > 0.0f && time - lastSimulationRight <= profile.DoublePressTime) { IsAlwaysVisibleRight = !IsAlwaysVisibleRight; } lastSimulationRight = time; } if (KeyInputSystem.GetKeyUp(profile.RightControllerManipulationKey)) { IsSimulatingRight = false; } if (isSimulatingGaze) { lastSimulationGaze = time; } } mouseRotation.Update(profile.ControllerRotateButton, cancelRotationKey, false); SimulateInput(ref lastInputTrackedTimestampLeft, InputStateLeft, IsSimulatingLeft, IsAlwaysVisibleLeft, mouseDelta, mouseRotation.IsRotating); SimulateInput(ref lastInputTrackedTimestampRight, InputStateRight, IsSimulatingRight, IsAlwaysVisibleRight, mouseDelta, mouseRotation.IsRotating); SimulateInput(ref lastInputTrackedTimestampGaze, InputStateGaze, isSimulatingGaze, false, mouseDelta, mouseRotation.IsRotating); }
private void Update() { bool shortcutPressed = true; bool shortcutDown = false; // Checks to make sure that all keys are pressed and that one of the required shortcut keys was pressed on this frame // before bringing up the shortcut foreach (KeyCode key in helpGuideShortcutKeys) { shortcutPressed &= KeyInputSystem.GetKey(KeyBinding.FromKey(key)); shortcutDown |= KeyInputSystem.GetKeyDown(KeyBinding.FromKey(key)); } if (shortcutPressed && shortcutDown) { helpGuideVisual.SetActive(!helpGuideVisual.activeSelf); helpGuideShortcutTip.SetActive(false); } }
/// <summary> /// Start or stop rotation based on the key binding. /// </summary> /// <remarks> /// Also manages shared features such as cursor visibility that can be activated by different rotation providers. /// </remarks> public void Update(KeyBinding rotationKey, KeyBinding cancelRotationKey, bool toggle) { bool wasRotating = isRotating; // Only allow the mouse to control rotation when Unity has focus. // This enables the player to temporarily alt-tab away without having the player // look around randomly back in the Unity Game window. if (!Application.isFocused) { isRotating = false; } else { if (toggle) { if (isRotating) { // Pressing escape will stop capture isRotating = !KeyInputSystem.GetKeyDown(cancelRotationKey); } else { // Capture focus when starting rotation isRotating = KeyInputSystem.GetKeyDown(rotationKey); } } else { // Rotate only while key is pressed isRotating = KeyInputSystem.GetKey(rotationKey); } } if (!wasRotating && isRotating) { OnStartRotating(rotationKey); } else if (wasRotating && !isRotating) { OnEndRotating(rotationKey); } }
private ArticulatedHandPose.GestureId ToggleGesture(ArticulatedHandPose.GestureId gesture) { // See comments in SelectGesture for why both the button down and gesture are checked. if (KeyInputSystem.GetKeyDown(profile.InteractionButton) && profile.LeftMouseHandGesture != ArticulatedHandPose.GestureId.None) { return(gesture != profile.LeftMouseHandGesture ? profile.LeftMouseHandGesture : profile.DefaultHandGesture); } else if (KeyInputSystem.GetKeyDown(profile.MouseLookButton) && profile.RightMouseHandGesture != ArticulatedHandPose.GestureId.None) { return(gesture != profile.RightMouseHandGesture ? profile.RightMouseHandGesture : profile.DefaultHandGesture); } else if (KeyInputSystem.GetKeyDown(KeyBinding.FromMouseButton(KeyBinding.MouseButton.Middle)) && profile.MiddleMouseHandGesture != ArticulatedHandPose.GestureId.None) { return(gesture != profile.MiddleMouseHandGesture ? profile.MiddleMouseHandGesture : profile.DefaultHandGesture); } else { // 'None' will not change the gesture return(ArticulatedHandPose.GestureId.None); } }
/// <summary> /// Update hand state based on keyboard and mouse input /// </summary> private void SimulateUserInput(MouseDelta mouseDelta) { float time = Time.time; if (KeyInputSystem.GetKeyDown(profile.ToggleLeftHandKey)) { IsAlwaysVisibleLeft = !IsAlwaysVisibleLeft; } if (KeyInputSystem.GetKeyDown(profile.ToggleRightHandKey)) { IsAlwaysVisibleRight = !IsAlwaysVisibleRight; } if (!Application.isFocused && !KeyInputSystem.SimulatingInput) { isSimulatingLeft = false; isSimulatingRight = false; } else { if (KeyInputSystem.GetKeyDown(profile.LeftHandManipulationKey)) { isSimulatingLeft = true; if (lastSimulationLeft > 0.0f && time - lastSimulationLeft <= profile.DoublePressTime) { IsAlwaysVisibleLeft = !IsAlwaysVisibleLeft; } lastSimulationLeft = time; } if (KeyInputSystem.GetKeyUp(profile.LeftHandManipulationKey)) { isSimulatingLeft = false; } if (KeyInputSystem.GetKeyDown(profile.RightHandManipulationKey)) { isSimulatingRight = true; if (lastSimulationRight > 0.0f && time - lastSimulationRight <= profile.DoublePressTime) { IsAlwaysVisibleRight = !IsAlwaysVisibleRight; } lastSimulationRight = time; } if (KeyInputSystem.GetKeyUp(profile.RightHandManipulationKey)) { isSimulatingRight = false; } if (isSimulatingGaze) { lastSimulationGaze = time; } } mouseRotation.Update(profile.HandRotateButton, cancelRotationKey, false); SimulateHandInput(ref lastHandTrackedTimestampLeft, HandStateLeft, isSimulatingLeft, IsAlwaysVisibleLeft, mouseDelta, mouseRotation.IsRotating); SimulateHandInput(ref lastHandTrackedTimestampRight, HandStateRight, isSimulatingRight, IsAlwaysVisibleRight, mouseDelta, mouseRotation.IsRotating); SimulateHandInput(ref lastHandTrackedTimestampGaze, HandStateGaze, isSimulatingGaze, false, mouseDelta, mouseRotation.IsRotating); // This line explicitly uses unscaledDeltaTime because we don't want input simulation // to lag when the time scale is set to a value other than 1. Input should still continue // to move freely. float gestureAnimDelta = profile.HandGestureAnimationSpeed * Time.unscaledDeltaTime; HandStateLeft.GestureBlending += gestureAnimDelta; HandStateRight.GestureBlending += gestureAnimDelta; HandStateGaze.GestureBlending = 1.0f; }