broken
This commit is contained in:
91
Runtime/FPPKit/Code/FPPPlayerController.cs
Normal file
91
Runtime/FPPKit/Code/FPPPlayerController.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using RebootKit.Engine;
|
||||
using RebootKit.Engine.Foundation;
|
||||
using RebootKit.Engine.Services.Console;
|
||||
using RebootKit.Engine.Services.Input;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.InputSystem;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace RebootKit.FPPKit {
|
||||
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;
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
}
|
||||
|
||||
public async UniTask OnStart(CancellationToken cancellationToken) {
|
||||
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);
|
||||
}
|
||||
|
||||
public void OnStop() {
|
||||
m_InputService.DisableControls();
|
||||
m_InputService.UnlockCursor();
|
||||
Object.Destroy(m_FPPActor);
|
||||
|
||||
RR.World.KillActor(m_FPPActor);
|
||||
}
|
||||
|
||||
public void OnTick() {
|
||||
// m_FPPActor.FPPCamera.Sensitivity = m_SensitivityCVar.FloatValue;
|
||||
// m_FPPActor.Locomotion.maxMovementSpeed = m_MovementSpeedCVar.FloatValue;
|
||||
|
||||
Vector2 lookInput = m_Config.lookActionReference.action.ReadValue<Vector2>();
|
||||
m_FPPActor.Look(lookInput);
|
||||
|
||||
Vector2 moveInput = m_Config.moveActionReference.action.ReadValue<Vector2>();
|
||||
m_FPPActor.MoveRight(moveInput.x);
|
||||
m_FPPActor.MoveForward(moveInput.y);
|
||||
|
||||
if (m_Config.jumpActionReference.action.WasPerformedThisFrame()) {
|
||||
m_FPPActor.Jump();
|
||||
}
|
||||
|
||||
// m_FPPActor.Dragger.TargetWorldPosition = m_FPPActor.FPPCamera.Camera.transform.position + m_FPPActor.FPPCamera.Camera.transform.forward * m_FPPActor.DragObjectDistanceFromCamera;
|
||||
//
|
||||
// if (m_Config.dragObjectActionReference.action.WasPressedThisFrame() && !m_FPPActor.Dragger.IsDragging) {
|
||||
// GameObject pickedGameObject = m_FPPActor.FPPCamera.Sensor.Sense();
|
||||
// if (pickedGameObject != null && pickedGameObject.TryGetComponent(out Rigidbody rigidbody)) {
|
||||
// m_FPPActor.Dragger.Grab(rigidbody);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (m_Config.dragObjectActionReference.action.WasReleasedThisFrame()) {
|
||||
// m_FPPActor.Dragger.Drop();
|
||||
// }
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class Config {
|
||||
public AssetReferenceT<GameObject> fppActorPrefab;
|
||||
|
||||
public InputActionReference moveActionReference;
|
||||
public InputActionReference lookActionReference;
|
||||
public InputActionReference jumpActionReference;
|
||||
public InputActionReference dragObjectActionReference;
|
||||
public InputActionReference primaryActionReference;
|
||||
public InputActionReference secondaryActionReference;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user