重做物品系统

This commit is contained in:
MuHua-123
2025-10-11 17:02:18 +08:00
parent dd690d871c
commit 21b7cbcef5
145 changed files with 1177 additions and 2219 deletions
@@ -0,0 +1,38 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
using MuHua;
/// <summary>
/// UI库存
/// </summary>
public class UIInventory : ModuleUIPanel {
public Inventory inventory;
public ModuleUIItems<UIInventorySlot, InventorySlot> items;
public VisualElement Container => Q<VisualElement>("Container");
public UIInventory(VisualElement element, VisualTreeAsset templateAsset) : base(element) {
items = new ModuleUIItems<UIInventorySlot, InventorySlot>(Container, templateAsset,
(data, element) => new UIInventorySlot(data, element));
}
public void Dispose() {
items.Release();
if (inventory == null) { return; }
inventory.OnChange -= Inventory_OnChange;
}
public void Settings(Inventory inventory) {
if (this.inventory != null) { Dispose(); }
this.inventory = inventory;
if (inventory == null) { return; }
items.Create(inventory.slots);
inventory.OnChange += Inventory_OnChange;
}
private void Inventory_OnChange(Inventory inventory) {
items.Create(inventory.slots);
}
}