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

@@ -27,7 +27,8 @@
"GUID:96f476e982d6fb945bfc9140ba094b7f",
"GUID:ef0bb553b58b90b488bdbe8672e3be0b",
"GUID:045a42f233e479d41adc32d02b99631e",
"GUID:1235ca61e7f433b408ed5a68767e7123"
"GUID:1235ca61e7f433b408ed5a68767e7123",
"GUID:c0b9c98c59e49554c8f4ca6dc4998d79"
],
"includePlatforms": [],
"excludePlatforms": [],

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using BITFALL.Entities.Armor;
using BITFALL.Player.Equip;
using BITFALL.Player.Movement;
using UnityEngine;
@@ -34,6 +35,7 @@ namespace BITFALL.UX
[SerializeField] private UXBar healthBar;
[SerializeField] private UXBar lerpHealthBar;
[SerializeField] private UXBar staminaBar;
[SerializeField] private UXBar armorBar;
[Header(Constant.Header.Input)]
public InputActionReference inventoryAction;
@@ -50,6 +52,8 @@ namespace BITFALL.UX
private IEquipService _equipService;
[Inject]
private ISelector _selector;
[Inject]
private IArmor _armor;
private float _currentHealthLerp;
protected override void Awake()
{
@@ -99,6 +103,14 @@ namespace BITFALL.UX
_selector.OnInactive += OnInactive;
_selector.OnSelected += OnSelect;
_armor.OnArmorChanged += x => armorBar.Set(x);
_armor.OnEquipArmor += x =>
{
armorBar.Set(_armor.Armor);
armorBar.SetActive(true);
};
_armor.OnUnEquipArmor += x => armorBar.SetActive(false);
if (steamService.IsInitialized)
{
playerNameLabel.Set(steamService.Name);
@@ -108,6 +120,8 @@ namespace BITFALL.UX
_equipService = entity.Get<IEquipService>();
armorBar.SetActive(_armor.TryGetCurrentArmor(out _));
OnSetHP(_health.HealthPoint);
OnSetAlive(_health.IsAlive);

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;