81 lines
2.3 KiB
C#
81 lines
2.3 KiB
C#
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<WorldItem>(out var item)) return;
|
|
var _item = item.Pick();
|
|
if(item.GetAssetable().IsImprovised)
|
|
{
|
|
if (_knockdown is not null && _knockdown.IsKnockdown)
|
|
{
|
|
return;
|
|
}
|
|
if (_improvisedService.TryEquipImprovisedItem(_item))
|
|
{
|
|
item.Picked();
|
|
}
|
|
}
|
|
else if (Add(_item))
|
|
{
|
|
item.Picked();
|
|
}
|
|
}
|
|
}
|
|
#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
|
|
} |