This commit is contained in:
CortexCore
2023-10-20 22:46:14 +08:00
parent a160813262
commit 325f63d6bc
42 changed files with 1602 additions and 79 deletions

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using BITFALL.Entities.Equipment;
using BITFALL.Player.Inventory;
using UnityEngine;
using UnityEngine.UIElements;
@@ -36,7 +37,7 @@ namespace BITFALL.UX
[Inject]
private IPlayerInventory _playerInventory;
[Inject]
private IPlayerEquipContainer equipContainer;
private IEntityEquipmentContainer equipContainer;
private IEntity _entity;
protected override async void Awake()
{
@@ -73,26 +74,36 @@ namespace BITFALL.UX
{
base.OnEnable();
playerService.OnPlayerInitialized += OnPlayerInitializedLocalPlayer;
playerService.OnPlayerDisposed += OnPlayerDisposed;
}
private void OnPlayerDisposed(Entity obj)
{
inventory = null;
equipContainer = null;
_playerInventory = null;
}
protected override void OnDisable()
{
base.OnDisable();
playerService.OnPlayerDisposed -= OnPlayerDisposed;
playerService.OnPlayerInitialized -= OnPlayerInitializedLocalPlayer;
}
private void OnPlayerInitializedLocalPlayer(IEntity entity)
{
entity.Inject(this);
itemContainers.Clear();
equipContainers.Clear();
builder.Clear();
var weighted = entity.Get<IPlayerInventoryWeightable>();
weighted.OnWeighted += OnWeighted;
equipContainer = entity.Get<IPlayerEquipContainer>();
equipContainer.OnEquip += OnEquip;
equipContainer.OnDeEquip += DeEquip;
inventory = entity.Get<IBasicItemContainer>();
inventory.OnAdd += OnAdd;
inventory.OnRemove += OnRemove;