BITFALL/Assets/Artists/Scripts/Equip/UniversalUseControllerState.cs

82 lines
2.3 KiB
C#
Raw Normal View History

2023-10-20 22:46:14 +08:00
using System;
2023-10-20 19:31:12 +08:00
using System.Collections;
using System.Collections.Generic;
2024-03-22 20:16:32 +08:00
using BITKit;
2023-10-20 22:46:14 +08:00
using BITKit.StateMachine;
2024-03-29 00:58:24 +08:00
using BITKit.UX;
2023-10-20 19:31:12 +08:00
using UnityEngine;
namespace BITFALL.Entities.Equipment.Universal.States
{
2023-10-20 22:46:14 +08:00
[Serializable]
2023-10-20 19:31:12 +08:00
public sealed class Draw:UseState
{
2024-03-22 20:16:32 +08:00
protected override void OnPlayEnd()
{
base.OnPlayEnd();
useController.TransitionState<Use>();
}
2023-10-20 19:31:12 +08:00
}
2023-10-20 22:46:14 +08:00
[Serializable]
2023-10-20 19:31:12 +08:00
public sealed class Use:UseState
{
2024-03-29 00:58:24 +08:00
public override void OnStateEntry(IState old)
{
base.OnStateEntry(old);
useController._equipmentContainer.OnEquip+=OnEquip;
}
public override void OnStateExit(IState old, IState newState)
{
base.OnStateExit(old, newState);
useController._equipmentContainer.OnEquip-=OnEquip;
}
2024-03-22 20:16:32 +08:00
protected override void OnPlayEnd()
{
base.OnPlayEnd();
2024-03-29 00:58:24 +08:00
//useController.TransitionState<Exit>();
if (useController.Release)
useController._playerEquipSelector.Cancel();
else
{
try
{
if (useController.Item is not null
&& useController.Inventory.AllowUseItem(useController.Item)
)
{
currentState.Events.OnEnd = null;
currentState.Stop();
PlayAnimation();
//animancerComponent.States.Current.Time = 0;
}
else
{
useController._playerEquipSelector.Cancel();
}
}
catch (InGameException e)
{
useController.UXPopup.Popup(e.Message);
useController._playerEquipSelector.Cancel();
}
}
}
private void OnEquip(IEquipmentSlot arg1, IBasicItem arg2)
{
if (useController.ScriptableItem.AddressablePath != arg2?.AddressablePath) return;
useController.Item = arg2;
2024-03-22 20:16:32 +08:00
}
2023-10-20 19:31:12 +08:00
}
2023-10-20 22:46:14 +08:00
[Serializable]
2023-10-20 19:31:12 +08:00
public sealed class Exit:UseState
{
2024-03-22 20:16:32 +08:00
protected override void OnPlayEnd()
{
base.OnPlayEnd();
animancerComponent.Stop();
}
2023-10-20 19:31:12 +08:00
}
}