1
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using BITFALL.Entities.Equipment.Melee;
|
||||
using BITFALL.Entities.Equipment.Universal.States;
|
||||
using BITFALL.Entities.Inventory;
|
||||
using BITFALL.Player.Inventory;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
@@ -13,14 +14,18 @@ using Draw = BITFALL.Entities.Equipment.Universal.States.Draw;
|
||||
|
||||
namespace BITFALL.Entities.Equipment.Universal
|
||||
{
|
||||
public interface IUseState:IState{}
|
||||
public interface IUseState : IState
|
||||
{
|
||||
}
|
||||
|
||||
public abstract class UseState : IUseState
|
||||
{
|
||||
[SerializeField] protected UniversalUseController useController;
|
||||
public virtual bool Enabled { get; set; }
|
||||
|
||||
public virtual void Initialize()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public virtual void OnStateEntry(IState old)
|
||||
@@ -38,14 +43,48 @@ namespace BITFALL.Entities.Equipment.Universal
|
||||
|
||||
public class UniversalUseController : BITEquipBase<IUseState>
|
||||
{
|
||||
[SerializeField] private IAssetableItem[] supportedItems;
|
||||
|
||||
public override bool IsSupportItem(IBasicItem _item)
|
||||
[Inject] private IPlayerInventory _playerInventory;
|
||||
[Inject] private IEntityInventory _inventory;
|
||||
[Inject] private IPlayerEquipSelector _playerEquipSelector;
|
||||
public bool IClosed { get; set; }
|
||||
public override void OnAwake()
|
||||
{
|
||||
return _item is not null && supportedItems.Any(x=>x.AddressablePath == _item.AddressablePath);
|
||||
base.OnAwake();
|
||||
animator[0].onStateEnter += (x) =>
|
||||
{
|
||||
if (IsEntered is false) return;
|
||||
switch (x)
|
||||
{
|
||||
case BITConstant.Player.Draw:
|
||||
TransitionState<Draw>();
|
||||
break;
|
||||
case BITConstant.Player.Use:
|
||||
TransitionState<Use>();
|
||||
break;
|
||||
case BITConstant.Player.Exit:
|
||||
TransitionState<Exit>();
|
||||
break;
|
||||
}
|
||||
};
|
||||
animator[0].onStateExit += x =>
|
||||
{
|
||||
if (IsEntered is false) return;
|
||||
switch (x)
|
||||
{
|
||||
case BITConstant.Player.Exit:
|
||||
IClosed = true;
|
||||
if (IsEntered)
|
||||
{
|
||||
_playerEquipSelector.Cancel();
|
||||
}
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public override void Entry()
|
||||
{
|
||||
IClosed = false;
|
||||
base.Entry();
|
||||
TransitionState<Draw>();
|
||||
}
|
||||
@@ -58,20 +97,37 @@ namespace BITFALL.Entities.Equipment.Universal
|
||||
|
||||
public override async UniTask ExitAsync()
|
||||
{
|
||||
await base.ExitAsync();
|
||||
|
||||
while (destroyCancellationToken.IsCancellationRequested is false)
|
||||
{
|
||||
if (animator[0].stateName == BITConstant.Player.Exit && animator[0].currentState.normalizedTime > 1)
|
||||
if (IClosed)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (destroyCancellationToken.IsCancellationRequested)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
await UniTask.NextFrame();
|
||||
}
|
||||
|
||||
await base.ExitAsync();
|
||||
}
|
||||
|
||||
public override void AnimationEvent(string eventName)
|
||||
{
|
||||
base.AnimationEvent(eventName);
|
||||
|
||||
switch (eventName)
|
||||
{
|
||||
case BITConstant.Player.Use when CurrentState is Use:
|
||||
if (_inventory.UseItem(Item))
|
||||
{
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user