54 lines
1.2 KiB
C#
54 lines
1.2 KiB
C#
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
|
|
// Drag Dropable
|
|
public class InventoryItem : MonoBehaviour, IPointerDownHandler, IBeginDragHandler, IEndDragHandler
|
|
{
|
|
[SerializeField] private Canvas canvas;
|
|
public GameItem GameItem;
|
|
private RectTransform _rectTransform;
|
|
private CanvasGroup canvasGroup;
|
|
|
|
private void Awake()
|
|
{
|
|
_rectTransform = GetComponent<RectTransform>();
|
|
canvasGroup = GetComponent<CanvasGroup>();
|
|
}
|
|
|
|
// Update is called once per frame
|
|
private void Update()
|
|
{
|
|
}
|
|
|
|
public void OnBeginDrag(PointerEventData eventData)
|
|
{
|
|
canvasGroup.alpha = 0.6f;
|
|
canvasGroup.blocksRaycasts = false;
|
|
}
|
|
|
|
/*public void OnDrop(PointerEventData eventData)
|
|
{
|
|
}*/
|
|
|
|
public void OnEndDrag(PointerEventData eventData)
|
|
{
|
|
canvasGroup.alpha = 1.0f;
|
|
canvasGroup.blocksRaycasts = true;
|
|
}
|
|
|
|
public void OnPointerDown(PointerEventData eventData)
|
|
{
|
|
Debug.Log("OnPointerDown");
|
|
}
|
|
|
|
public void SetItem(GameItem item)
|
|
{
|
|
GameItem = item;
|
|
}
|
|
|
|
public void OnDrag(PointerEventData eventData)
|
|
{
|
|
_rectTransform.anchoredPosition += eventData.delta / canvas.scaleFactor;
|
|
}
|
|
} |