48 lines
1.2 KiB
C#
48 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BITFALL.Entities.Inventory;
|
|
using BITFALL.Placement;
|
|
using BITKit;
|
|
using BITKit.Entities;
|
|
using BITKit.StateMachine;
|
|
using UnityEngine;
|
|
|
|
namespace BITFALL.Player.Equip
|
|
{
|
|
public interface IPlacingState:IState{}
|
|
public class PlacingController : BITEquipBase<IPlacingState>
|
|
{
|
|
internal AssetablePlacement _placement => item as AssetablePlacement;
|
|
|
|
[SerializeField] private Vector3 offset;
|
|
|
|
[Inject] private IEntityInventory _inventory;
|
|
[Inject] private IEntityMovement _movement;
|
|
[Inject] private IPlayerEquipSelector _equipSelector;
|
|
|
|
public override void OnAwake()
|
|
{
|
|
base.OnAwake();
|
|
animator[0].onStateExit += OnStateExit;
|
|
}
|
|
|
|
private void OnStateExit(string obj)
|
|
{
|
|
if (IsEntered is false || obj is not BITConstant.Player.Use) return;
|
|
if (!_inventory.Remove(Item)) return;
|
|
var instance = _placement.CreateInstance() as MonoBehaviour;
|
|
instance!.transform.SetPositionAndRotation(_movement.Position + _movement.Rotation * offset, _movement.Rotation);
|
|
|
|
_equipSelector.Cancel();
|
|
}
|
|
|
|
public override void Entry()
|
|
{
|
|
base.Entry();
|
|
animator.Play(BITConstant.Player.Draw);
|
|
}
|
|
}
|
|
|
|
}
|
|
|