mirror of
https://github.com/DerTyp7/harvestdale-unity.git
synced 2025-10-29 20:52:10 +01:00
draggable items
This commit is contained in:
34
Assets/Scripts/UI/DraggableSlotContentUI.cs
Normal file
34
Assets/Scripts/UI/DraggableSlotContentUI.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user