summaryrefslogtreecommitdiff
path: root/Thronefall_1_57/Decompile/Rewired.Demos/TouchButtonExample.cs
blob: af6edad932a4c087807499c3465e0f38c29e64a5 (plain)
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
48
49
50
51
52
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace Rewired.Demos;

[AddComponentMenu("")]
[RequireComponent(typeof(Image))]
public class TouchButtonExample : MonoBehaviour, IPointerDownHandler, IEventSystemHandler, IPointerUpHandler
{
	public bool allowMouseControl = true;

	public bool isPressed { get; private set; }

	private void Awake()
	{
		if (SystemInfo.deviceType == DeviceType.Handheld)
		{
			allowMouseControl = false;
		}
	}

	private void Restart()
	{
		isPressed = false;
	}

	void IPointerDownHandler.OnPointerDown(PointerEventData eventData)
	{
		if (allowMouseControl || !IsMousePointerId(eventData.pointerId))
		{
			isPressed = true;
		}
	}

	void IPointerUpHandler.OnPointerUp(PointerEventData eventData)
	{
		if (allowMouseControl || !IsMousePointerId(eventData.pointerId))
		{
			isPressed = false;
		}
	}

	private static bool IsMousePointerId(int id)
	{
		if (id != -1 && id != -2)
		{
			return id == -3;
		}
		return true;
	}
}