refactor
This commit is contained in:
@@ -5,21 +5,42 @@ using RebootKit.Engine;
|
||||
using RebootKit.Engine.Foundation;
|
||||
using RebootKit.Engine.Services.Console;
|
||||
using RebootKit.Engine.Services.Input;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.InputSystem;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace RebootKit.FPPKit {
|
||||
|
||||
public static class FPPConfig {
|
||||
[ConfigVar("fpp.mouse.sens", 0.25f, "Mouse look sensitivity")] public static ConfigVar s_MouseSensitivity;
|
||||
[ConfigVar("fpp.mouse.invert.y", 0, "Invert mouse look")] public static ConfigVar s_MouseInvertY;
|
||||
[ConfigVar("fpp.gamepad.sens", 4.0f, "Gamepad look sensitivity")] public static ConfigVar s_GamepadSensitivity;
|
||||
}
|
||||
|
||||
public static class SensitivityReader {
|
||||
public static float2 Read(InputAction action) {
|
||||
float2 sensitivity = action.ReadValue<Vector2>();
|
||||
|
||||
// @TODO: differentiate between gamepad and mouse
|
||||
|
||||
sensitivity *= FPPConfig.s_MouseSensitivity.FloatValue;
|
||||
|
||||
if (FPPConfig.s_MouseInvertY.IndexValue == 1) {
|
||||
sensitivity.y *= -1;
|
||||
}
|
||||
|
||||
return sensitivity;
|
||||
}
|
||||
}
|
||||
|
||||
public class FPPPlayerController : IController {
|
||||
readonly Config m_Config;
|
||||
FPPActor m_FPPActor;
|
||||
|
||||
[Inject] InputService m_InputService;
|
||||
|
||||
[CVar("p_move_speed", 4.0f)] CVar m_MovementSpeedCVar;
|
||||
[CVar("fpp_cam_look_sens", 0.25f)] CVar m_SensitivityCVar;
|
||||
|
||||
public FPPPlayerController(Config config) {
|
||||
m_Config = config;
|
||||
}
|
||||
@@ -31,9 +52,6 @@ namespace RebootKit.FPPKit {
|
||||
m_InputService.LockCursor();
|
||||
m_InputService.EnableControls();
|
||||
|
||||
m_SensitivityCVar = RR.CVarNumber("fpp_cam_look_sens", 0.25f);
|
||||
m_MovementSpeedCVar = RR.CVarNumber("p_move_speed", 4.0f);
|
||||
|
||||
m_FPPActor = await RR.World.SpawnActor<FPPActor>(m_Config.fppActorPrefab, cancellationToken);
|
||||
|
||||
await Awaitable.NextFrameAsync(cancellationToken);
|
||||
@@ -48,11 +66,18 @@ namespace RebootKit.FPPKit {
|
||||
}
|
||||
|
||||
public void OnTick() {
|
||||
// m_FPPActor.FPPCamera.Sensitivity = m_SensitivityCVar.FloatValue;
|
||||
if (m_FPPActor == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Application.isFocused) {
|
||||
return;
|
||||
}
|
||||
|
||||
// m_FPPActor.Locomotion.maxMovementSpeed = m_MovementSpeedCVar.FloatValue;
|
||||
|
||||
Vector2 lookInput = m_Config.lookActionReference.action.ReadValue<Vector2>();
|
||||
m_FPPActor.Look(lookInput);
|
||||
m_FPPActor.Look(lookInput * FPPConfig.s_MouseSensitivity.FloatValue);
|
||||
|
||||
Vector2 moveInput = m_Config.moveActionReference.action.ReadValue<Vector2>();
|
||||
m_FPPActor.MoveRight(moveInput.x);
|
||||
|
||||
Reference in New Issue
Block a user