1
This commit is contained in:
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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user