This commit is contained in:
CortexCore
2024-04-19 21:43:30 +08:00
parent e12a6e5a46
commit 3cc6491973
46 changed files with 6792 additions and 23887 deletions

View File

@@ -33,29 +33,29 @@ namespace BITFALL.Entities.Player.Movement.States
{
base.OnStateEntry(old);
actor.SetSize(initialSize,CharacterActor.SizeReferenceType.Bottom);
characterController.ReferenceSpeed = initialSpeed;
self.ReferenceSpeed = initialSpeed;
}
public override void BeforeUpdateMovement(float deltaTime)
{
characterController.CurrentCameraPosition.shouldBe = initialCameraPosition;
self.CurrentCameraPosition.shouldBe = initialCameraPosition;
}
public override void AfterUpdateMovement(float deltaTime)
{
if (knockdown.IsKnockdown)
{
characterController.TransitionState<Knockdown>();
self.TransitionState<Knockdown>();
}
if (knockdown.IsKnockdown is false && characterController.ExpectParachute.shouldBe)
if (knockdown.IsKnockdown is false && self.ExpectParachute.shouldBe)
{
characterController.TransitionState<Parachute>();
characterController.ExpectParachute.Reset();
self.TransitionState<Parachute>();
self.ExpectParachute.Reset();
}
if (characterController.RequestClimb is false) return;
if(characterController.topBlocked)return;
if (self.RequestClimb is false) return;
if(self.topBlocked)return;
// if (characterController.topBlocked is false && characterController.RequestClimb &&
// characterController.climbClosePoint.TryGetClosePoint(out var closePoint))
@@ -65,37 +65,37 @@ namespace BITFALL.Entities.Player.Movement.States
// return;
// }
if (characterController.vaultPoint.TryGetClosePoint(out var closePoint))
if (self.vaultPoint.TryGetClosePoint(out var closePoint))
{
characterController.ExpectClimb.shouldBe = closePoint;
characterController.TransitionState<Vault>();
characterController.ExpectJump.Reset();
characterController.RequestClimb = false;
self.ExpectClimb.shouldBe = closePoint;
self.TransitionState<Vault>();
self.ExpectJump.Reset();
self.RequestClimb = false;
return;
}
if (characterController.climbClosePoint.TryGetClosePoint(out closePoint))
if (self.climbClosePoint.TryGetClosePoint(out closePoint))
{
characterController.ExpectClimb.shouldBe = closePoint;
characterController.TransitionState<Climb>();
characterController.ExpectJump.Reset();
characterController.RequestClimb = false;
self.ExpectClimb.shouldBe = closePoint;
self.TransitionState<Climb>();
self.ExpectJump.Reset();
self.RequestClimb = false;
return;
}
if (characterController.edgeClimbPoint.TryGetClosePoint(out closePoint))
if (self.edgeClimbPoint.TryGetClosePoint(out closePoint))
{
characterController.ExpectClimb.shouldBe = closePoint;
characterController.TransitionState<EdgeClimb>();characterController.ExpectJump.Reset();
characterController.RequestClimb = false;
self.ExpectClimb.shouldBe = closePoint;
self.TransitionState<EdgeClimb>();self.ExpectJump.Reset();
self.RequestClimb = false;
return;
}
}
public override void UpdateVelocity(ref Vector3 currentVelocity, float deltaTime)
{
var rotation = Quaternion.Euler(0, characterController.LookInput.y, 0);
var movementInput = characterController.MovementInput;
var rotation = Quaternion.Euler(0, self.LookInput.y, 0);
var movementInput = self.MovementInput;
if (_cameraService?.IsCameraActivated is false)
{
@@ -103,7 +103,7 @@ namespace BITFALL.Entities.Player.Movement.States
}
var moveVelocity = rotation * new Vector3(
movementInput.x * Mathf.Min(characterController.initialSpeed, initialSpeed),
movementInput.x * Mathf.Min(self.initialSpeed, initialSpeed),
0,
movementInput.z * initialSpeed
);
@@ -112,18 +112,18 @@ namespace BITFALL.Entities.Player.Movement.States
moveVelocity = rotation * movementInput * initialSpeed;
}
if (characterController.limitSpeed.Allow)
if (self.limitSpeed.Allow)
{
switch (characterController.CurrentState)
switch (self.CurrentState)
{
case IPlayerWalkState:
case IPlayerCrouchState:
moveVelocity = Vector3.ClampMagnitude(moveVelocity, characterController.limitSpeed.Value);
moveVelocity = Vector3.ClampMagnitude(moveVelocity, self.limitSpeed.Value);
break;
}
}
if (characterController.IsGrounded)
if (self.IsGrounded)
{
var effectiveGroundNormal = actor.GroundStableNormal;
@@ -139,7 +139,7 @@ namespace BITFALL.Entities.Player.Movement.States
Vector3.Lerp(currentVelocity, targetMovementVelocity, 1f - Mathf.Exp(-16 * deltaTime));
currentVelocity = newVelocity;
if (characterController.ExpectJump.shouldBe)
if (self.ExpectJump.shouldBe)
{
actor.ForceNotGrounded();
@@ -151,14 +151,14 @@ namespace BITFALL.Entities.Player.Movement.States
currentVelocity.y+= initialJumpForce;
characterController.ExpectJump.Reset();
self.ExpectJump.Reset();
characterController.ExecuteCommand<OnPlayerJumpCommand>();
self.ExecuteCommand<OnPlayerJumpCommand>();
}
}
else
{
if (moveVelocity.sqrMagnitude > 0f && characterController.landFreeze.AllowUpdateWithoutReset)
if (moveVelocity.sqrMagnitude > 0f && self.landFreeze.AllowUpdateWithoutReset)
{
var addedVelocity = moveVelocity * (3 * deltaTime);
@@ -212,7 +212,7 @@ namespace BITFALL.Entities.Player.Movement.States
public override void UpdateRotation(ref Quaternion currentRotation, float deltaTime)
{
var newRotation = Quaternion.Euler(0, characterController.LookInput.y, 0);
var newRotation = Quaternion.Euler(0, self.LookInput.y, 0);
@@ -221,36 +221,36 @@ namespace BITFALL.Entities.Player.Movement.States
if (Physics.Raycast(_cameraService.CameraPosition, _cameraService.CameraRotation * Vector3.forward,
out var hit, 256, LayerMask.GetMask("Default"), QueryTriggerInteraction.Ignore))
{
characterController.ViewForward = (hit.point - (characterController.Position +
characterController.Rotation *
characterController.ViewCenter)).normalized;
self.ViewForward = (hit.point - (self.Position +
self.Rotation *
self.ViewCenter)).normalized;
newRotation = Quaternion.LookRotation(characterController.ViewForward);
characterController.ViewRotation = newRotation;
newRotation = Quaternion.LookRotation(self.ViewForward);
self.ViewRotation = newRotation;
characterController.FocusPoint = hit.point;
self.FocusPoint = hit.point;
Debug.DrawLine(_cameraService.CameraPosition, hit.point, Color.green, 0.1f);
Debug.DrawLine(characterController.Position + characterController.ViewCenter,
characterController.Position +
characterController.ViewCenter + characterController.ViewRotation * Vector3.forward
Debug.DrawLine(self.Position + self.ViewCenter,
self.Position +
self.ViewCenter + self.ViewRotation * Vector3.forward
, Color.blue, 0.1f);
}
else
{
characterController.ViewRotation = Quaternion.Euler(characterController.LookInput);;
self.ViewRotation = Quaternion.Euler(self.LookInput);;
characterController.FocusPoint = characterController.Position +
characterController.ViewRotation * Vector3.forward * 256;
self.FocusPoint = self.Position +
self.ViewRotation * Vector3.forward * 256;
Debug.DrawLine(_cameraService.CameraPosition, _cameraService.CameraRotation * Vector3.forward,
Color.red, 0.1f);
}
var rotationDirection = _cameraService.CameraRotation * characterController.MovementInput;
var rotationDirection = _cameraService.CameraRotation * self.MovementInput;
rotationDirection = Vector3.ProjectOnPlane(rotationDirection, Vector3.up);
if (rotationDirection.sqrMagnitude >= 0.16f)
{
@@ -258,7 +258,7 @@ namespace BITFALL.Entities.Player.Movement.States
currentRotation = Quaternion.Lerp(currentRotation, newPlayerRotation, 1f - Mathf.Exp(-16 * deltaTime));
}
if (characterController.allowFocus)
if (self.allowFocus)
{
currentRotation =
Quaternion.LookRotation(_cameraService.CameraRotation * Vector3.forward, Vector3.up);
@@ -279,16 +279,16 @@ namespace BITFALL.Entities.Player.Movement.States
public override void AfterUpdateMovement(float deltaTime)
{
base.AfterUpdateMovement(deltaTime);
if (characterController.CurrentState != this) return;
switch (characterController.ExpectRun.shouldBe, characterController.ExpectCrouch.shouldBe)
if (self.CurrentState != this) return;
switch (self.ExpectRun.shouldBe, self.ExpectCrouch.shouldBe)
{
case (_,_) when characterController.topBlocked && characterController.IsGrounded:
case (_,_) when self.topBlocked && self.IsGrounded:
case (_, true):
characterController.TransitionState<Crouch>();
self.TransitionState<Crouch>();
return;
case (true, false) when characterController.pauseRun.Allow is false &&
characterController.MovementInput.z > 0:
characterController.TransitionState<Run>();
case (true, false) when self.pauseRun.Allow is false &&
self.MovementInput.z > 0:
self.TransitionState<Run>();
return;
}
}
@@ -300,17 +300,17 @@ namespace BITFALL.Entities.Player.Movement.States
public override void OnStateEntry(IState old)
{
_equipService.AllowEquip.AddDisableElements(this);
characterController.LimitViewAngle = 20;
self.LimitViewAngle = 20;
base.OnStateEntry(old);
}
public override void AfterUpdateMovement(float deltaTime)
{
if (actor.IsGrounded is false)
{
characterController.TransitionState<Walk>();
self.TransitionState<Walk>();
return;
}
characterController.CurrentCameraPosition.shouldBe = characterController.FpvLocalPosition;
self.CurrentCameraPosition.shouldBe = self.FpvLocalPosition;
}
public override void UpdateRotation(ref Quaternion currentRotation, float deltaTime)
@@ -323,7 +323,7 @@ namespace BITFALL.Entities.Player.Movement.States
public override void OnStateExit(IState old, IState newState)
{
base.OnStateExit(old, newState);
characterController.LimitViewAngle = 0;
self.LimitViewAngle = 0;
_equipService.AllowEquip.RemoveDisableElements(this);
}
}
@@ -338,7 +338,7 @@ namespace BITFALL.Entities.Player.Movement.States
public override void OnStateEntry(IState old)
{
base.OnStateEntry(old);
characterController.InvokeOpenParachute();
self.InvokeOpenParachute();
_equipService.AllowEquip.AddDisableElements(this);
var velocity = actor.Velocity;
@@ -349,20 +349,20 @@ namespace BITFALL.Entities.Player.Movement.States
public override void OnStateExit(IState old, IState newState)
{
base.OnStateExit(old, newState);
characterController.InvokeCloseParachute();
self.InvokeCloseParachute();
_equipService.AllowEquip.RemoveDisableElements(this);
}
public override void UpdateRotation(ref Quaternion currentRotation, float deltaTime)
{
currentRotation = Quaternion.Euler(0,characterController.LookInput.y,0);
currentRotation = Quaternion.Euler(0,self.LookInput.y,0);
}
public override void UpdateVelocity(ref Vector3 currentVelocity, float deltaTime)
{
var rotation = Quaternion.Euler(0,characterController.LookInput.y,0);
var moveVelocity = rotation * characterController.MovementInput;
var rotation = Quaternion.Euler(0,self.LookInput.y,0);
var moveVelocity = rotation * self.MovementInput;
currentVelocity.y =
Mathf.MoveTowards(
currentVelocity.y,
@@ -377,10 +377,10 @@ namespace BITFALL.Entities.Player.Movement.States
{
if (actor.IsGrounded)
{
characterController.TransitionState<Walk>();
self.TransitionState<Walk>();
}
characterController.ExpectParachute.Reset();
characterController.CurrentCameraPosition.shouldBe = characterController.FpvLocalPosition;
self.ExpectParachute.Reset();
self.CurrentCameraPosition.shouldBe = self.FpvLocalPosition;
}
}
[Serializable]
@@ -388,12 +388,12 @@ namespace BITFALL.Entities.Player.Movement.States
{
public override void OnStateEntry(IState old)
{
characterController.ExpectRun.being = true;
self.ExpectRun.being = true;
}
public override void OnStateExit(IState old, IState newState)
{
characterController.ExpectRun.being = false;
self.ExpectRun.being = false;
}
public override void UpdateRotation(ref Quaternion currentRotation, float deltaTime)
@@ -407,7 +407,7 @@ namespace BITFALL.Entities.Player.Movement.States
var baseRotation = Quaternion.identity;
base.UpdateRotation(ref baseRotation, deltaTime);
var targetRotation = Quaternion.LookRotation(baseRotation * characterController.MovementInput);
var targetRotation = Quaternion.LookRotation(baseRotation * self.MovementInput);
float maxAngleDelta = 30; // 你可以根据需要调整最大角度差值
float maxDeltaMagnitude = Mathf.Sin(Mathf.Deg2Rad * maxAngleDelta / 2);
@@ -431,52 +431,52 @@ namespace BITFALL.Entities.Player.Movement.States
public override void OnStateUpdate(float deltaTime)
{
base.OnStateUpdate(deltaTime);
AudioSensorService.MakeNoise(actor.Position,characterController.transform,3,new MovementNoise());
AudioSensorService.MakeNoise(actor.Position,self.transform,3,new MovementNoise());
}
public override void AfterUpdateMovement(float deltaTime)
{
base.AfterUpdateMovement(deltaTime);
switch (characterController.CurrentState)
switch (self.CurrentState)
{
case Walk:
case Run:
case Sprint:
case Crouch:
switch (characterController.ExpectRun.shouldBe, characterController.ExpectCrouch.shouldBe)
switch (self.ExpectRun.shouldBe, self.ExpectCrouch.shouldBe)
{
case (_, true):
characterController.TransitionState<Crouch>();
self.TransitionState<Crouch>();
return;
case (false, false):
characterController.TransitionState<Walk>();
self.TransitionState<Walk>();
return;
}
if (_cameraService.IsCameraActivated)
{
if (characterController.MovementInput.z <= 0)
if (self.MovementInput.z <= 0)
{
characterController.TransitionState<Walk>();
self.TransitionState<Walk>();
return;
}
}
else
{
if (characterController.MovementInput == default)
if (self.MovementInput == default)
{
characterController.TransitionState<Walk>();
self.TransitionState<Walk>();
return;
}
}
if (characterController.pauseRun.Allow)
if (self.pauseRun.Allow)
{
characterController.TransitionState<Walk>();
self.TransitionState<Walk>();
return;
}
if (characterController.ExpectSprint.shouldBe && characterController.MovementInput.z > 0)
if (self.ExpectSprint.shouldBe && self.MovementInput.z > 0)
{
characterController.TransitionState<Sprint>();
self.TransitionState<Sprint>();
return;
}
break;
@@ -488,7 +488,7 @@ namespace BITFALL.Entities.Player.Movement.States
if (Enabled is false) return;
if (command is PlayerCancelRunCommand)
{
characterController.TransitionState<Walk>();
self.TransitionState<Walk>();
}
}
}
@@ -505,9 +505,9 @@ namespace BITFALL.Entities.Player.Movement.States
public override void OnStateEntry(IState old)
{
base.OnStateEntry(old);
characterController.ExpectCrouch.being = true;
characterController.ExpectCrouch.shouldBe = true;
characterController.ExecuteCommand<PlayerCancelRunCommand>();
self.ExpectCrouch.being = true;
self.ExpectCrouch.shouldBe = true;
self.ExecuteCommand<PlayerCancelRunCommand>();
_addedVelocity = false;
}
@@ -532,21 +532,21 @@ namespace BITFALL.Entities.Player.Movement.States
}
public override void AfterUpdateMovement(float deltaTime)
{
if (characterController.ExpectRun.shouldBe)
if (self.ExpectRun.shouldBe)
{
characterController.TransitionState<Run>();
self.TransitionState<Run>();
return;
}
if (characterController.ExpectCrouch.shouldBe is false || (alwaysSlide is false && actor.IsGrounded is false))
if (self.ExpectCrouch.shouldBe is false || (alwaysSlide is false && actor.IsGrounded is false))
{
characterController.TransitionState<Walk>();
self.TransitionState<Walk>();
return;
}
if (actor.Velocity.sqrMagnitude <= stopSpeed)
{
characterController.TransitionState<Crouch>();
self.TransitionState<Crouch>();
}
characterController.CurrentCameraPosition.shouldBe = characterController.FpvLocalPosition;
self.CurrentCameraPosition.shouldBe = self.FpvLocalPosition;
}
}
[Serializable]
@@ -556,35 +556,35 @@ namespace BITFALL.Entities.Player.Movement.States
public override void OnStateEntry(IState old)
{
base.OnStateEntry(old);
characterController.ExpectCrouch.being = true;
self.ExpectCrouch.being = true;
standInterval.Reset();
}
public override void OnStateExit(IState old, IState newState)
{
characterController.ExpectCrouch.being = false;
self.ExpectCrouch.being = false;
}
public override void AfterUpdateMovement(float deltaTime)
{
base.AfterUpdateMovement(deltaTime);
if(characterController.topBlocked)standInterval.Reset();
if(self.topBlocked)standInterval.Reset();
if (characterController.ExpectRun.shouldBe)
if (self.ExpectRun.shouldBe)
{
characterController.TransitionState<Run>();
self.TransitionState<Run>();
return;
}
if (characterController.ExpectCrouch.shouldBe is false)
if (self.ExpectCrouch.shouldBe is false)
{
if (characterController.topBlocked)
if (self.topBlocked)
{
}
else if(standInterval.AllowUpdateWithoutReset)
{
characterController.TransitionState<Walk>();
self.TransitionState<Walk>();
}
return;
}
@@ -597,11 +597,11 @@ namespace BITFALL.Entities.Player.Movement.States
[SerializeField] private int staminaCost = 1;
public override void OnStateEntry(IState old)
{
characterController.ExpectSprint.being = true;
self.ExpectSprint.being = true;
}
public override void OnStateExit(IState old, IState newState)
{
characterController.ExpectSprint.being = false;
self.ExpectSprint.being = false;
}
public override void UpdateRotation(ref Quaternion currentRotation, float deltaTime)
@@ -614,7 +614,7 @@ namespace BITFALL.Entities.Player.Movement.States
var baseRotation = Quaternion.identity;
base.UpdateRotation(ref baseRotation, deltaTime);
var targetRotation = Quaternion.LookRotation(baseRotation * characterController.MovementInput);
var targetRotation = Quaternion.LookRotation(baseRotation * self.MovementInput);
float maxAngleDelta = 30; // 你可以根据需要调整最大角度差值
float maxDeltaMagnitude = Mathf.Sin(Mathf.Deg2Rad * maxAngleDelta / 2);
@@ -636,35 +636,35 @@ namespace BITFALL.Entities.Player.Movement.States
}
public override void OnStateUpdate(float deltaTime)
{
if (actor.IsGrounded && actor.Velocity.GetLength() > characterController.initialSpeed/2)
characterController.Stamina -= staminaCost * deltaTime;
AudioSensorService.MakeNoise(actor.Position,characterController.transform);
if (actor.IsGrounded && actor.Velocity.GetLength() > self.initialSpeed/2)
self.Stamina -= staminaCost * deltaTime;
AudioSensorService.MakeNoise(actor.Position,self.transform);
}
public override void AfterUpdateMovement(float deltaTime)
{
base.AfterUpdateMovement(deltaTime);
if (Enabled is false) return;
if (characterController.pauseRun.Allow)
if (self.pauseRun.Allow)
{
characterController.TransitionState<Walk>();
self.TransitionState<Walk>();
return;
}
switch (characterController.ExpectRun.shouldBe,characterController.ExpectCrouch.shouldBe)
switch (self.ExpectRun.shouldBe,self.ExpectCrouch.shouldBe)
{
case (_,_) when characterController.Stamina is 0:
characterController.ExpectSprint.Reset();
characterController.TransitionState<Run>();
case (_,_) when self.Stamina is 0:
self.ExpectSprint.Reset();
self.TransitionState<Run>();
return;
case (_,true) when characterController.IsGrounded && characterController.Stamina > 0:
characterController.Stamina -= slideCost;
characterController.TransitionState<Slide>();
case (_,true) when self.IsGrounded && self.Stamina > 0:
self.Stamina -= slideCost;
self.TransitionState<Slide>();
return;
case (_,true):
characterController.TransitionState<Crouch>();
self.TransitionState<Crouch>();
return;
case (true,false) when characterController.MovementInput.z <=0:
case (true,false) when self.MovementInput.z <=0:
case (false,false):
characterController.TransitionState<Walk>();
self.TransitionState<Walk>();
return;
}
}
@@ -672,7 +672,7 @@ namespace BITFALL.Entities.Player.Movement.States
{
if (Enabled is false) return;
if(command is PlayerCancelRunCommand)
characterController.TransitionState<Walk>();
self.TransitionState<Walk>();
}
}
@@ -708,16 +708,16 @@ namespace BITFALL.Entities.Player.Movement.States
public override void AfterUpdateMovement(float deltaTime)
{
base.AfterUpdateMovement(deltaTime);
characterController.CurrentCameraPosition.shouldBe = characterController.FpvLocalPosition;
self.CurrentCameraPosition.shouldBe = self.FpvLocalPosition;
}
private void OnRevive()
{
if(Enabled)characterController.TransitionState<Walk>();
if(Enabled)self.TransitionState<Walk>();
}
private void OnKnockdown()
{
characterController.TransitionState<Knockdown>();
self.TransitionState<Knockdown>();
}
}
[Serializable]
@@ -745,7 +745,7 @@ namespace BITFALL.Entities.Player.Movement.States
_clipAction = _ClipAction;
characterController.destroyCancellationToken.Register(() =>
self.destroyCancellationToken.Register(() =>
{
Data.RemoveListender<bool>(clipEnv.Value, OnClip);
});
@@ -763,11 +763,11 @@ namespace BITFALL.Entities.Player.Movement.States
if(_health.IsAlive is false) return;
if (obj && Enabled is false)
{
characterController.TransitionState<Clip>();
self.TransitionState<Clip>();
//BIT4Log.Log<Clip>("NoClip Enabled");
}else if (Enabled && obj is false)
{
characterController.TransitionState<Walk>();
self.TransitionState<Walk>();
//BIT4Log.Log<Clip>("NoClip Disabled");
}
}
@@ -776,7 +776,7 @@ namespace BITFALL.Entities.Player.Movement.States
{
if (Enabled && obj is false)
{
characterController.TransitionState<Walk>();
self.TransitionState<Walk>();
}
}
@@ -798,12 +798,12 @@ namespace BITFALL.Entities.Player.Movement.States
public override void AfterUpdateMovement(float deltaTime)
{
base.AfterUpdateMovement(deltaTime);
actor.Position += characterController.ViewRotation * characterController.MovementInput * (
deltaTime * (_inputActionGroup.GetAction(characterController.RunAction).IsPressed()
actor.Position += self.ViewRotation * self.MovementInput * (
deltaTime * (_inputActionGroup.GetAction(self.RunAction).IsPressed()
? 8
: characterController.initialSpeed
: self.initialSpeed
));
actor.Rotation = Quaternion.Euler(0,characterController.LookInput.y,0);
actor.Rotation = Quaternion.Euler(0,self.LookInput.y,0);
}
}
}