using System; using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; using UnityEngine.Events; namespace Kryz.CharacterStats.Examples { public class ItemSlot : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler { [SerializeField] protected Image image; public UnityEvent_ItemInstance OnRightClickEvent = new UnityEvent_ItemInstance(); protected ItemInstance _item; public ItemInstance Item { get { return _item; } set { _item = value; if (_item == null) { image.enabled = false; } else if (_item.Icon == null) { image.enabled = false; } else { Debug.Log("Item Slot: " + _item); Debug.Log("Item Slot: " + _item.Icon); Debug.Log("Item Slot: " + _item.templateIndex); Debug.Log("Item Slot: " + ItemIndexer.Instance.Items[_item.templateIndex].ItemName); image.sprite = _item.Icon; image.enabled = true; } } } public void OnPointerClick(PointerEventData eventData) { if (eventData != null && eventData.button == PointerEventData.InputButton.Right) { //Debug.LogError("PointerClick"); //Debug.LogError(Item); //Debug.LogError(OnRightClickEvent); if (Item != null && OnRightClickEvent != null) { OnRightClickEvent.Invoke(Item); //Debug.LogError("right click: " + Item.ItemName); } } } protected virtual void OnValidate() { if (image == null) image = GetComponent(); } public virtual void OnPointerEnter(PointerEventData eventData) { ItemTooltip.Instance.ShowTooltip(Item); if (Item is EquippableItemInstance ei) { EquippableItemInstance equippedInSameSlot = EquipmentPanel.Instance.GetEquippedItemOnSpecificSlot(ei.EquipmentType); if (equippedInSameSlot != null && !string.IsNullOrEmpty(equippedInSameSlot.ItemName)) { EquippedItemTooltip.Instance.ShowTooltip(equippedInSameSlot); } } } public void OnPointerExit(PointerEventData eventData) { ItemTooltip.Instance.HideTooltip(); EquippedItemTooltip.Instance.HideTooltip(); } } }