Files
harvestdale-unity/Assets/Scripts/UI/DraggableSlotContentUI.cs
2023-02-22 13:39:32 +01:00

34 lines
876 B
C#

using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class DraggableSlotContentUI : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
{
public int slotIndex;
[HideInInspector] public Transform parentAfterDrag;
public Image image;
public void OnBeginDrag(PointerEventData eventData)
{
Debug.Log("Start Drag");
parentAfterDrag = transform.parent;
transform.SetParent(transform.root);
transform.SetAsLastSibling();
image.raycastTarget = false;
}
public void OnDrag(PointerEventData eventData)
{
Debug.Log("Dragging");
transform.position = Input.mousePosition;
}
public void OnEndDrag(PointerEventData eventData)
{
Debug.Log("End drag");
transform.SetParent(parentAfterDrag);
image.raycastTarget = true;
// invoke
Inventory.OnPlayerInventoryChanged?.Invoke();
}
}