BITFALL/Assets/Artists/Scripts/Entities/Inventory/PlayerInventory.cs

81 lines
2.3 KiB
C#
Raw Normal View History

2023-10-20 19:31:12 +08:00
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)
{
2023-11-15 23:54:54 +08:00
if (!obj.Transform.TryGetComponent<WorldItem>(out var item)) return;
2023-10-24 23:37:59 +08:00
var _item = item.Pick();
2023-10-29 15:27:13 +08:00
if(item.GetAssetable().IsImprovised)
2023-10-20 19:31:12 +08:00
{
2023-10-24 23:37:59 +08:00
if (_knockdown is not null && _knockdown.IsKnockdown)
2023-10-20 19:31:12 +08:00
{
2023-10-24 23:37:59 +08:00
return;
2023-10-20 19:31:12 +08:00
}
2023-10-24 23:37:59 +08:00
if (_improvisedService.TryEquipImprovisedItem(_item))
2023-10-20 19:31:12 +08:00
{
item.Picked();
}
}
2023-10-24 23:37:59 +08:00
else if (Add(_item))
{
item.Picked();
}
2023-10-20 19:31:12 +08:00
}
}
#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
}