summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/ScreenJoystick.cs
blob: f787ea3fcc10745315c967edc6cb6f854ef12d79 (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
53
54
using System;
using UnityEngine;

public class ScreenJoystick : MonoBehaviour, IVirtualJoystick
{
	public Vector2 Delta { get; private set; }

	private Collider2D[] hitBuffer = new Collider2D[20];

	private Controller myController = new Controller();

	private int touchId = -1;

	private void FixedUpdate()
	{
		this.myController.Update();
		if (this.touchId <= -1)
		{
			for (int i = 0; i < this.myController.Touches.Length; i++)
			{
				Controller.TouchState touchState = this.myController.Touches[i];
				if (touchState.TouchStart)
				{
					bool flag = false;
					int num = Physics2D.OverlapPointNonAlloc(touchState.Position, this.hitBuffer, Constants.NotShipMask);
					for (int j = 0; j < num; j++)
					{
						Collider2D collider2D = this.hitBuffer[j];
						if (collider2D.GetComponent<ButtonBehavior>() || collider2D.GetComponent<PassiveButton>())
						{
							flag = true;
							break;
						}
					}
					if (!flag)
					{
						this.touchId = i;
						return;
					}
				}
			}
			return;
		}
		Controller.TouchState touchState2 = this.myController.Touches[this.touchId];
		if (touchState2.IsDown)
		{
			Vector2 b = Camera.main.ViewportToWorldPoint(new Vector2(0.5f, 0.5f));
			this.Delta = (touchState2.Position - b).normalized;
			return;
		}
		this.touchId = -1;
		this.Delta = Vector2.zero;
	}
}