1
This commit is contained in:
@@ -10,6 +10,7 @@ using UnityEngine.InputSystem;
|
||||
using BITKit.StateMachine;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Unity.Mathematics;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine.InputSystem.Interactions;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
@@ -95,7 +96,7 @@ namespace BITFALL.Guns
|
||||
[Inject]
|
||||
private IHealth _health;
|
||||
private static readonly int IsGrounded = Animator.StringToHash("IsGrounded");
|
||||
|
||||
private AssetableGun _gun=>item as AssetableGun;
|
||||
private bool isHolstered;
|
||||
|
||||
#region 接口实现
|
||||
@@ -209,15 +210,12 @@ namespace BITFALL.Guns
|
||||
|
||||
public override void OnUpdate(float deltaTime)
|
||||
{
|
||||
//CurrentState?.OnStateUpdate(deltaTime);
|
||||
UpdateState(deltaTime);
|
||||
switch (assetable.FireMode)
|
||||
{
|
||||
case AutoFireMode:
|
||||
expectFiring.shouldBe = fireAction.action.IsPressed();
|
||||
break;
|
||||
case SemiFireMode:
|
||||
expectFiring.shouldBe = fireAction.action.WasPressedThisFrame();
|
||||
break;
|
||||
case BurstFireMode when expectFiring.being:
|
||||
expectFiring.shouldBe = fireAction.action.WasPressedThisFrame();
|
||||
@@ -273,7 +271,8 @@ namespace BITFALL.Guns
|
||||
pos = (_transform.position+rotation * bulletInitialOffset).Fix(),
|
||||
rot = rotation,
|
||||
forward = _transform.forward.Fix(),
|
||||
initialDamage = 32,
|
||||
initialDamage = _gun.InitialDamage,
|
||||
InitialForce = _gun.InitialBulletForce,
|
||||
});
|
||||
|
||||
//播放枪口MuzzleFlash
|
||||
@@ -313,7 +312,29 @@ namespace BITFALL.Guns
|
||||
}
|
||||
private void OnFire(InputAction.CallbackContext context)
|
||||
{
|
||||
|
||||
switch (assetable.FireMode)
|
||||
{
|
||||
case AutoFireMode :
|
||||
switch (context)
|
||||
{
|
||||
case {interaction:TapInteraction , started:true}:
|
||||
expectFiring.shouldBe = true;
|
||||
break;
|
||||
case {interaction:TapInteraction , performed:true}:
|
||||
case {interaction:HoldInteraction , canceled:true}:
|
||||
expectFiring.shouldBe = false;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SemiFireMode:
|
||||
switch (context)
|
||||
{
|
||||
case { interaction: TapInteraction, started: true }:
|
||||
expectFiring.shouldBe = true;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
private void OnAim(InputAction.CallbackContext context)
|
||||
{
|
||||
|
@@ -51,8 +51,6 @@ namespace BITFALL.Guns.States
|
||||
{
|
||||
root.TransitionState<Run>();
|
||||
}
|
||||
|
||||
root.expectAiming.shouldBe = root.aimAction.action.IsPressed();
|
||||
}
|
||||
public void OnActive(ISelectable selectable)
|
||||
{
|
||||
|
@@ -2,6 +2,8 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BITFALL.Items.Melee;
|
||||
using BITFALL.Combat;
|
||||
using BITFALL.Player.Movement;
|
||||
using BITKit;
|
||||
using BITKit.Core.Entites;
|
||||
using BITKit.Entities;
|
||||
@@ -24,7 +26,7 @@ namespace BITFALL.Entities.Equipment.Melee
|
||||
public virtual bool Enabled { get; set; }
|
||||
public virtual void Initialize()
|
||||
{
|
||||
|
||||
meleeController.Entity.Inject(this);
|
||||
}
|
||||
|
||||
public virtual void OnStateEntry(IState old)
|
||||
@@ -43,6 +45,7 @@ namespace BITFALL.Entities.Equipment.Melee
|
||||
{
|
||||
[Header(Constant.Header.Input)]
|
||||
[SerializeField] private InputActionReference attackAction;
|
||||
[SerializeField] private InputActionReference blockAction;
|
||||
|
||||
[Header(Constant.Header.Gameobjects)]
|
||||
[SerializeField] private Transform velocityReference;
|
||||
@@ -55,15 +58,68 @@ namespace BITFALL.Entities.Equipment.Melee
|
||||
|
||||
[Inject]
|
||||
private IEntityMovement _movement;
|
||||
[Inject]
|
||||
private IPlayerMovement _playerMovement;
|
||||
[Inject] private IHealth _health;
|
||||
public override void OnAwake()
|
||||
{
|
||||
base.OnAwake();
|
||||
inputActionGroup.RegisterCallback(attackAction, OnAttack);
|
||||
inputActionGroup.RegisterCallback(blockAction, OnBlock);
|
||||
_health.OnDamageFactory += OnDamageFactory;
|
||||
|
||||
_movement.OnStateChanged += OnMovementStateChanged;
|
||||
}
|
||||
|
||||
private void OnMovementStateChanged(IEntityMovementState arg1, IEntityMovementState arg2)
|
||||
{
|
||||
switch (arg2)
|
||||
{
|
||||
case IPlayerDodgeState:
|
||||
TransitionState<Idle>();
|
||||
animator.Play(BITConstant.Player.Dodge);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private int OnDamageFactory(DamageMessage arg1, int arg2)
|
||||
{
|
||||
if (Enabled is false || arg1.Initiator is null) return arg2;
|
||||
if (CurrentState is not Blocking blocking) return arg2;
|
||||
var combat = arg1.Initiator.Get<IMeleeCombat>();
|
||||
if (combat is null) return arg2;
|
||||
|
||||
if (blocking.AllowBlockStun && _playerMovement.Stamina >= melee.BlockStaminaCost)
|
||||
{
|
||||
arg2 =0;
|
||||
combat.HitStun();
|
||||
|
||||
animator.Play(BITConstant.Player.BlockStun);
|
||||
|
||||
_playerMovement.Stamina -= melee.BlockStaminaCost*0.5f;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_playerMovement.Stamina > melee.BlockStaminaCost)
|
||||
{
|
||||
animator.Play(BITConstant.Player.BlockStun);
|
||||
arg2 /= 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
animator.Play(BITConstant.Player.BlockBreak);
|
||||
arg2 /= 2;
|
||||
}
|
||||
_playerMovement.Stamina -= melee.BlockStaminaCost;
|
||||
}
|
||||
|
||||
|
||||
return arg2;
|
||||
}
|
||||
public override void Entry()
|
||||
{
|
||||
base.Entry();
|
||||
|
||||
TransitionState<Draw>();
|
||||
}
|
||||
|
||||
@@ -79,7 +135,19 @@ namespace BITFALL.Entities.Equipment.Melee
|
||||
|
||||
animator.animator.SetFloat(BITConstant.Player.SqrMagnitude,sqr);
|
||||
}
|
||||
|
||||
private void OnBlock(InputAction.CallbackContext obj)
|
||||
{
|
||||
switch (obj)
|
||||
{
|
||||
case {interaction:TapInteraction,started:true} when CurrentState is Idle:
|
||||
TransitionState<Blocking>();
|
||||
break;
|
||||
case {interaction:TapInteraction,performed:true} when CurrentState is Blocking:
|
||||
case {interaction:HoldInteraction,canceled:true} when CurrentState is Blocking:
|
||||
TransitionState<Idle>();
|
||||
break;
|
||||
}
|
||||
}
|
||||
private void OnAttack(InputAction.CallbackContext context)
|
||||
{
|
||||
//如果启用了指针则不开火
|
||||
@@ -89,13 +157,13 @@ namespace BITFALL.Entities.Equipment.Melee
|
||||
}
|
||||
switch (context)
|
||||
{
|
||||
case {interaction: TapInteraction,performed:true} when CurrentState is not (Attack or HeavyAttack or Draw):
|
||||
case {interaction: TapInteraction,performed:true} when CurrentState is not (Attack or HeavyAttack or Draw or Blocking):
|
||||
TransitionState<Attack>();
|
||||
break;
|
||||
case {interaction: HoldInteraction,started:true} when CurrentState is not (Charging or Attack or HeavyAttack or Draw):
|
||||
case {interaction: HoldInteraction,started:true} when CurrentState is not (Charging or Attack or HeavyAttack or Draw or Blocking):
|
||||
TransitionState<Charging>();
|
||||
break;
|
||||
case {interaction: HoldInteraction,canceled:true} when CurrentState is not (Attack or Idle or Draw):
|
||||
case {interaction: HoldInteraction,canceled:true} when CurrentState is not (Attack or Idle or Draw or Blocking):
|
||||
TransitionState<HeavyAttack>();
|
||||
break;
|
||||
}
|
||||
|
@@ -1,6 +1,9 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BITFALL.Player.Movement;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
using BITKit.StateMachine;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -28,16 +31,46 @@ namespace BITFALL.Entities.Equipment.Melee
|
||||
[Serializable]
|
||||
public sealed class Idle:PlayerMeleeControllerState
|
||||
{
|
||||
|
||||
}
|
||||
[Serializable]
|
||||
public sealed class Run:PlayerMeleeControllerState
|
||||
{
|
||||
|
||||
[Inject]
|
||||
private IEntityMovement _movement;
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
_movement.OnStateChanged += OnMovementStateChanged;
|
||||
}
|
||||
|
||||
public override void OnStateEntry(IState old)
|
||||
{
|
||||
base.OnStateEntry(old);
|
||||
meleeController.animator.CrossFade(BITConstant.Player.Idle,1f);
|
||||
}
|
||||
|
||||
public override void OnStateUpdate(float deltaTime)
|
||||
{
|
||||
base.OnStateUpdate(deltaTime);
|
||||
meleeController.animator.animator.SetBool(BITConstant.Player.IsRunning,_movement.CurrentState is IPlayerRunState or IPlayerSprintState);
|
||||
meleeController.animator.animator.SetBool(BITConstant.Player.IsGrounded,_movement.IsGrounded);
|
||||
meleeController.animator.animator.SetBool(BITConstant.Player.IsCrouched,_movement.CurrentState is IPlayerCrouchState);
|
||||
}
|
||||
|
||||
private void OnMovementStateChanged(IEntityMovementState arg1, IEntityMovementState arg2)
|
||||
{
|
||||
switch (arg2)
|
||||
{
|
||||
case IPlayerClimbState:
|
||||
case IPlayerLinkState:
|
||||
meleeController.animator.Play(BITConstant.Player.Climb);
|
||||
break;
|
||||
}
|
||||
|
||||
if (Enabled is false) return;
|
||||
}
|
||||
}
|
||||
[Serializable]
|
||||
public sealed class Attack:PlayerMeleeControllerState
|
||||
{
|
||||
[Inject]
|
||||
private IEntityMovement _movement;
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -47,31 +80,40 @@ namespace BITFALL.Entities.Equipment.Melee
|
||||
meleeController.TransitionState<Idle>();
|
||||
};
|
||||
}
|
||||
|
||||
public override void OnStateEntry(IState old)
|
||||
{
|
||||
base.OnStateEntry(old);
|
||||
meleeController.animator.Play(BITConstant.Player.Attack);
|
||||
}
|
||||
public override void OnStateUpdate(float deltaTime)
|
||||
{
|
||||
base.OnStateUpdate(deltaTime);
|
||||
_movement.ExecuteCommand<PlayerCancelRunCommand>();
|
||||
}
|
||||
}
|
||||
[Serializable]
|
||||
public sealed class Charging:PlayerMeleeControllerState
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
}
|
||||
[Inject]
|
||||
private IEntityMovement _movement;
|
||||
|
||||
public override void OnStateEntry(IState old)
|
||||
{
|
||||
base.OnStateEntry(old);
|
||||
meleeController.animator.Play(BITConstant.Player.Charging);
|
||||
|
||||
}
|
||||
public override void OnStateUpdate(float deltaTime)
|
||||
{
|
||||
base.OnStateUpdate(deltaTime);
|
||||
_movement.ExecuteCommand<PlayerCancelRunCommand>();
|
||||
}
|
||||
}
|
||||
[Serializable]
|
||||
public sealed class HeavyAttack:PlayerMeleeControllerState
|
||||
{
|
||||
[Inject]
|
||||
private IPlayerMovement _playerMovement;
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -80,12 +122,33 @@ namespace BITFALL.Entities.Equipment.Melee
|
||||
if(Enabled && state is BITConstant.Player.HeavyAttack)
|
||||
meleeController.TransitionState<Idle>();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public override void OnStateEntry(IState old)
|
||||
{
|
||||
base.OnStateEntry(old);
|
||||
meleeController.animator.Play(BITConstant.Player.HeavyAttack);
|
||||
_playerMovement.Stamina -= meleeController.melee.HeavyAttackStaminaCost;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public sealed class Blocking : PlayerMeleeControllerState
|
||||
{
|
||||
public bool AllowBlockStun => _interval.AllowUpdateWithoutReset is false;
|
||||
private readonly IntervalUpdate _interval = new(0.32f);
|
||||
[Inject]
|
||||
private IEntityMovement _movement;
|
||||
public override void OnStateEntry(IState old)
|
||||
{
|
||||
base.OnStateEntry(old);
|
||||
_interval.Reset();
|
||||
meleeController.animator.Play(BITConstant.Player.Blocking);
|
||||
}
|
||||
public override void OnStateUpdate(float deltaTime)
|
||||
{
|
||||
base.OnStateUpdate(deltaTime);
|
||||
_movement.ExecuteCommand<PlayerCancelRunCommand>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -69,6 +69,7 @@ namespace BITFALL.Player.Equip
|
||||
|
||||
private void OnEquip(IBasicItem obj)
|
||||
{
|
||||
if (IsEntered is false) return;
|
||||
spriteRenderer.sprite = null;
|
||||
if (modelDictionary.TryGetValue(obj.AddressablePath, out var model))
|
||||
model.gameObject.SetActive(true);
|
||||
|
89
Assets/Artists/Scripts/Equip/ThrowController.cs
Normal file
89
Assets/Artists/Scripts/Equip/ThrowController.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BITFALL.Entities.Equipment;
|
||||
using BITFALL.Entities.Inventory;
|
||||
using BITFALL.Items;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
using BITKit.StateMachine;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.InputSystem.Interactions;
|
||||
|
||||
namespace BITFALL.Throws
|
||||
{
|
||||
public interface IThrowState:IState{}
|
||||
public class ThrowController : BITEquipBase<IThrowState>
|
||||
{
|
||||
[Header(nameof(throwPoint))]
|
||||
[SerializeField] private Transform throwPoint;
|
||||
[SerializeField] private float throwForce;
|
||||
[SerializeField] private InputActionReference throwAction;
|
||||
private AssetableThrow _assetableThrow=>(AssetableThrow)item;
|
||||
[Inject] private IPlayerEquipSelector _equipSelector;
|
||||
[Inject] private IEntityInventory _inventory;
|
||||
[Inject] private IEntityEquipmentContainer _equipmentContainer;
|
||||
private bool isHolding;
|
||||
public override void OnAwake()
|
||||
{
|
||||
inputActionGroup.RegisterCallback(throwAction, OnThrow);
|
||||
base.OnAwake();
|
||||
animator[0].onStateExit += OnStateExit;
|
||||
}
|
||||
private void OnStateExit(string obj)
|
||||
{
|
||||
if (IsEntered is false) return;
|
||||
switch (obj)
|
||||
{
|
||||
case BITConstant.Player.Draw:
|
||||
if (isHolding is false)
|
||||
{
|
||||
animator.Play(BITConstant.Player.Throw);
|
||||
}
|
||||
break;
|
||||
case BITConstant.Player.Throw:
|
||||
_equipSelector.Cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Entry()
|
||||
{
|
||||
isHolding = false;
|
||||
base.Entry();
|
||||
animator.Play(BITConstant.Player.Draw);
|
||||
}
|
||||
|
||||
private void OnThrow(InputAction.CallbackContext obj)
|
||||
{
|
||||
switch (obj)
|
||||
{
|
||||
case { interaction: HoldInteraction, performed: true }:
|
||||
isHolding = true;
|
||||
break;
|
||||
case { interaction: HoldInteraction, canceled: true }:
|
||||
if (animator[0].stateName == BITConstant.Player.Idle)
|
||||
animator.Play(BITConstant.Player.Throw);
|
||||
break;
|
||||
}
|
||||
// if(obj is not {interaction:TapInteraction, performed:true}) return;
|
||||
// switch (animator[0].stateName)
|
||||
// {
|
||||
// case BITConstant.Player.Idle:
|
||||
// animator.Play(BITConstant.Player.Throw);
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
|
||||
public override void AnimationEvent(string eventName)
|
||||
{
|
||||
if (IsEntered is false) return;
|
||||
if (eventName is not BITConstant.Player.Throw) return;
|
||||
if (!_equipmentContainer.TryUseEquip<EquipmentAsThrow>()) return;
|
||||
var instance = _assetableThrow.GetInstance();
|
||||
if (!instance.TryGetComponent<Rigidbody>(out var _rigidbody)) return;
|
||||
_rigidbody.position = throwPoint.position;
|
||||
_rigidbody.AddForce(throwPoint.forward * throwForce, ForceMode.VelocityChange);
|
||||
}
|
||||
}
|
||||
}
|
@@ -46,6 +46,7 @@ namespace BITFALL.Entities.Equipment.Universal
|
||||
[Inject] private IPlayerInventory _playerInventory;
|
||||
[Inject] private IEntityInventory _inventory;
|
||||
[Inject] private IPlayerEquipSelector _playerEquipSelector;
|
||||
[Inject] private IEntityEquipmentContainer _equipmentContainer;
|
||||
public bool IClosed { get; set; }
|
||||
public override void OnAwake()
|
||||
{
|
||||
@@ -118,13 +119,17 @@ namespace BITFALL.Entities.Equipment.Universal
|
||||
public override void AnimationEvent(string eventName)
|
||||
{
|
||||
base.AnimationEvent(eventName);
|
||||
|
||||
|
||||
switch (eventName)
|
||||
{
|
||||
case BITConstant.Player.Use when CurrentState is Use:
|
||||
if (_inventory.UseItem(Item))
|
||||
if (item.TryGetProperty<EquipmentAsSlot>(out var asSlot))
|
||||
{
|
||||
|
||||
_equipmentContainer.TryUseEquip(asSlot.slot);
|
||||
}
|
||||
else
|
||||
{
|
||||
_inventory.UseItem(Item);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
Reference in New Issue
Block a user