using System.Collections.Generic; using Lean.Pool; using Michsky.UI.Heat; using UFS3; using UnityEngine; public class UI_InventoryList : MonoBehaviour { public ItemType ItemType; public ScriptableListItemData InventoryList; public ScriptableEventItemData OnRemoveAssignItem; [SerializeField] private UI_InventoryButton InventoryButtonTemplate; [SerializeField] private ButtonManager noItemButton; [SerializeField] private PanelManager mainContent; private List _ButtonInstances; public RectTransform buttonParent; private void OnEnable() { Refresh(); InventoryList.OnItemCountChanged += InventoryList_OnItemCountChanged; } private void InventoryList_OnItemCountChanged() { Clear(); Refresh(); } public void OnNoItemButtonClick() { if (!(mainContent == null)) { int index = mainContent.panels.FindIndex((PanelManager.PanelItem element) => element.panelName == "Shop"); PanelManager componentInChildren = mainContent.panels[index].panelObject.GetComponentInChildren(); mainContent.OpenPanel("Shop"); switch (ItemType) { case ItemType.Rod: componentInChildren.OpenPanel("Rods"); break; case ItemType.Reel: componentInChildren.OpenPanel("Reels"); break; case ItemType.Line: componentInChildren.OpenPanel("Lines"); break; case ItemType.Bobber: componentInChildren.OpenPanel("Bobbers"); break; case ItemType.Hook: componentInChildren.OpenPanel("Hooks"); break; case ItemType.Lure: componentInChildren.OpenPanel("Lures"); break; case ItemType.Bait: componentInChildren.OpenPanel("Baits"); break; } } } private void OnRemoveAssignItemOnOnRaised(BaseItemData obj) { Clear(); Refresh(); } private void OnDisable() { Clear(); InventoryList.OnItemCountChanged -= InventoryList_OnItemCountChanged; } private void Refresh() { _ButtonInstances = new List(); foreach (BaseItemData inventory in InventoryList) { ItemType itemType = ((IItemType)inventory).ItemType; if (itemType == ItemType) { UI_InventoryButton uI_InventoryButton = LeanPool.Spawn(InventoryButtonTemplate, buttonParent); uI_InventoryButton.Initialize(inventory, itemType); _ButtonInstances.Add(uI_InventoryButton); uI_InventoryButton.gameObject.SetActive(value: true); } } noItemButton.gameObject.SetActive(_ButtonInstances.Count == 0); } private void Clear() { foreach (UI_InventoryButton buttonInstance in _ButtonInstances) { if (buttonInstance != null) { LeanPool.Despawn(buttonInstance); } } _ButtonInstances.Clear(); } }