1
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@@ -13,6 +14,23 @@ namespace BITFALL.Guns
|
||||
float FireRate { get; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 后坐力接口定义
|
||||
/// </summary>
|
||||
public interface IRecoil:IProperty
|
||||
{
|
||||
/// <summary>
|
||||
/// 后坐力的方向
|
||||
/// </summary>
|
||||
Vector3 Recoil { get; }
|
||||
}
|
||||
[Serializable]
|
||||
[CustomType(typeof(IRecoil))]
|
||||
public struct VectorRecoil:IRecoil
|
||||
{
|
||||
[SerializeField] private Vector3 recoil;
|
||||
public Vector3 Recoil => recoil;
|
||||
}
|
||||
/// <summary>
|
||||
/// 射击模式的基类
|
||||
/// </summary>
|
||||
public record FireMode : IFireMode {
|
||||
|
@@ -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)
|
||||
{
|
||||
|
@@ -1,3 +1,4 @@
|
||||
using System.Data.Odbc;
|
||||
using BITFALL.Player.Movement;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
@@ -44,6 +45,8 @@ namespace BITFALL.Guns.States
|
||||
{
|
||||
root.TransitionState<Run>();
|
||||
}
|
||||
|
||||
root.expectAiming.shouldBe = root.aimAction.action.IsPressed();
|
||||
}
|
||||
public void OnHover(ISelectable selectable)
|
||||
{
|
||||
@@ -190,10 +193,9 @@ namespace BITFALL.Guns.States
|
||||
public override void OnMovementStateChanged(IEntityMovementState old, IEntityMovementState newState)
|
||||
{
|
||||
if (Enabled is false) return;
|
||||
if(newState is IPlayerRunState or IPlayerSprintState)
|
||||
{
|
||||
root.TransitionState<Movement>();
|
||||
}
|
||||
if (newState is not (IPlayerRunState or IPlayerSprintState)) return;
|
||||
root.expectAiming.Reset();
|
||||
root.TransitionState<Movement>();
|
||||
}
|
||||
}
|
||||
[System.Serializable]
|
||||
@@ -281,7 +283,14 @@ namespace BITFALL.Guns.States
|
||||
public override void OnStateEntry(IState old)
|
||||
{
|
||||
root.animator.Play(BITGun._Melee);
|
||||
_entityMovement.ExecuteCommand(new PlayerDisableRunCommand(this));
|
||||
}
|
||||
|
||||
public override void OnStateExit(IState old, IState newState)
|
||||
{
|
||||
_entityMovement.ExecuteCommand(new PlayerEnableRunCommand(this));
|
||||
}
|
||||
|
||||
public override void OnStateUpdate(float deltaTime)
|
||||
{
|
||||
_entityMovement.ExecuteCommand<PlayerCancelRunCommand>();
|
||||
|
39
Assets/Artists/Scripts/Equip/EquipSway.cs
Normal file
39
Assets/Artists/Scripts/Equip/EquipSway.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace BITFALL.Player.Movement
|
||||
{
|
||||
public class EquipSway : EntityComponent
|
||||
{
|
||||
[SerializeField] private float rotDelta;
|
||||
[SerializeField] private float rotValue;
|
||||
[SerializeField] private float posDelta;
|
||||
[SerializeField] private float posValue;
|
||||
[SerializeField] private LocationAdditive locationAdditive;
|
||||
private Quaternion currentRotation;
|
||||
private Vector3 currentPosition;
|
||||
private IEntityMovement _movement;
|
||||
public override void OnAwake()
|
||||
{
|
||||
_movement = entity.Get<IEntityMovement>();
|
||||
}
|
||||
|
||||
public override void OnLateUpdate(float deltaTime)
|
||||
{
|
||||
var velocity = _movement.LocomotionBasedVelocity;
|
||||
var angularVelocity = _movement.AngularVelocity;
|
||||
|
||||
currentPosition = Vector3.Lerp(currentPosition,velocity * posValue,posDelta * deltaTime);
|
||||
currentRotation = Quaternion.Lerp(currentRotation,Quaternion.Euler(angularVelocity * rotValue),rotDelta * deltaTime);
|
||||
|
||||
locationAdditive.AddEuler(currentRotation.eulerAngles);
|
||||
locationAdditive.AddPosition(currentPosition);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,39 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using BITKit;
|
||||
namespace BITFALL
|
||||
{
|
||||
|
||||
public interface ISwap
|
||||
{
|
||||
void Add();
|
||||
void Remove();
|
||||
}
|
||||
[System.Serializable]
|
||||
public class BITSwap : ISwap
|
||||
{
|
||||
public void Add()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
[System.Serializable]
|
||||
public class FltotoItemContainer : ISwap
|
||||
{
|
||||
public void Add()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user