using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using TMPro; using UnityEngine.UI; public class BagItem : LogicElementHolder { #region Inspector Elements [SerializeField] private Transform LogicElementLocation; [SerializeField] private LogicElementUI LogicElementPrefab; #endregion Inspector Elements #region Private Variables private int Count; protected Inventory.Data InventoryData; //private TextMeshProUGUI CountText; private Text CountText1; #endregion Private Variables #region Read Only #endregion Read Only #region Class Functionality public void Initialise(Inventory.Data data) { InventoryData = data; if (CountText1 == null) CountText1 = GetComponentInChildren(); Count = data.Count; LogicElementUI logicElement = Instantiate(LogicElementPrefab.gameObject, LogicElementLocation).GetComponent(); logicElement.Initialise(data.element, this); UpdateUI(); } public void UpdateUI() { if (!InventoryData.isInfinit) CountText1.text = Count.ToString(); else CountText1.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.isInfinit) 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.isInfinit && Count > 0) Count--; else if (!InventoryData.isInfinit) Destroy(element.gameObject); LogicElementUI logicElement = Instantiate(LogicElementPrefab.gameObject, LogicElementLocation).GetComponent(); logicElement.Initialise(InventoryData.element, this); UpdateUI(); } /// /// Called to check if this holder can hold the provided element; /// /// element to check if it can hold /// returns true if this can hold the element public override bool canHold(LogicBlock element) { return element.isSameType(InventoryData.element); } /// /// Called when an element in this holder is double clicked /// /// element which was double clicked public override void OnDoubleClick(LogicElementUI element) { } #endregion LogicElementHolder Implementation }