the initial commit to the repo.
This commit is contained in:
parent
025c032b8c
commit
1b757591b9
264 changed files with 21882 additions and 0 deletions
42
stoopid.raw/Draggable.cs
Normal file
42
stoopid.raw/Draggable.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class Draggable : MonoBehaviour, IPointerDownHandler, IEventSystemHandler, IDragHandler
|
||||
{
|
||||
private RectTransform rectTransform;
|
||||
|
||||
private CanvasGroup canvasGroup;
|
||||
|
||||
private Vector2 offset;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
rectTransform = GetComponent<RectTransform>();
|
||||
canvasGroup = GetComponent<CanvasGroup>();
|
||||
}
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, eventData.position, eventData.pressEventCamera, out offset);
|
||||
}
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
if (canvasGroup != null)
|
||||
{
|
||||
canvasGroup.blocksRaycasts = false;
|
||||
}
|
||||
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, eventData.position, eventData.pressEventCamera, out var localPoint))
|
||||
{
|
||||
rectTransform.anchoredPosition += localPoint - offset;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnEndDrag(PointerEventData eventData)
|
||||
{
|
||||
if (canvasGroup != null)
|
||||
{
|
||||
canvasGroup.blocksRaycasts = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue