1
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Animancer;
|
||||
using BITFALL.Entities.Equipment;
|
||||
using BITFALL.Entities.Inventory;
|
||||
using BITFALL.Items;
|
||||
@@ -10,74 +11,83 @@ using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.InputSystem.Interactions;
|
||||
|
||||
namespace BITFALL.Throws
|
||||
namespace BITFALL.Player.Equip
|
||||
{
|
||||
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 IEntityEquipmentContainer _equipmentContainer;
|
||||
private bool isHolding;
|
||||
public override void OnAwake()
|
||||
public static void Throw(Transform throwPoint,int throwForce, IBasicItem item)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public override void AnimationEvent(string eventName)
|
||||
{
|
||||
if (IsEntered is false) return;
|
||||
if (eventName is not BITConstant.Player.Throw) return;
|
||||
|
||||
if (!_equipmentContainer.TryUseEquip<EquipmentAsThrow>() && !_equipmentContainer.TryUseEquip<EquipmentAsTactics>()) return;
|
||||
var instance =Instantiate(_assetableThrow.Prefab,
|
||||
if (item.GetAssetable() is not AssetableThrow assetableThrow) return;
|
||||
var instance =Instantiate(assetableThrow.Prefab,
|
||||
throwPoint.position + throwPoint.forward * 0.016f,
|
||||
throwPoint.rotation) ;
|
||||
if (!instance.TryGetComponent<Rigidbody>(out var _rigidbody)) return;
|
||||
_rigidbody.AddForce(throwPoint.forward * throwForce, ForceMode.VelocityChange);
|
||||
var forward = throwPoint.forward;
|
||||
_rigidbody.AddForce(forward * throwForce, ForceMode.VelocityChange);
|
||||
_rigidbody.AddTorque(forward * throwForce, ForceMode.VelocityChange);
|
||||
}
|
||||
[Header(nameof(throwPoint))]
|
||||
[SerializeField] private Transform throwPoint;
|
||||
[SerializeField] private int throwForce;
|
||||
[SerializeField] private InputActionReference throwAction;
|
||||
[Inject] private IPlayerEquipSelector _equipSelector;
|
||||
[Inject] private IEntityEquipmentContainer _equipmentContainer;
|
||||
|
||||
[Header(Constant.Header.Animations)]
|
||||
[SerializeField] private AnimationClip drawClip;
|
||||
[SerializeField] private AnimationClip throwClip;
|
||||
private AnimancerState currentState;
|
||||
private bool isThrowing;
|
||||
public override void Entry()
|
||||
{
|
||||
base.Entry();
|
||||
isThrowing = false;
|
||||
inputActionGroup.RegisterCallback(throwAction, OnThrow);
|
||||
currentState = AnimancerComponent.Play(drawClip);
|
||||
currentState.Events.OnEnd = () =>
|
||||
{
|
||||
currentState.Events.OnEnd = null;
|
||||
if (inputActionGroup.GetAction(throwAction).IsPressed())
|
||||
{
|
||||
currentState.Events.OnEnd = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
isThrowing = true;
|
||||
currentState = AnimancerComponent.Play(throwClip);
|
||||
currentState.Events.OnEnd =()=>
|
||||
{
|
||||
currentState.Events.OnEnd = null;
|
||||
_equipSelector.Cancel();
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
private void OnThrow(InputAction.CallbackContext obj)
|
||||
{
|
||||
if (obj is not { interaction: HoldInteraction, canceled: true } || isThrowing) return;
|
||||
isThrowing = true;
|
||||
currentState = AnimancerComponent.Play(throwClip);
|
||||
currentState.Events.OnEnd =()=>
|
||||
{
|
||||
currentState.Events.OnEnd = null;
|
||||
_equipSelector.Cancel();
|
||||
};
|
||||
}
|
||||
|
||||
public override void Exit()
|
||||
{
|
||||
base.Exit();
|
||||
inputActionGroup.UnRegisterCallback(throwAction, OnThrow);
|
||||
AnimancerComponent.Stop();
|
||||
}
|
||||
public override void AnimationEvent(string eventName)
|
||||
{
|
||||
if (eventName is not BITConstant.Player.Throw) return;
|
||||
if(item.GetAssetable().TryGetProperty<EquipmentAsSlot>(out var slot) is false)return;
|
||||
if(_equipmentContainer.TryUseEquip(slot.slot) is false) return;
|
||||
Throw(throwPoint, throwForce, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user