This commit is contained in:
CortexCore
2023-09-01 14:33:54 +08:00
parent 4fadd3a530
commit 8ef5c7ec0a
451 changed files with 1048940 additions and 2028 deletions

View File

@@ -1,10 +1,12 @@
using System;
using BITFALL.Entities.Player.Movement.States;
using BITFALL.Player.Movement;
using BITKit;
using BITKit.Entities;
using BITKit.Entities.Physics;
using BITKit.Entities.Player;
using Lightbug.CharacterControllerPro.Core;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Interactions;
@@ -12,11 +14,13 @@ using UnityEngine.UIElements;
namespace BITFALL.Entities.Player.Movement
{
public class PlayerCharacterController : StateBasedPlayerComponent<IEntityMovementState>,IEntityMovement,IServiceRegister
[CustomType(typeof(IEntityMovement))]
[CustomType(typeof(IPlayerMovement))]
public class PlayerCharacterController : StateBasedPlayerComponent<IEntityMovementState>,IEntityMovement,IServiceRegister,IPlayerMovement
{
public override Type BaseType => typeof(IEntityMovement);
[SerializeField] private CharacterActor actor;
[SerializeField] private Vector3 initialCameraPosition = new Vector3(0,0.11f,0.27f);
[SerializeField] private Vector3 initialCameraPosition = new(0,0.11f,0.27f);
[SerializeField] private float initialSpeed;
[SerializeReference,SubclassSelector] private IClosePoint climbClosePoint;
@@ -25,9 +29,12 @@ namespace BITFALL.Entities.Player.Movement
private IProvider adsProvider;
[SerializeField] private Transform cameraTransform;
public Vector3 ViewCenter { get; set; }
public Quaternion ViewRotation { get; set; }
public Vector3 LocomotionBasedVelocity { get;private set; }
public Vector3 Velocity => actor.Velocity;
public Vector3 GroundVelocity=>actor.GroundVelocity;
public Vector3 AngularVelocity { get;private set; }
public bool IsGrounded => actor.IsGrounded;
public Vector3 MovementInput { get; private set; }
@@ -38,8 +45,8 @@ namespace BITFALL.Entities.Player.Movement
public ExpectState<bool> ExpectSprint;
public ExpectState<Vector3> expectClimb;
public Vector3 CurrentCameraPosition;
private readonly ValidHandle allowMovement = new();
private readonly ValidHandle allowRun = new();
private IEntityPhysics physics;
private IHealth _health;
private bool isDead;
@@ -63,6 +70,7 @@ namespace BITFALL.Entities.Player.Movement
private void OnSetAlive(bool obj)
{
allowMovement.SetElements(this,obj);
allowRun.SetElements(this,obj);
if (obj)
{
if (!isDead) return;
@@ -91,13 +99,26 @@ namespace BITFALL.Entities.Player.Movement
ExpectSprint.Reset();
}
public void ExecuteCommand<T>(T command)
public void ExecuteCommand<T>(T command=default)
{
foreach (var x in StateDictionary.Values)
{
x.ExecuteCommand<T>(command);
}
switch (command)
{
case PlayerEnableRunCommand enableRunCommand:
allowRun.RemoveDisableElements(enableRunCommand.Lock);
ExpectRun.Reset();
ExpectSprint.Reset();
break;
case PlayerDisableRunCommand disableRunCommand:
allowRun.AddDisableElements(disableRunCommand.Lock);
break;
}
OnCommand?.Invoke(command);
}
public event Action<object> OnCommand;
public void View(InputAction.CallbackContext context)
{
@@ -111,6 +132,12 @@ namespace BITFALL.Entities.Player.Movement
lookInput.y += raw.x;
lookInput.x = Mathf.Clamp(lookInput.x, -80, 80);
LookInput = lookInput;
AngularVelocity = new Vector3
(
raw.y,
-raw.x
);
}
public void Jump(InputAction.CallbackContext context)
{
@@ -127,6 +154,7 @@ namespace BITFALL.Entities.Player.Movement
}
public void Run(InputAction.CallbackContext context)
{
if (allowRun.Allow is false) return;
switch (context)
{
case { interaction: PressInteraction, started: true }:
@@ -191,6 +219,18 @@ namespace BITFALL.Entities.Player.Movement
cameraTransform.rotation = rotation;
CurrentState?.AfterUpdateMovement(deltaTime);
cameraTransform.localPosition = Vector3.Lerp(cameraTransform.localPosition,CurrentCameraPosition,5 * deltaTime);
ViewCenter = cameraTransform.position;
ViewRotation = rotation;
}
public void AddViewEuler(float2 euler)
{
LookInput = new Vector3
{
x = LookInput.x + euler.x,
y = LookInput.y + euler.y
};
}
}