/// <summary> /// Gets the currently active gesture, according to the mouse configuration and mouse button that is down. /// </summary> private ArticulatedHandPose.GestureId SelectGesture() { // Each check needs to verify that both: // 1) The corresponding mouse button is down (meaning the gesture, if defined, should be used) // 2) The gesture is defined. // If only #1 is checked and #2 is not checked, it's possible to "miss" transitions in cases where the user has // the left mouse button down and then while it is down, presses the right button, and then lifts the left. // It's not until both mouse buttons lift in that case, that the state finally "rests" to the DefaultHandGesture. if (KeyInputSystem.GetKey(profile.InteractionButton) && profile.LeftMouseHandGesture != ArticulatedHandPose.GestureId.None) { return(profile.LeftMouseHandGesture); } else if (KeyInputSystem.GetKey(profile.MouseLookButton) && profile.RightMouseHandGesture != ArticulatedHandPose.GestureId.None) { return(profile.RightMouseHandGesture); } else if (KeyInputSystem.GetKey(KeyBinding.FromMouseButton(KeyBinding.MouseButton.Middle)) && profile.MiddleMouseHandGesture != ArticulatedHandPose.GestureId.None) { return(profile.MiddleMouseHandGesture); } else { return(profile.DefaultHandGesture); } }
/// <inheritdoc /> internal override void SimulateInput(ref long lastMotionControllerTrackedTimestamp, SimulatedControllerState state, bool isSimulating, bool isAlwaysVisible, MouseDelta mouseDelta, bool useMouseRotation) { var motionControllerState = state as SimulatedMotionControllerState; if (motionControllerState == null) { return; } bool enableTracking = isAlwaysVisible || isSimulating; if (!motionControllerState.IsTracked && enableTracking) { ResetInput(motionControllerState, isSimulating); } if (isSimulating) { motionControllerState.SimulateInput(mouseDelta, useMouseRotation, profile.MouseRotationSensitivity, profile.MouseControllerRotationSpeed, profile.ControllerJitterAmount); motionControllerState.ButtonState = new SimulatedMotionControllerButtonState { IsSelecting = KeyInputSystem.GetKey(profile.MotionControllerTriggerKey), IsGrabbing = KeyInputSystem.GetKey(profile.MotionControllerGrabKey), IsPressingMenu = KeyInputSystem.GetKey(profile.MotionControllerMenuKey) }; } // Update tracked state of a motion controller. // If hideTimeout value is null, motion controllers will stay visible after tracking stops. // TODO: DateTime.UtcNow can be quite imprecise, better use Stopwatch.GetTimestamp // https://stackoverflow.com/questions/2143140/c-sharp-datetime-now-precision DateTime currentTime = DateTime.UtcNow; if (enableTracking) { motionControllerState.IsTracked = true; lastMotionControllerTrackedTimestamp = currentTime.Ticks; } else { float timeSinceTracking = (float)currentTime.Subtract(new DateTime(lastMotionControllerTrackedTimestamp)).TotalSeconds; if (timeSinceTracking > profile.ControllerHideTimeout) { motionControllerState.IsTracked = false; } } }
private Vector3 GetCameraControlTranslation(Transform transform) { Vector3 deltaPosition = Vector3.zero; // Support fly up/down keypresses if the current project maps it. This isn't a standard // Unity InputManager mapping, so it has to gracefully fail if unavailable. if (this.isFlyKeypressEnabled) { try { deltaPosition += InputCurve(UnityEngine.Input.GetAxis("Fly")) * transform.up; } catch (System.Exception) { this.isFlyKeypressEnabled = false; } } else { // use page up/down in this case deltaPosition += GetKeyDir("page down", "page up") * Vector3.up; } deltaPosition += InputCurve(UnityEngine.Input.GetAxis(profile.MoveHorizontal)) * transform.right; Vector3 forward; Vector3 up; if (profile.CurrentControlMode == InputSimulationControlMode.Walk) { up = Vector3.up; forward = Vector3.ProjectOnPlane(transform.forward, up).normalized; } else { forward = transform.forward; up = transform.up; } deltaPosition += InputCurve(UnityEngine.Input.GetAxis(profile.MoveVertical)) * forward; deltaPosition += InputCurve(UnityEngine.Input.GetAxis(profile.MoveUpDown)) * up; float accel = KeyInputSystem.GetKey(profile.FastControlKey) ? profile.ControlFastSpeed : profile.ControlSlowSpeed; return(accel * deltaPosition * Time.deltaTime); }
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); } }