using System; using System.Collections; using System.Collections.Generic; using BITFALL.Items.Melee; using BITKit; using BITKit.Core.Entites; using BITKit.Entities; using BITKit.Entities.Melee; using BITKit.StateMachine; using Cysharp.Threading.Tasks; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Interactions; namespace BITFALL.Entities.Equipment.Melee { public interface IPlayerMeleeControllerState : IState { } public abstract class PlayerMeleeControllerState : IPlayerMeleeControllerState { [SerializeField] protected MeleeController meleeController; public virtual bool Enabled { get; set; } public virtual void Initialize() { } public virtual void OnStateEntry(IState old) { } public virtual void OnStateUpdate(float deltaTime) { } public virtual void OnStateExit(IState old, IState newState) { } } public sealed class MeleeController : BITEquipBase { [Header(Constant.Header.Input)] [SerializeField] private InputActionReference attackAction; [Header(Constant.Header.Gameobjects)] [SerializeField] private Transform velocityReference; public override string AddressablePath => item.AddressablePath; public AssetableMelee melee => item as AssetableMelee; protected override Vector3 meleeForce => _velocity; private Vector3 _velocity; private Vector3 _lastPosition; [Inject] private IEntityMovement _movement; public override void OnAwake() { base.OnAwake(); inputActionGroup.RegisterCallback(attackAction, OnAttack); } public override void Entry() { base.Entry(); TransitionState(); } public override void OnUpdate(float deltaTime) { base.OnUpdate(deltaTime); var position = velocityReference.position; _velocity = (position - _lastPosition).normalized; _lastPosition = position; UpdateState(deltaTime); var sqr = _movement.LocomotionBasedVelocity.sqrMagnitude; animator.animator.SetFloat(BITConstant.Player.SqrMagnitude,sqr); } private void OnAttack(InputAction.CallbackContext context) { //如果启用了指针则不开火 if(BITAppForUnity.AllowCursor) { return; } switch (context) { case {interaction: TapInteraction,performed:true} when CurrentState is not (Attack or HeavyAttack or Draw): TransitionState(); break; case {interaction: HoldInteraction,started:true} when CurrentState is not (Charging or Attack or HeavyAttack or Draw): TransitionState(); break; case {interaction: HoldInteraction,canceled:true} when CurrentState is not (Attack or Idle or Draw): TransitionState(); break; } } } }