Files
beyond/Assets/Scripts/Input/WaveTouchController.cs
2024-11-20 15:21:28 +01:00

57 lines
1.8 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
namespace Beyond
{
public class WaveTouchController : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IDragHandler
{
private Vector2 m_startPoint;
private Vector2 m_currentPoint;
private Vector2 m_normalizedPos;
private RectTransform m_rect;
public UnityEvent<Vector2> OnChange;
void UpdatePos()
{
}
public void OnDrag(PointerEventData eventData)
{
RectTransformUtility.ScreenPointToLocalPointInRectangle(m_rect, eventData.position, eventData.pressEventCamera, out m_currentPoint);
m_normalizedPos = 2f * m_currentPoint / m_rect.rect.size;
Debug.Log($"Current pos: {m_normalizedPos}");
OnChange.Invoke(m_normalizedPos);
}
public void OnPointerDown(PointerEventData eventData)
{
RectTransformUtility.ScreenPointToLocalPointInRectangle(m_rect, eventData.position, eventData.pressEventCamera, out m_currentPoint);
m_startPoint = m_currentPoint;
m_normalizedPos = 2f * m_currentPoint / m_rect.rect.size;
Debug.Log($"Current pos: {m_normalizedPos}");
OnChange.Invoke(m_normalizedPos);
}
public void OnPointerUp(PointerEventData eventData)
{
RectTransformUtility.ScreenPointToLocalPointInRectangle(m_rect, eventData.position, eventData.pressEventCamera, out m_currentPoint);
}
// Start is called before the first frame update
void Start()
{
m_rect = GetComponent<RectTransform>();
}
// Update is called once per frame
void Update()
{
}
}
}