/// Apply changes to one controller and update tracking internal abstract void SimulateInput( ref long lastHandTrackedTimestamp, SimulatedControllerState state, bool isSimulating, bool isAlwaysVisible, MouseDelta mouseDelta, bool useMouseRotation);
internal override void ResetInput(SimulatedControllerState state, bool isSimulating) { base.ResetInput(state, isSimulating); var motionControllerState = state as SimulatedMotionControllerState; motionControllerState.ResetButtonStates(); motionControllerState.ResetRotation(); }
internal override void ResetInput(SimulatedControllerState state, bool isSimulating) { base.ResetInput(state, isSimulating); var handState = state as SimulatedHandState; handState.Gesture = profile.DefaultHandGesture; handState.ResetGesture(); handState.ResetRotation(); }
/// Apply changes to one hand and update tracking internal override void SimulateInput( ref long lastHandTrackedTimestamp, SimulatedControllerState state, bool isSimulating, bool isAlwaysVisible, MouseDelta mouseDelta, bool useMouseRotation) { var handState = state as SimulatedHandState; bool enableTracking = isAlwaysVisible || isSimulating; if (!handState.IsTracked && enableTracking) { ResetInput(handState, isSimulating); } if (isSimulating) { handState.SimulateInput(mouseDelta, useMouseRotation, profile.MouseRotationSensitivity, profile.MouseControllerRotationSpeed, profile.ControllerJitterAmount); if (isAlwaysVisible) { // Toggle gestures on/off handState.Gesture = ToggleGesture(handState.Gesture); } else { // Enable gesture while mouse button is pressed handState.Gesture = SelectGesture(); } } // Update tracked state of a hand. // If hideTimeout value is null, hands 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) { handState.IsTracked = true; lastHandTrackedTimestamp = currentTime.Ticks; } else { float timeSinceTracking = (float)currentTime.Subtract(new DateTime(lastHandTrackedTimestamp)).TotalSeconds; if (timeSinceTracking > profile.ControllerHideTimeout) { handState.IsTracked = false; } } }
internal virtual void ResetInput(SimulatedControllerState state, bool isSimulating) { if (isSimulating) { // Start at current mouse position Vector3 mousePos = UnityEngine.Input.mousePosition; state.ResetPosition(CameraCache.Main.ScreenToViewportPoint(new Vector3(mousePos.x, mousePos.y, profile.DefaultControllerDistance))); } else { state.ResetPosition(new Vector3(0.5f, 0.5f, profile.DefaultControllerDistance)); } }
/// <inheritdoc /> internal override void SimulateInput(ref long lastMotionControllerTrackedTimestamp, SimulatedControllerState state, bool isSimulating, bool isAlwaysVisible, MouseDelta mouseDelta, bool useMouseRotation) { if (!(state is SimulatedMotionControllerState motionControllerState)) { 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; } } }