This commit is contained in:
CortexCore
2023-11-15 23:54:54 +08:00
parent ee3ecec6cb
commit 3c837a4a33
356 changed files with 73756 additions and 26493 deletions

View File

@@ -17,7 +17,8 @@
"GUID:a3de65b07192e7d49bad7b4032d681de",
"GUID:d8b63aba1907145bea998dd612889d6b",
"GUID:f6155d9ae143f3949ac54e8355593d6c",
"GUID:21d1eb854b91ade49bc69a263d12bee2"
"GUID:21d1eb854b91ade49bc69a263d12bee2",
"GUID:96f476e982d6fb945bfc9140ba094b7f"
],
"includePlatforms": [],
"excludePlatforms": [],

View File

@@ -2,6 +2,7 @@ using System;
using System.Security.Permissions;
using System.Timers;
using BITFALL.Entities.Player.Movement.States;
using BITFALL.Player.Equip;
using BITFALL.Player.Movement;
using BITKit;
using BITKit.Entities;
@@ -22,18 +23,29 @@ namespace BITFALL.Entities.Player.Movement
[CustomType(typeof(IPlayerMovement))]
public class PlayerCharacterController : StateBasedPlayerBehavior<IEntityMovementState>,IEntityMovement,IPlayerMovement
{
[SerializeField] private CharacterActor actor;
[Header(Constant.Header.Settings)]
[SerializeField] private Vector3 initialCameraPosition = new(0,0.11f,0.27f);
[SerializeField] private float initialSpeed;
[SerializeReference,SubclassSelector] private IClosePoint climbClosePoint;
[SerializeReference, SubclassSelector]
private IProvider adsProvider;
[Header(Constant.Header.Components)]
[SerializeField] private CharacterActor actor;
[SerializeField] private LocationAdditive locationAdditive;
[Header(Constant.Header.Gameobjects)]
[SerializeField] private Transform fpvPoint;
[SerializeField] private Transform parachuteModel;
[Header(Constant.Header.Input)]
[SerializeField] private InputActionReference movementAction;
[SerializeField] private InputActionReference viewAction;
[SerializeField] private InputActionReference jumpAction;
[SerializeField] private InputActionReference crouchAction;
[SerializeField] private InputActionReference runAction;
[Header(Constant.Header.Providers)]
[SerializeReference,SubclassSelector] private IClosePoint climbClosePoint;
[SerializeReference, SubclassSelector] private IProvider adsProvider;
public Vector3 Position
{
@@ -67,30 +79,35 @@ namespace BITFALL.Entities.Player.Movement
public ExpectState<Vector3> CurrentCameraPosition;
public OffMeshLink OffMeshLink { get; private set; }
[Header(Constant.Header.Gameobjects)]
[SerializeField] private Transform parachuteModel;
private readonly ValidHandle allowMovement = new();
private readonly ValidHandle allowRun = new();
[Inject]
private IEntityPhysics physics;
[Inject]
private IHealth _health;
internal readonly ValidHandle allowMovement = new();
internal readonly ValidHandle allowRun = new();
internal readonly ValidHandle pauseRun = new();
private bool isDead;
private Vector3 keepVelocity;
private readonly DoubleBuffer<Vector3> gravityDamage = new();
private readonly DoubleBuffer<float> gravityDamping = new();
private Vector3 cacheGravity;
[Inject]
private IEntityPhysics _physics;
[Inject]
private IHealth _health;
[Inject]
private InputActionGroup _inputActionGroup;
public override void OnAwake()
{
base.OnAwake();
_health.OnSetAlive += OnSetAlive;
physics.OnSetPhysics += OnSetPhysics;
_physics.OnSetPhysics += OnSetPhysics;
LookInput = MathV.TransientRotationAxis(transform.rotation.eulerAngles);
parachuteModel.gameObject.SetActive(false);
}
public override void OnStart()
@@ -101,11 +118,19 @@ namespace BITFALL.Entities.Player.Movement
actor.PhysicsComponent.IgnoreCollision(x.transform,true);
}
TransitionState<Walk>();
_inputActionGroup.RegisterCallback(movementAction, Movement);
_inputActionGroup.RegisterCallback(viewAction, View);
_inputActionGroup.RegisterCallback(jumpAction, Jump);
_inputActionGroup.RegisterCallback(crouchAction, Crouch);
_inputActionGroup.RegisterCallback(runAction, Run);
}
private void OnSetPhysics(bool obj)
{
if (obj is false) return;
physics.Velocity = keepVelocity;
//_physics.Velocity = keepVelocity;
_physics.Velocity = default;
actor.Velocity = Vector3.zero;
}
@@ -116,7 +141,7 @@ namespace BITFALL.Entities.Player.Movement
if (obj)
{
if (!isDead) return;
actor.Position = physics.Center;
actor.Position = _physics.Center;
isDead = false;
}
else
@@ -159,12 +184,19 @@ namespace BITFALL.Entities.Player.Movement
case PlayerDisableRunCommand disableRunCommand:
allowRun.AddDisableElements(disableRunCommand.Lock);
break;
case PlayerCancelRunCommand:
ExpectRun.Reset();
ExpectSprint.Reset();
break;
case PlayerChangeVelocityCommand changeVelocityCommand:
actor.Velocity = Vector3.Lerp(actor.Velocity, changeVelocityCommand.Velocity, 5 * Time.deltaTime);
break;
case PlayerAddGravityDampingCommand addGravityDampingCommand:
gravityDamping.Release(addGravityDampingCommand.Damping);
break;
case PlayerPauseRunCommand pauseRunCommand:
pauseRun.SetElements(this,pauseRunCommand.Pause);
break;
}
OnCommand?.Invoke(command);
}
@@ -333,8 +365,8 @@ namespace BITFALL.Entities.Player.Movement
{
actor.Velocity = currentVelocity;
actor.Rotation = currentRotation;
if (currentVelocity.sqrMagnitude > 0.01f)
keepVelocity = currentVelocity;
//if (currentVelocity.sqrMagnitude > 0.01f)
keepVelocity = currentVelocity;
}
var localVelocity = transform.InverseTransformDirection(Velocity);

