1
This commit is contained in:
@@ -10,7 +10,7 @@ using UnityEngine.AddressableAssets;
|
||||
|
||||
namespace BITFALL.UX
|
||||
{
|
||||
public class UXInventory : UIToolKitPanel,IWeightedCallback,IPlayerEquipCallback
|
||||
public class UXInventory : UIToolKitPanel
|
||||
{
|
||||
[Header(Constant.Header.Input)]
|
||||
public InputActionReference inventoryAction;
|
||||
@@ -76,10 +76,14 @@ namespace BITFALL.UX
|
||||
}
|
||||
private void OnPlayerInitializedLocalPlayer(IEntity entity)
|
||||
{
|
||||
entity.RegisterCallback<IWeightedCallback>(this);
|
||||
entity.RegisterCallback<IPlayerEquipCallback>(this);
|
||||
inventory = entity.Get<IBasicItemContainer>();
|
||||
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;
|
||||
@@ -98,13 +102,14 @@ namespace BITFALL.UX
|
||||
UXService.Entry<UXHud>();
|
||||
}
|
||||
|
||||
public void OnWeighted(float current, float max)
|
||||
public void OnWeighted(double current, double max)
|
||||
{
|
||||
weightBar.SetDirect( current is 0 ? 0 :(current / max).Fix(),$"{current}/{max}");
|
||||
var value = current is 0 ? 0 : (current / max);
|
||||
weightBar.SetDirect((float) value,$"{current}/{max}");
|
||||
}
|
||||
private void OnAdd(IBasicItem item)
|
||||
{
|
||||
var asset = Addressables.LoadAssetAsync<AssetableItem>(item.AdressablePath).WaitForCompletion();
|
||||
var asset = Addressables.LoadAssetAsync<AssetableItem>(item.AddressablePath).WaitForCompletion();
|
||||
var uxContainer = builder.BuildAsContainer();
|
||||
uxContainer.icon.style.backgroundImage = asset.SquareIcon;
|
||||
uxContainer.contextLabel.text = asset.Name;
|
||||
@@ -141,28 +146,23 @@ namespace BITFALL.UX
|
||||
}
|
||||
private void UseItem(IBasicItem item)
|
||||
{
|
||||
_entity.Get<IRequestor<IBasicItem>>().Excute(item);
|
||||
_entity.Get<TaskPublisher<IBasicItem>>().Execute(item);
|
||||
}
|
||||
private void DropItem(IBasicItem item)
|
||||
{
|
||||
inventory.Drop(item.Id);
|
||||
}
|
||||
void IPlayerEquipCallback.OnEquip(IEquipmentSlot slot, IBasicItem item)
|
||||
private void OnEquip(IEquipmentSlot slot, IBasicItem item)
|
||||
{
|
||||
var asset = item.GetAssetable();
|
||||
if (equipContainers.TryGetValue(slot.GetType().Name, out var container))
|
||||
{
|
||||
container.icon.style.backgroundImage = asset.SquareIcon;
|
||||
BIT4Log.Log<UXInventory>($"已装备:{item.Name}@{slot.GetType().Name}");
|
||||
}
|
||||
if (!equipContainers.TryGetValue(slot.GetType().Name, out var container)) return;
|
||||
container.icon.style.backgroundImage = asset.SquareIcon;
|
||||
BIT4Log.Log<UXInventory>($"已装备:{item.Name}@{slot.GetType().Name}");
|
||||
}
|
||||
|
||||
void IPlayerEquipCallback.DeEquip(IEquipmentSlot slot, IBasicItem item)
|
||||
private void DeEquip(IEquipmentSlot slot, IBasicItem item)
|
||||
{
|
||||
if(equipContainers.TryGetValue(slot.GetType().Name,out var container))
|
||||
{
|
||||
container.icon.style.backgroundImage = null;
|
||||
}
|
||||
if (!equipContainers.TryGetValue(slot.GetType().Name, out var container)) return;
|
||||
container.icon.style.backgroundImage = null;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user