summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/Input/XVirtualTab.cs
blob: c68068e731d054fc2b16ddeb22ae207464bc8077 (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
using System;
using UnityEngine;
using XMainClient.UI.UICommon;
using XUpdater;
using XUtliPoolLib;

namespace XMainClient
{
	internal class XVirtualTab : XSingleton<XVirtualTab>
	{
		public int FingerId
		{
			get
			{
				return this._finger_id;
			}
		}

		public bool Freezed
		{
			get
			{
				return this._bFreeze;
			}
			set
			{
				this._bFreeze = value;
				this.Cancel();
			}
		}

		public bool Feeding
		{
			get
			{
				return this._bFeeding && !this._bFreeze;
			}
		}

		public float DeadZone
		{
			get
			{
				return this._dead_zone;
			}
		}

		public float MaxDistance
		{
			get
			{
				return this._max_distance;
			}
		}

		public Vector3 Direction
		{
			get
			{
				bool flag = XSingleton<XEntityMgr>.singleton.Player != null && XSingleton<XEntityMgr>.singleton.Player.Buffs.IsBuffStateOn(XBuffType.XBuffType_Puzzled);
				Vector3 result;
				if (flag)
				{
					result = XSingleton<XCommon>.singleton.HorizontalRotateVetor3(this._direction, (float)XSingleton<XEntityMgr>.singleton.Player.Buffs.GetStateParam(XBuffType.XBuffType_Puzzled), true);
				}
				else
				{
					result = this._direction;
				}
				return result;
			}
		}

		public float CentrifugalFactor
		{
			get
			{
				return this._velocity;
			}
		}

		private readonly float _dead_zone = 15f;

		private int _finger_id = -1;

		private bool _bTouch = false;

		private bool _bFeeding = false;

		private bool _bFreeze = false;

		private float _max_distance = 75f;

		private float _velocity = 0f;

		private float _outer_radius = 0f;

		private float _inner_radius = 0f;

		private Vector3 _direction = Vector3.zero;

		private Vector2 _center = Vector2.zero;

		private Vector2 _rocker_center = Vector2.zero;

		private Vector2 _tab_dir = Vector2.up;

		public void OnEnterScene()
		{
			this._outer_radius = DlgBase<VirtualJoystick, VirtualJoystickBehaviour>.singleton.GetPanelRadius();
			this._inner_radius = DlgBase<VirtualJoystick, VirtualJoystickBehaviour>.singleton.GetJoystickRadius();
			this._max_distance = (XSingleton<XUpdater.XUpdater>.singleton.EditorMode ? 125f : (this._outer_radius + this._inner_radius));
			this.Cancel();
			this._bFreeze = false;
		}

		public void Feed(XTouchItem touch)
		{
			bool newly = this._finger_id == -1 && touch.FingerId != XSingleton<XGesture>.singleton.FingerId;
			bool keep = this._finger_id == touch.FingerId;
			bool flag = !this._bFreeze && (newly || keep);
			Debug.Log("newly=" + newly + ", keep=" + keep);
			if (flag)
			{
				bool bFeeding = this._bFeeding;
				if (bFeeding)
				{
					bool flag2 = XTouch.IsActiveTouch(touch);
					if (flag2)
					{
						this.CalcMove(touch, false);
					}
					else
					{
						this.Cancel();
					}
				}
				else
				{
					bool bTouch = this._bTouch;
					if (bTouch)
					{
						bool flag3 = XTouch.IsActiveTouch(touch);
						if (flag3)
						{
							//bool flag4 = (touch.Position - this._center).sqrMagnitude > this._dead_zone * this._dead_zone;
							//if (flag4)
							//{
								this._bFeeding = true;
								this.CalcMove(touch, true);
							//}
						}
						else
						{
							this.Cancel();
						}
					}
					else
					{
						// 这里会导致没法使用虚拟摇杆
						//bool flag5 = touch.Phase == null && touch.Position.x < (float)Screen.width * 0.5f;
						bool flag5 = touch.Phase == TouchPhase.Began && touch.Position.x < (float)Screen.width * 0.5f;
						if (flag5)
						{
							this._bTouch = true;
							this._center = new Vector2(touch.Position.x, touch.Position.y);
							this._finger_id = touch.FingerId;
							Debug.Log( "touch center = " + this._center);
						}
					}
				}
			}
		}

		public void Cancel()
		{
			bool bTouch = this._bTouch;
			if (bTouch)
			{
				this._bTouch = false;
				this._bFeeding = false;
				this._center = Vector2.zero;
				this._finger_id = -1;
				DlgBase<VirtualJoystick, VirtualJoystickBehaviour>.singleton.ShowPanel(false, default(Vector2));
			}
		}

		private void CalcMove(XTouchItem touch, bool newly)
		{
			//c 这里把两个this.TabCulling()注释掉了

			//this.TabCulling();
			Vector2 vector = touch.Position - this._center;
			bool flag = !newly && XSingleton<XUpdater.XUpdater>.singleton.EditorMode && touch.FingerId == 1;
			if (flag)
			{
				float num = 480f * Time.deltaTime;
				float num2 = Vector2.Angle(this._tab_dir, vector);
				bool flag2 = num2 > num;
				if (flag2)
				{
					bool flag3 = XSingleton<XCommon>.singleton.Clockwise(this._tab_dir, vector);
					this._tab_dir = XSingleton<XCommon>.singleton.HorizontalRotateVetor2(this._tab_dir, flag3 ? num : (-num), false);
					bool flag4 = XSingleton<XCommon>.singleton.Clockwise(this._tab_dir, vector);
					bool flag5 = flag3 != flag4;
					if (flag5)
					{
						this._tab_dir = vector;
					}
				}
				else
				{
					this._tab_dir = vector;
				}
			}
			else
			{
				this._tab_dir = vector;
			}
			float num3 = this._tab_dir.magnitude;
			bool flag6 = num3 > this._max_distance;
			if (flag6)
			{
				num3 = this._max_distance;
				//this.TabCulling();
			}
			this._velocity = 1f;
			float num4 = Vector2.Angle(Vector2.up, this._tab_dir);
			bool flag7 = XSingleton<XCommon>.singleton.Clockwise(Vector2.up, this._tab_dir);
			bool flag8 = XSingleton<XScene>.singleton.GameCamera == null || XSingleton<XScene>.singleton.GameCamera.CameraTrans == null;
			if (!flag8)
			{
				Vector3 forward = XSingleton<XScene>.singleton.GameCamera.CameraTrans.forward;
				forward.y = 0f;
				forward.Normalize();
				this._direction = XSingleton<XCommon>.singleton.HorizontalRotateVetor3(forward, flag7 ? num4 : (-num4), true);
				DlgBase<VirtualJoystick, VirtualJoystickBehaviour>.singleton.ShowPanel(true, this._center);
				DlgBase<VirtualJoystick, VirtualJoystickBehaviour>.singleton.SetJoystickPos(num3, (flag7 ? num4 : (360f - num4)) - 90f);
			}
		}

		private void TabCulling()
		{
			bool flag = this._center.x - this._max_distance < 0f;
			if (flag)
			{
				this._center.x = this._max_distance;
			}
			bool flag2 = this._center.y - this._max_distance < 0f;
			if (flag2)
			{
				this._center.y = this._max_distance;
			}
			bool flag3 = this._center.x + this._max_distance > (float)Screen.width;
			if (flag3)
			{
				this._center.x = (float)Screen.width - this._max_distance;
			}
			bool flag4 = this._center.y + this._max_distance > (float)Screen.height;
			if (flag4)
			{
				this._center.y = (float)Screen.height - this._max_distance;
			}
		}
	}
}