summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/Input/XTouch.cs
blob: 25823344876aedfc03eafbbacf34483b401af79d (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using System;
using UnityEngine;
using XUpdater;
using XUtliPoolLib;

namespace XMainClient
{
	internal class XTouch : XSingleton<XTouch>
	{
		public static int MultiTouchCount = 2;

		private bool _on_screen_save = false;

		private float _screenSave = 0f;

		private XTouchItem _touches = new XTouchItem();

		public static bool PointOnUI(Vector3 point)
		{
			Ray ray = XSingleton<XGameUI>.singleton.UICamera.ScreenPointToRay(point);
			RaycastHit raycastHit;
			bool flag = Physics.Raycast(ray, out raycastHit, float.PositiveInfinity, 32);
			return flag && !raycastHit.collider.CompareTag("ChatUI");
		}

		public static bool IsActiveTouch(XTouchItem touch)
		{
			return (int) touch.Phase != 3 && (int)touch.Phase != 4;
		}

		public void Update()
		{
			XSingleton<XGesture>.singleton.ClearOneHit();
			this.UpdateTouch();
		}

		private void UpdateTouch()
		{
			int num = 0;
			while (num < Input.touchCount && num < XTouch.MultiTouchCount)
			{
				this._touches.Fake = false;
				this._touches.touch = Input.GetTouch(num);
				this.HandleTouch(this._touches);
				num++;
			}
			bool enabled = XSingleton<XKeyboard>.singleton.Enabled;
			if (enabled)
			{
				XSingleton<XKeyboard>.singleton.Update();
				for (int i = 0; i < XSingleton<XKeyboard>.singleton.touchCount; i++)
				{
					XTouchItem touchItem = XSingleton<XKeyboard>.singleton.GetTouch(i);
					Debug.Log("touch=" + touchItem);
					this.HandleTouch(touchItem);
				}
			}
			bool enabled2 = XSingleton<XSirJoystick>.singleton.Enabled;
			if (enabled2)
			{
				XSingleton<XSirJoystick>.singleton.Update();
				for (int j = 0; j < XSingleton<XSirJoystick>.singleton.touchCount; j++)
				{
					this.HandleTouch(XSingleton<XSirJoystick>.singleton.GetTouch(j));
				}
			}
			bool enabled3 = XSingleton<XGyroscope>.singleton.Enabled;
			if (enabled3)
			{
				XSingleton<XGyroscope>.singleton.Update();
				for (int k = 0; k < XSingleton<XGyroscope>.singleton.touchCount; k++)
				{
					this.HandleTouch(XSingleton<XGyroscope>.singleton.GetTouch(k));
				}
			}
			this.UpdateScreenSave();
		}

		private void UpdateScreenSave()
		{
			bool on_screen_save = this._on_screen_save;
			if (on_screen_save)
			{
				bool flag = Input.touchCount > 0;
				if (flag)
				{
					XSingleton<XUpdater.XUpdater>.singleton.XPlatform.ResetScreenLightness();
					this._on_screen_save = false;
					this._screenSave = 0f;
				}
			}
			else
			{
				bool flag2 = Input.touchCount == 0;
				if (flag2)
				{
					this._screenSave += Time.unscaledDeltaTime;
				}
				else
				{
					this._screenSave = 0f;
				}
			}
			bool flag3 = this._screenSave > XSingleton<XGlobalConfig>.singleton.ScreenSaveLimit;
			if (flag3)
			{
				this._on_screen_save = true;
				this._screenSave = 0f;
				XSingleton<XUpdater.XUpdater>.singleton.XPlatform.SetScreenLightness(XSingleton<XGlobalConfig>.singleton.ScreenSavePercentage);
			}
		}

		private void HandleTouch(XTouchItem touch)
		{
			bool flag = XTouch.PointOnUI(touch.Position);
			bool flag2 = flag;
			if (flag2)
			{
				switch (touch.Phase)
				{
				case 0:
				{
					bool fake = touch.Fake;
					if (fake)
					{
						touch.faketouch.phase =(TouchPhase) 4;
					}
					else
					{
						touch.Convert2FakeTouch((TouchPhase)4);
					}
					break;
				}
				}
			}
			XSingleton<XVirtualTab>.singleton.Feed(touch);
			XSingleton<XGesture>.singleton.Feed(touch);
		}
	}
}