View File

@@ -1,5 +1,6 @@
using System;
using BITFALL.Entities.Player.Movement.States;
using BITFALL.Player.Equip;
using BITFALL.Player.Movement;
using BITKit;
using BITKit.StateMachine;
@@ -109,13 +110,6 @@ namespace BITFALL.Entities.Player.Movement.States
[Serializable]
public sealed class Walk:BasicMovement,IPlayerWalkState
{
public override void OnStateEntry(IState old)
{
base.OnStateEntry(old);
characterController.ExpectRun.Reset();
characterController.ExpectSprint.Reset();
}
public override void AfterUpdateMovement(float deltaTime)
{
base.AfterUpdateMovement(deltaTime);
@@ -123,10 +117,10 @@ namespace BITFALL.Entities.Player.Movement.States
{
case (_,true):
characterController.TransitionState<Crouch>();
break;
case (true,false):
return;
case (true,false) when characterController.pauseRun.Allow is false:
characterController.TransitionState<Run>();
break;
return;
}
}
}
@@ -136,14 +130,21 @@ namespace BITFALL.Entities.Player.Movement.States
{
[SerializeField] private float moveDamping = 3f;
[SerializeField] private float damping = 1f;
[Inject] private IEquipService _equipService;
public override void OnStateEntry(IState old)
{
base.OnStateEntry(old);
characterController.InvokeOpenParachute();
_equipService.AllowEquip.AddDisableElements(this);
}
public override void OnStateExit(IState old, IState newState)
{
base.OnStateExit(old, newState);
characterController.InvokeCloseParachute();
_equipService.AllowEquip.RemoveDisableElements(this);
}
public override void UpdateRotation(ref Quaternion currentRotation, float deltaTime)
@@ -191,18 +192,25 @@ namespace BITFALL.Entities.Player.Movement.States
public override void AfterUpdateMovement(float deltaTime)
{
base.AfterUpdateMovement(deltaTime);
if (characterController.ExpectSprint.shouldBe)
{
characterController.TransitionState<Sprint>();
}
switch (characterController.ExpectRun.shouldBe,characterController.ExpectCrouch.shouldBe)
{
case (_,true):
characterController.TransitionState<Crouch>();
break;
return;
case (false,false):
characterController.TransitionState<Walk>();
break;
return;
}
if (characterController.pauseRun.Allow)
{
characterController.TransitionState<Walk>();
return;
}
if (characterController.ExpectSprint.shouldBe)
{
characterController.TransitionState<Sprint>();
return;
}
}
@@ -229,6 +237,7 @@ namespace BITFALL.Entities.Player.Movement.States
{
characterController.ExpectCrouch.being = true;
characterController.ExpectCrouch.shouldBe = true;
characterController.ExecuteCommand<PlayerCancelRunCommand>();
_addedVelocity = false;
}
@@ -319,22 +328,27 @@ namespace BITFALL.Entities.Player.Movement.States
public override void AfterUpdateMovement(float deltaTime)
{
base.AfterUpdateMovement(deltaTime);
if (characterController.pauseRun.Allow)
{
characterController.TransitionState<Walk>();
return;
}
switch (characterController.ExpectRun.shouldBe,characterController.ExpectCrouch.shouldBe)
{
case (_,_) when characterController.Stamina is 0:
characterController.ExpectSprint.Reset();
characterController.TransitionState<Run>();
break;
return;
case (_,true) when characterController.IsGrounded && characterController.Stamina >= slideCost:
characterController.Stamina -= slideCost;
characterController.TransitionState<Slide>();
break;
return;
case (_,true):
characterController.TransitionState<Crouch>();
break;
return;
case (false,false):
characterController.TransitionState<Walk>();
break;
return;
}
}
public override void ExecuteCommand<T>(T command)

View File

@@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using BITFALL.Player.Equip;
using BITFALL.Player.Movement;
using BITKit;
using BITKit.Entities;
@@ -22,6 +23,8 @@ namespace BITFALL.Entities.Player.Movement.States
{
[SerializeField] protected float lerpDelta = 5;
private IntervalUpdate cancelInterval = new(0.16f);
public override void OnStateEntry(IState old)
{
base.OnStateEntry(old);
@@ -49,6 +52,8 @@ namespace BITFALL.Entities.Player.Movement.States
actor.ColliderComponent.enabled = true;
characterController.ExpectJump.Reset();
actor.ForceGrounded();
}
public override void UpdateVelocity(ref Vector3 currentVelocity, float deltaTime)
@@ -69,6 +74,8 @@ namespace BITFALL.Entities.Player.Movement.States
private ISplineContainer _splineContainer;
private float progress;
private float increment;
[Inject] private IEquipService _equipService;
public override void OnStateEntry(IState old)
{
@@ -86,6 +93,8 @@ namespace BITFALL.Entities.Player.Movement.States
Init(characterController.OffMeshLink);
characterController.LimitViewAngle = 45;
_equipService.AllowEquip.AddDisableElements(this);
}
public override void OnStateExit(IState old, IState newState)
@@ -95,6 +104,8 @@ namespace BITFALL.Entities.Player.Movement.States
actor.ColliderComponent.enabled = true;
characterController.LimitViewAngle = 0;
_equipService.AllowEquip.RemoveDisableElements(this);
}
private void Init(OffMeshLink offMeshLink)
@@ -272,6 +283,8 @@ namespace BITFALL.Entities.Player.Movement.States
private IPlayerFixedPlace _fixedPlace;
[Inject] private ISelector _selector;
[Inject] private IEquipService _equipService;
public override void Initialize()
{
base.Initialize();
@@ -288,6 +301,8 @@ namespace BITFALL.Entities.Player.Movement.States
actor.alwaysNotGrounded = true;
characterController.ExpectCrouch.Reset();
characterController.LimitViewAngle = 100;
_equipService.AllowEquip.AddDisableElements(this);
}
public override void OnStateExit(IState old, IState newState)
@@ -299,6 +314,8 @@ namespace BITFALL.Entities.Player.Movement.States
actor.PhysicsComponent.enabled = true;
//actor.enabled = true;
characterController.LimitViewAngle = 0;
_equipService.AllowEquip.RemoveDisableElements(this);
}
public override void UpdateVelocity(ref Vector3 currentVelocity, float deltaTime)
{

View File

@@ -18,9 +18,9 @@ namespace BITFALL.Player.Animation
[SerializeField] internal UnityAnimator animator;
private IEntityMovement _movement;
private static readonly int Vertical = Animator.StringToHash("Vertical");
private static readonly int Horizontal = Animator.StringToHash("Horizontal");
private static readonly int SqrMagnitude = Animator.StringToHash("SqrMagnitude");
private static readonly int Vertical = Animator.StringToHash(BITConstant.Player.Vertical);
private static readonly int Horizontal = Animator.StringToHash(BITConstant.Player.Horizontal);
private static readonly int SqrMagnitude = Animator.StringToHash(BITConstant.Player.SqrMagnitude);
public override void OnAwake()
{
@@ -28,14 +28,12 @@ namespace BITFALL.Player.Animation
_movement = UnityEntity.Get<IEntityMovement>();
_movement.OnStateChanged += OnMovementStateChanged;
}
public override void OnFixedUpdate(float deltaTime)
{
animator.animator.SetFloat(Vertical, _movement.LocomotionBasedVelocity.z);
animator.animator.SetFloat(Horizontal, _movement.LocomotionBasedVelocity.x);
animator.animator.SetFloat(SqrMagnitude, _movement.LocomotionBasedVelocity.sqrMagnitude);
}
private void OnMovementStateChanged(IEntityMovementState arg1, IEntityMovementState arg2)
{
foreach (var x in StateDictionary.Values)