This commit is contained in:
CortexCore
2023-09-01 14:33:54 +08:00
parent 4fadd3a530
commit 8ef5c7ec0a
451 changed files with 1048940 additions and 2028 deletions

View File

@@ -1,11 +1,13 @@
using System.Linq;
using BITFALL.Guns.States;
using BITFALL.Player.Movement;
using UnityEngine;
using BITKit;
using BITKit.Entities;
using BITKit.Entities.Melee;
using UnityEngine.InputSystem;
using BITKit.StateMachine;
using Unity.Mathematics;
using UnityEngine.InputSystem.Interactions;
#if UNITY_EDITOR
using UnityEditor;
@@ -66,6 +68,8 @@ namespace BITFALL.Guns
//简单设置
[Header(Constant.Header.Settings)]
[SerializeField] private Vector3 bulletInitialOffset;
[SerializeField] private int initialAimFov = 60;
[SerializeField] private SpringEulerAngle recoilSpring=new();
// 输入系统
[Header(Constant.Header.Input)]
@@ -80,12 +84,13 @@ namespace BITFALL.Guns
[SerializeReference, SubclassSelector] private IMeleeService meleeService;
// 引用组件
[Header(Constant.Header.Components)]
public Renderer[] rendererComponents;
public VFXPlayer vfxPlayer;
[SerializeField] private Renderer[] rendererComponents;
[SerializeField] private VFXPlayer vfxPlayer;
[SerializeField] private LocationAdditive locationAdditive;
// 引用预制体
[Header(Constant.Header.Prefabs)]
public AssetableGun assetable;
[SerializeField] internal AssetableGun assetable;
[Header(Constant.Header.Reference)]
// 内部变量burst
@@ -95,12 +100,12 @@ namespace BITFALL.Guns
internal readonly IntervalUpdate fireInterval = new(0.32f);
internal readonly IntervalUpdate burstFireInterval = new(0.1f);
internal int burstFireCount;
private SpringEulerAngle positionSpring=new();
private SpringEulerAngle recoilSpring=new();
private IEntityMovement _movement;
private IPlayerMovement _playerMovement;
private static readonly int IsGrounded = Animator.StringToHash("IsGrounded");
#region
public override string AddressablePath => assetable.AdressablePath;
public override string AddressablePath => assetable.AddressablePath;
#endregion
public override void OnAwake()
@@ -110,7 +115,20 @@ namespace BITFALL.Guns
actionGroup.RegisterCallback(aimAction, OnAim);
actionGroup.RegisterCallback(reloadAction, OnReload);
actionGroup.RegisterCallback(meleeAction, OnMelee);
entity.Get<IEntityMovement>().OnStateChanged += OnMovementStateChanged;
_movement = entity.Get<IEntityMovement>();
_playerMovement = entity.Get<IPlayerMovement>();
_movement.OnStateChanged += OnMovementStateChanged;
_movement.OnCommand += OnMovementCommand;
}
private void OnMovementCommand(object obj)
{
switch (obj)
{
case OnPlayerJumpCommand:
animator.Play("Jump");
break;
}
}
private void OnMelee(InputAction.CallbackContext obj)
@@ -155,6 +173,8 @@ namespace BITFALL.Guns
public override void Entry()
{
base.Entry();
var animName = animator.animator.GetCurrentAnimatorStateInfo(0).shortNameHash;
animator.animator.Play(animName,-1,0);
animator.animator.enabled = true;
actionGroup.allowInput.AddElement(this);
foreach (var x in rendererComponents)
@@ -205,6 +225,11 @@ namespace BITFALL.Guns
}
break;
}
animator.animator.SetBool(IsGrounded,_movement.IsGrounded);
recoilSpring.Update(deltaTime,default);
locationAdditive.AddEuler(recoilSpring.value);
}
public override void AnimationEvent(string eventName)
@@ -267,8 +292,18 @@ namespace BITFALL.Guns
}
break;
}
// .value = new Vector3(Random.Range(-gunSpec.recoil.x, 0), gunSpec.recoil.y.Random(), 0);
// sprintPos.value -= new Vector3(gunSpec.recoil.z.Random(), 0, gunSpec.recoil.z);
if (assetable.TryGetProperty<IRecoil>(out var _recoil))
{
var _newRecoil = new Vector3
{
x = _recoil.Recoil.x,
y = _recoil.Recoil.y.Random(),
z = _recoil.Recoil.z.Random()
};
recoilSpring.value = _newRecoil;
_playerMovement.AddViewEuler(new float2(_newRecoil.x,_newRecoil.y));
}
}
private void OnFire(InputAction.CallbackContext context)
{