add sniper

This commit is contained in:
CortexCore
2023-10-31 18:07:15 +08:00
parent 18f664a545
commit f0f348c246
47 changed files with 4568 additions and 389 deletions

View File

@@ -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)