1
This commit is contained in:
@@ -62,14 +62,21 @@ namespace BITFALL.Guns
|
||||
[Header(Constant.Header.Settings)]
|
||||
[SerializeField] private Vector3 bulletInitialOffset;
|
||||
[SerializeField] private SpringEulerAngle recoilSpring=new();
|
||||
|
||||
[Header(Constant.Header.Gameobjects)]
|
||||
[SerializeField] private Transform initialSight;
|
||||
[SerializeField] private Optional<Transform> newSight;
|
||||
|
||||
[Header(nameof(Optional<GameObject>))]
|
||||
[SerializeField] private Optional<LocationAdditive> breathingAdditive;
|
||||
|
||||
// 输入系统
|
||||
[Header(Constant.Header.Input)]
|
||||
public InputActionReference fireAction;
|
||||
public InputActionReference aimAction;
|
||||
public InputActionReference reloadAction;
|
||||
public InputActionReference meleeAction;
|
||||
|
||||
[SerializeField] internal InputActionReference fireAction;
|
||||
[SerializeField] internal InputActionReference aimAction;
|
||||
[SerializeField] internal InputActionReference reloadAction;
|
||||
[SerializeField] internal InputActionReference meleeAction;
|
||||
[SerializeField] internal InputActionReference steadyAimAction;
|
||||
|
||||
[Header(Constant.Header.HotFix)]
|
||||
[SerializeField] private Transform cameraView;
|
||||
@@ -97,6 +104,7 @@ namespace BITFALL.Guns
|
||||
private static readonly int IsGrounded = Animator.StringToHash("IsGrounded");
|
||||
private AssetableGun _gun=>item as AssetableGun;
|
||||
private bool isHolstered;
|
||||
private bool isSteadyAim;
|
||||
|
||||
public bool RequireBolt { get; set; }
|
||||
|
||||
@@ -111,6 +119,7 @@ namespace BITFALL.Guns
|
||||
inputActionGroup.RegisterCallback(aimAction, OnAim);
|
||||
inputActionGroup.RegisterCallback(reloadAction, OnReload);
|
||||
inputActionGroup.RegisterCallback(meleeAction, OnMelee);
|
||||
inputActionGroup.RegisterCallback(steadyAimAction, OnSteadyAim);
|
||||
_movement.OnStateChanged += OnMovementStateChanged;
|
||||
_movement.OnCommand += OnMovementCommand;
|
||||
|
||||
@@ -119,6 +128,20 @@ namespace BITFALL.Guns
|
||||
isHolstered = state is BITConstant.Player.Holster;
|
||||
};
|
||||
}
|
||||
|
||||
private void OnSteadyAim(InputAction.CallbackContext obj)
|
||||
{
|
||||
switch (obj)
|
||||
{
|
||||
case { interaction: PressInteraction, performed: true } when CurrentState is Aim:
|
||||
isSteadyAim = true;
|
||||
break;
|
||||
case { interaction: PressInteraction, canceled: true }:
|
||||
isSteadyAim = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMovementCommand(object obj)
|
||||
{
|
||||
switch (obj)
|
||||
@@ -215,7 +238,6 @@ namespace BITFALL.Guns
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnUpdate(float deltaTime)
|
||||
{
|
||||
UpdateState(deltaTime);
|
||||
@@ -240,6 +262,8 @@ namespace BITFALL.Guns
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
animator.animator.SetBool(IsGrounded,_movement.IsGrounded);
|
||||
animator.animator.SetFloat(BITConstant.Player.SqrMagnitude,_movement.LocomotionBasedVelocity.sqrMagnitude);
|
||||
|
||||
@@ -250,8 +274,50 @@ namespace BITFALL.Guns
|
||||
if(AnimationProperties.TryGetValue(BITConstant.Player.Aim, out var _aim))
|
||||
{
|
||||
_equipService.Zoom.Allow = CurrentState is Aim;
|
||||
_equipService.Zoom.Value =Mathf.Lerp(0,_gun.InitialAimZoom, _aim);
|
||||
_equipService.Zoom.Value =Mathf.Lerp(1,_gun.InitialAimZoom, _aim);
|
||||
_equipService.AllowScope = _aim > 0.86f && _gun.IsScopeAim;
|
||||
|
||||
if (breathingAdditive.Allow)
|
||||
{
|
||||
var breatheFrequency = 0.5f; // 呼吸的频率,值越大呼吸越快
|
||||
var breatheAmplitude = 0.005f; // 呼吸的幅度,即准星上下移动的最大距离
|
||||
|
||||
if (_playerMovement.Stamina <= 8)
|
||||
{
|
||||
breatheFrequency = 8;
|
||||
breatheAmplitude = 0.1f;
|
||||
}
|
||||
|
||||
var breatheOffset = Mathf.Sin(Time.time * breatheFrequency) * breatheAmplitude;
|
||||
|
||||
if (isSteadyAim)
|
||||
{
|
||||
if (_playerMovement.Stamina > 0)
|
||||
{
|
||||
_playerMovement.Stamina -= 16 * deltaTime;
|
||||
breatheOffset *= 0.16f;
|
||||
}
|
||||
else
|
||||
{
|
||||
isSteadyAim = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
breatheOffset *= _aim;
|
||||
}
|
||||
|
||||
_playerMovement.AddViewEuler(new float2(breatheOffset, breatheOffset));
|
||||
}
|
||||
|
||||
if (newSight.Allow)
|
||||
{
|
||||
transform.localPosition=Vector3.Lerp(default, newSight.Value.position-initialSight.position, _aim);
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.localPosition = default;
|
||||
}
|
||||
}
|
||||
|
||||
if (AnimationProperties.TryGetValue(BITConstant.Player.Stable, out var stable))
|
||||
@@ -266,7 +332,7 @@ namespace BITFALL.Guns
|
||||
|
||||
AllowRendering.SetDisableElements(64564,_equipService.AllowScope);
|
||||
}
|
||||
|
||||
|
||||
public override void AnimationEvent(string eventName)
|
||||
{
|
||||
if(IsEntered is false) return;
|
||||
@@ -302,10 +368,11 @@ namespace BITFALL.Guns
|
||||
BulletService.Spawn(new SpawnBullet
|
||||
{
|
||||
initiator = Entity.Id,
|
||||
pos = (_transform.position+rotation * bulletInitialOffset).Fix(),
|
||||
pos = (_transform.position+rotation * bulletInitialOffset),
|
||||
rot = rotation,
|
||||
forward = _transform.forward.Fix(),
|
||||
forward = _transform.forward,
|
||||
initialDamage = _gun.InitialDamage,
|
||||
startSpeed = _gun.InitialBulletSpeed,
|
||||
InitialForce = _gun.InitialBulletForce,
|
||||
});
|
||||
|
||||
@@ -352,11 +419,10 @@ namespace BITFALL.Guns
|
||||
case AutoFireMode :
|
||||
switch (context)
|
||||
{
|
||||
case {interaction:TapInteraction , started:true}:
|
||||
case {interaction:PressInteraction , started:true}:
|
||||
expectFiring.shouldBe = true;
|
||||
break;
|
||||
case {interaction:TapInteraction , performed:true}:
|
||||
case {interaction:HoldInteraction , canceled:true}:
|
||||
case {interaction:PressInteraction , canceled:true}:
|
||||
expectFiring.shouldBe = false;
|
||||
break;
|
||||
}
|
||||
@@ -364,7 +430,7 @@ namespace BITFALL.Guns
|
||||
case SemiFireMode:
|
||||
switch (context)
|
||||
{
|
||||
case { interaction: TapInteraction, started: true }:
|
||||
case { interaction: PressInteraction, started: true } when fireInterval.AllowUpdateWithoutReset && RequireBolt is false:
|
||||
expectFiring.shouldBe = true;
|
||||
break;
|
||||
}
|
||||
|
Reference in New Issue
Block a user