-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLookPad.cs
47 lines (40 loc) · 1.32 KB
/
LookPad.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
namespace VeryDisco.MobileInput
{
using UnityEngine;
using UnityEngine.EventSystems;
/// <summary>
/// Lookpad mobile input
/// Author: Nhat Linh - [email protected] - Verydisco Games
/// </summary>
public class LookPad : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IDragHandler, IEndDragHandler
{
[SerializeField] private Vector2 touchInput;
private Vector2 prevDelta, dragInput;
private bool isPressed;
void Update()
{
touchInput = (dragInput - prevDelta) / Time.smoothDeltaTime;
prevDelta = dragInput;
}
public void OnPointerDown(PointerEventData eventData)
{
isPressed = true;
prevDelta = dragInput = eventData.position;
}
public void OnPointerUp(PointerEventData eventData)
{
isPressed = false;
}
public void OnDrag(PointerEventData eventData)
{
dragInput = eventData.position;
}
public void OnEndDrag(PointerEventData eventData)
{
touchInput = Vector2.zero;
isPressed = false;
}
public Vector2 LookDir => touchInput * Time.deltaTime;
public bool IsPressed => isPressed;
}
}