You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

98 lines
2.5 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using TMPro;
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;
#endregion Private Variables
#region Class Functionality
public void Initialise(Inventory.Data data)
{
InventoryData = data;
if (CountText == null)
CountText = GetComponentInChildren<TextMeshProUGUI>();
Count = data.Count;
LogicElementUI logicElement = Instantiate(LogicElementPrefab.gameObject, LogicElementLocation).GetComponent<LogicElementUI>();
logicElement.Initialise(data.element, this);
UpdateUI();
}
public void UpdateUI()
{
if (!InventoryData.isInfinit)
CountText.text = Count.ToString();
else
CountText.text = "∞";
}
#endregion Class Functionality
#region LogicElementHolder Implementation
/// <summary>
/// When a logicElement needs to be added back to this holder
/// </summary>
/// <param name="element">Element which is being Added</param>
public override void OnAdd(LogicElementUI element)
{
Destroy(element.gameObject);
if (!InventoryData.isInfinit)
Count++;
UpdateUI();
}
/// <summary>
/// When a LogicElement has started being dragged from this holder
/// </summary>
/// <param name="element">Element which is being dragged</param>
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<LogicElementUI>();
logicElement.Initialise(InventoryData.element, this);
UpdateUI();
}
/// <summary>
/// Called when an element in this holder is double clicked
/// </summary>
/// <param name="element">element which was double clicked</param>
public override void OnDoubleClick(LogicElementUI element)
{
}
#endregion LogicElementHolder Implementation
}