add sniper
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using BITFALL.Guns.States;
|
||||
using BITFALL.Player.Equip;
|
||||
using BITFALL.Player.Movement;
|
||||
using UnityEngine;
|
||||
using BITKit;
|
||||
@@ -78,9 +79,6 @@ namespace BITFALL.Guns
|
||||
|
||||
// 引用预制体
|
||||
[Header(Constant.Header.Prefabs)]
|
||||
[SerializeField] internal AssetableGun assetable;
|
||||
[Header(Constant.Header.Reference)]
|
||||
|
||||
// 内部变量burst
|
||||
[Header(Constant.Header.InternalVariables)]
|
||||
public ExpectState<bool> expectFiring;
|
||||
@@ -94,12 +92,16 @@ namespace BITFALL.Guns
|
||||
private IPlayerMovement _playerMovement;
|
||||
[Inject]
|
||||
private IHealth _health;
|
||||
|
||||
[Inject] private IEquipService _equipService;
|
||||
private static readonly int IsGrounded = Animator.StringToHash("IsGrounded");
|
||||
private AssetableGun _gun=>item as AssetableGun;
|
||||
private bool isHolstered;
|
||||
|
||||
public bool RequireBolt { get; set; }
|
||||
|
||||
#region 接口实现
|
||||
public override string AddressablePath => assetable.AddressablePath;
|
||||
public override string AddressablePath => _gun.AddressablePath;
|
||||
#endregion
|
||||
|
||||
public override void OnAwake()
|
||||
@@ -166,10 +168,10 @@ namespace BITFALL.Guns
|
||||
expectFiring.Reset();
|
||||
Enabled = true;
|
||||
|
||||
fireInterval.Interval = 1f / assetable.FireMode.FireRate;
|
||||
fireInterval.Interval = 1f / _gun.FireMode.FireRate;
|
||||
fireInterval.Reset();
|
||||
|
||||
if (assetable.FireMode is BurstFireMode burstFireMode)
|
||||
if (_gun.FireMode is BurstFireMode burstFireMode)
|
||||
{
|
||||
burstFireInterval.Interval = burstFireMode.BurstFireInterval;
|
||||
burstFireInterval.Reset();
|
||||
@@ -183,6 +185,9 @@ namespace BITFALL.Guns
|
||||
public override async UniTask ExitAsync()
|
||||
{
|
||||
TransitionState<Holster>();
|
||||
|
||||
_equipService.AllowAttack = false;
|
||||
|
||||
inputActionGroup.allowInput.RemoveElement(this);
|
||||
expectFiring.Reset();
|
||||
|
||||
@@ -193,11 +198,17 @@ namespace BITFALL.Guns
|
||||
while (_health.IsAlive && isHolstered is false)
|
||||
{
|
||||
destroyCancellationToken.ThrowIfCancellationRequested();
|
||||
_equipService.Zoom.Value = Mathf.MoveTowards(_equipService.Zoom.Value,0,Time.deltaTime);
|
||||
await UniTask.NextFrame();
|
||||
}
|
||||
|
||||
_equipService.Zoom.Allow = false;
|
||||
|
||||
destroyCancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
_equipService.Stable = 1;
|
||||
|
||||
|
||||
await base.ExitAsync();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
@@ -208,7 +219,7 @@ namespace BITFALL.Guns
|
||||
public override void OnUpdate(float deltaTime)
|
||||
{
|
||||
UpdateState(deltaTime);
|
||||
switch (assetable.FireMode)
|
||||
switch (_gun.FireMode)
|
||||
{
|
||||
case AutoFireMode:
|
||||
break;
|
||||
@@ -218,7 +229,13 @@ namespace BITFALL.Guns
|
||||
expectFiring.shouldBe = fireAction.action.WasPressedThisFrame();
|
||||
if(burstFireInterval.AllowUpdate)
|
||||
{
|
||||
Fire();
|
||||
switch (AnimationProperties.TryGetValue(BITConstant.Player.AllowFire, out var allowFire))
|
||||
{
|
||||
case false:
|
||||
case true when allowFire >0.9f:
|
||||
Fire();
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -229,6 +246,25 @@ namespace BITFALL.Guns
|
||||
recoilSpring.Update(deltaTime,default);
|
||||
|
||||
locationAdditive.AddEuler(recoilSpring.value);
|
||||
|
||||
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.AllowScope = _aim > 0.86f && _gun.IsScopeAim;
|
||||
}
|
||||
|
||||
if (AnimationProperties.TryGetValue(BITConstant.Player.Stable, out var stable))
|
||||
{
|
||||
_equipService.Stable = stable;
|
||||
}
|
||||
|
||||
if(AnimationProperties.TryGetValue(BITConstant.Player.AllowFire, out var _allowFire))
|
||||
{
|
||||
_equipService.AllowAttack = _allowFire > 0.9f;
|
||||
}
|
||||
|
||||
AllowRendering.SetDisableElements(64564,_equipService.AllowScope);
|
||||
}
|
||||
|
||||
public override void AnimationEvent(string eventName)
|
||||
@@ -250,6 +286,7 @@ namespace BITFALL.Guns
|
||||
}
|
||||
public void Fire()
|
||||
{
|
||||
if (RequireBolt) return;
|
||||
//如果启用了指针则不开火
|
||||
if(BITAppForUnity.AllowCursor)
|
||||
{
|
||||
@@ -273,7 +310,7 @@ namespace BITFALL.Guns
|
||||
});
|
||||
|
||||
//开火模式逻辑判断
|
||||
switch (assetable.FireMode)
|
||||
switch (_gun.FireMode)
|
||||
{
|
||||
case AutoFireMode:
|
||||
break;
|
||||
@@ -291,7 +328,7 @@ namespace BITFALL.Guns
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (assetable.TryGetProperty<IRecoil>(out var _recoil))
|
||||
if (_gun.TryGetProperty<IRecoil>(out var _recoil))
|
||||
{
|
||||
var _newRecoil = new Vector3
|
||||
{
|
||||
@@ -302,11 +339,15 @@ namespace BITFALL.Guns
|
||||
recoilSpring.value = _newRecoil;
|
||||
_playerMovement.AddViewEuler(new float2(_newRecoil.x,_newRecoil.y));
|
||||
}
|
||||
|
||||
|
||||
if (_gun.FireMode is SemiFireMode {RequireBoltAction:true})
|
||||
{
|
||||
RequireBolt = true;
|
||||
}
|
||||
}
|
||||
private void OnFire(InputAction.CallbackContext context)
|
||||
{
|
||||
switch (assetable.FireMode)
|
||||
switch (_gun.FireMode)
|
||||
{
|
||||
case AutoFireMode :
|
||||
switch (context)
|
||||
|
@@ -7,6 +7,7 @@ using BITKit.Selection;
|
||||
using UnityEngine.InputSystem;
|
||||
using BITKit.StateMachine;
|
||||
using UnityEngine;
|
||||
// ReSharper disable UnassignedField.Local
|
||||
|
||||
namespace BITFALL.Guns.States
|
||||
{
|
||||
@@ -19,6 +20,8 @@ namespace BITFALL.Guns.States
|
||||
{
|
||||
[SerializeField] private ExpectState<bool> _expectRun;
|
||||
[Inject] protected ISelector _selector;
|
||||
private float elapsedTime;
|
||||
private bool boltActionImmediately;
|
||||
public override void OnStateEntry(IState old)
|
||||
{
|
||||
switch (old)
|
||||
@@ -31,14 +34,17 @@ namespace BITFALL.Guns.States
|
||||
break;
|
||||
}
|
||||
_selector.OnActive += OnActive;
|
||||
boltActionImmediately = root.RequireBolt;
|
||||
}
|
||||
public override void OnStateExit(IState old, IState newState)
|
||||
{
|
||||
elapsedTime = 0;
|
||||
base.OnStateExit(old, newState);
|
||||
_selector.OnActive -= OnActive;
|
||||
}
|
||||
public override void OnStateUpdate(float deltaTime)
|
||||
{
|
||||
elapsedTime += deltaTime;
|
||||
if (root.animator[0].stateName is not BITConstant.Player.Movement) return;
|
||||
if (root.expectFiring.shouldBe && root.fireInterval.AllowUpdate)
|
||||
{
|
||||
@@ -50,6 +56,9 @@ namespace BITFALL.Guns.States
|
||||
}else if (_expectRun)
|
||||
{
|
||||
root.TransitionState<Run>();
|
||||
}else if (root.RequireBolt && elapsedTime > 0.5f || boltActionImmediately)
|
||||
{
|
||||
root.TransitionState<Reload>();
|
||||
}
|
||||
}
|
||||
public void OnActive(ISelectable selectable)
|
||||
@@ -146,8 +155,6 @@ namespace BITFALL.Guns.States
|
||||
[System.Serializable]
|
||||
public sealed class Aim : GunState
|
||||
{
|
||||
[Inject]
|
||||
private IEquipService _equipService;
|
||||
public override void OnStateEntry(IState old)
|
||||
{
|
||||
switch (old)
|
||||
@@ -160,7 +167,6 @@ namespace BITFALL.Guns.States
|
||||
root.animator.CrossFade(BITConstant.Player.Aim, 0.16f);
|
||||
break;
|
||||
}
|
||||
_equipService.Zoom.Allow = true;
|
||||
_entityMovement.ExecuteCommand<PlayerCancelRunCommand>();
|
||||
}
|
||||
|
||||
@@ -183,13 +189,6 @@ namespace BITFALL.Guns.States
|
||||
{
|
||||
root.TransitionState<Movement>();
|
||||
}
|
||||
_equipService.Zoom.Value = root.aimAction.action.ReadValue<float>();
|
||||
}
|
||||
|
||||
public override void OnStateExit(IState old, IState newState)
|
||||
{
|
||||
base.OnStateExit(old, newState);
|
||||
_equipService.Zoom.Allow = false;
|
||||
}
|
||||
|
||||
public override void OnMovementStateChanged(IEntityMovementState old, IEntityMovementState newState)
|
||||
@@ -260,8 +259,16 @@ namespace BITFALL.Guns.States
|
||||
base.OnStateEntry(old);
|
||||
|
||||
_entityMovement.ExecuteCommand<PlayerCancelRunCommand>();
|
||||
|
||||
root.UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.Reload);
|
||||
|
||||
if (root.RequireBolt)
|
||||
{
|
||||
root.UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.BoltAction);
|
||||
}
|
||||
else
|
||||
{
|
||||
root.UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.Reload);
|
||||
}
|
||||
|
||||
}
|
||||
public override void OnMovementStateChanged(IEntityMovementState old, IEntityMovementState newState)
|
||||
{
|
||||
@@ -271,8 +278,13 @@ namespace BITFALL.Guns.States
|
||||
root.TransitionState<Movement>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnStateExit(IState old, IState newState)
|
||||
{
|
||||
root.RequireBolt = false;
|
||||
base.OnStateExit(old, newState);
|
||||
}
|
||||
}
|
||||
[System.Serializable]
|
||||
public sealed class Melee : GunState
|
||||
{
|
||||
|
Reference in New Issue
Block a user