idk
This commit is contained in:
87
Assets/jelycho/Code/Player/PlayerController.cs
Normal file
87
Assets/jelycho/Code/Player/PlayerController.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using RebootKit.Engine;
|
||||
using RebootKit.Engine.Foundation;
|
||||
using RebootKit.Engine.Services.Input;
|
||||
using RebootKit.FPPKit;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.Serialization;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace RealityReboot.jelycho.Player {
|
||||
public class PlayerController : IController {
|
||||
readonly Config m_Config;
|
||||
PlayerActor m_FPPActor;
|
||||
|
||||
[Inject] InputService m_InputService;
|
||||
|
||||
public PlayerController(Config config) {
|
||||
m_Config = config;
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
}
|
||||
|
||||
public async UniTask OnStart(CancellationToken cancellationToken) {
|
||||
m_InputService.LockCursor();
|
||||
m_InputService.EnableControls();
|
||||
|
||||
m_FPPActor = await RR.World.SpawnActor<PlayerActor>(m_Config.playerActorPrefab, cancellationToken);
|
||||
m_FPPActor.Simulate = true;
|
||||
|
||||
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() {
|
||||
if (m_FPPActor == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Application.isFocused) {
|
||||
return;
|
||||
}
|
||||
|
||||
Vector2 lookInput = SensitivityReader.Read(m_Config.lookActionReference.action);
|
||||
m_FPPActor.Look(lookInput * FPPConfig.s_MouseSensitivity.FloatValue);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
if (m_Config.dragObjectActionReference.action.WasPressedThisFrame()) {
|
||||
m_FPPActor.StartDrag();
|
||||
}
|
||||
|
||||
if (m_Config.dragObjectActionReference.action.WasReleasedThisFrame()) {
|
||||
m_FPPActor.StopDrag();
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class Config {
|
||||
[FormerlySerializedAs("fppActorPrefab")] public AssetReferenceT<GameObject> playerActorPrefab;
|
||||
|
||||
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