using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using TMPro; public class BagItem : LogicElementHolder { #region Inspector Elements [SerializeField] private LogicElementUI LogicElementPrefab; [SerializeField] private Transform LogicElementLocation; #endregion Inspector Elements #region Private Variables private int Count; protected Inventory.Data InventoryData; private TextMeshProUGUI CountText; #endregion Private Variables #region Class Functionality public void Initialise(Inventory.Data data) { InventoryData = data; if (CountText == null) CountText = GetComponentInChildren(); Count = data.Count; LogicElementUI logicElement = Instantiate(LogicElementPrefab.gameObject, LogicElementLocation).GetComponent(); logicElement.Initialise(data.element, this); UpdateUI(); } public void UpdateUI() { if (!InventoryData.infinit) CountText.text = Count.ToString(); else CountText.text = "∞"; } #endregion Class Functionality #region LogicElementHolder Implementation /// /// When a logicElement needs to be added back to this holder /// /// Element which is being Added public override void OnAdd(LogicElementUI element) { Destroy(element.gameObject); if (!InventoryData.infinit) Count++; UpdateUI(); } /// /// When a LogicElement has started being dragged from this holder /// /// Element which is being dragged public override void OnRemove(LogicElementUI element) { if (!InventoryData.infinit && Count > 0) Count--; else if (!InventoryData.infinit) Destroy(element.gameObject); LogicElementUI logicElement = Instantiate(LogicElementPrefab.gameObject, LogicElementLocation).GetComponent(); logicElement.Initialise(InventoryData.element, this); UpdateUI(); } #endregion LogicElementHolder Implementation }