1
This commit is contained in:
100
Assets/Artists/Scripts/Entities/Inventory/PlayerInventory.cs
Normal file
100
Assets/Artists/Scripts/Entities/Inventory/PlayerInventory.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using BITKit;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine.UIElements;
|
||||
using System.Text;
|
||||
using BITKit.Entities;
|
||||
using System.Linq;
|
||||
using BITFALL.Entities;
|
||||
using BITFALL.Entities.Improvised;
|
||||
using BITFALL.Player.Inventory;
|
||||
using BITKit.Selection;
|
||||
|
||||
namespace BITFALL
|
||||
{
|
||||
[CustomType(typeof(IPlayerInventory))]
|
||||
public class PlayerInventory : EntityInventory,IPlayerInventory
|
||||
{
|
||||
[Inject]
|
||||
private ISelector _selector;
|
||||
[Inject(true)]
|
||||
private ImprovisedServiceInterface _improvisedService;
|
||||
[Inject(true)]
|
||||
private IKnockdown _knockdown;
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
_selector.OnActive += OnActive;
|
||||
if (_improvisedService is not null)
|
||||
{
|
||||
_improvisedService.OnUnEquipImprovisedItem += OnUnEquipImprovisedItem;
|
||||
}
|
||||
}
|
||||
private void OnUnEquipImprovisedItem(IBasicItem obj)
|
||||
{
|
||||
Drop(obj);
|
||||
}
|
||||
private void OnActive(ISelectable obj)
|
||||
{
|
||||
if (obj.Transform.TryGetComponentAny<WorldableItem>(out var item))
|
||||
{
|
||||
var _item = item.Pick();
|
||||
if(item.GetAssetable().TryGetProperty<Improvisable>(out _))
|
||||
{
|
||||
if (_knockdown is not null && _knockdown.IsKnockdown)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_improvisedService.TryEquipImprovisedItem(_item))
|
||||
{
|
||||
item.Picked();
|
||||
}
|
||||
}
|
||||
else if (Add(_item))
|
||||
{
|
||||
item.Picked();
|
||||
}
|
||||
}
|
||||
// else if(obj.Transform.TryGetComponentAny<IBasicItemContainer>(out _))
|
||||
// {
|
||||
//
|
||||
// }
|
||||
}
|
||||
public bool TryUseItem(IBasicItem item)
|
||||
{
|
||||
if (OnUseItem is null) return false;
|
||||
return OnUseItem.CastAsFunc().Any(func => func.Invoke(item)) && UseItem(item);
|
||||
}
|
||||
|
||||
public event Func<IBasicItem, bool> OnUseItem;
|
||||
public bool TryUseItemCustom(IBasicItem item)
|
||||
{
|
||||
return OnUseItemCustom is not null && OnUseItemCustom.CastAsFunc().Any(func => func.Invoke(item));
|
||||
}
|
||||
|
||||
public event Func<IBasicItem, bool> OnUseItemCustom;
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.CustomEditor(typeof(PlayerInventory))]
|
||||
public class EntityPlayerInventoryInsepctor : BITInspector<PlayerInventory>
|
||||
{
|
||||
public override VisualElement CreateInspectorGUI()
|
||||
{
|
||||
FillDefaultInspector();
|
||||
CreateSubTitle(Constant.Header.Debug);
|
||||
var serializeLabel = root.Create<Label>();
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
foreach (var x in agent.GetItems())
|
||||
{
|
||||
stringBuilder.AppendLine($"{x.Id}@{x.Name}");
|
||||
}
|
||||
serializeLabel.text=stringBuilder.ToString();
|
||||
return root;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
Reference in New Issue
Block a user