summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/XKeyboard.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-01-25 14:28:30 +0800
committerchai <chaifix@163.com>2021-01-25 14:28:30 +0800
commit6eb915c129fc90c6f4c82ae097dd6ffad5239efc (patch)
tree7dd2be50edf41f36b60fac84696e731c13afe617 /Client/Assets/Scripts/XMainClient/XKeyboard.cs
+scripts
Diffstat (limited to 'Client/Assets/Scripts/XMainClient/XKeyboard.cs')
-rw-r--r--Client/Assets/Scripts/XMainClient/XKeyboard.cs141
1 files changed, 141 insertions, 0 deletions
diff --git a/Client/Assets/Scripts/XMainClient/XKeyboard.cs b/Client/Assets/Scripts/XMainClient/XKeyboard.cs
new file mode 100644
index 00000000..c38a2042
--- /dev/null
+++ b/Client/Assets/Scripts/XMainClient/XKeyboard.cs
@@ -0,0 +1,141 @@
+using System;
+using UnityEngine;
+using XUpdater;
+using XUtliPoolLib;
+
+namespace XMainClient
+{
+ internal class XKeyboard : XSingleton<XKeyboard>
+ {
+ public bool Enabled
+ {
+ get
+ {
+ return XSingleton<XUpdater.XUpdater>.singleton.EditorMode;
+ }
+ }
+
+ public int touchCount
+ {
+ get
+ {
+ return this._touch_count_this_frame;
+ }
+ }
+
+ private XTouchItem[] _touches = new XTouchItem[XTouch.MultiTouchCount];
+
+ private int _touch_count_this_frame = 0;
+
+ private bool _bAxis = false;
+
+ private float _x = 0f;
+
+ private float _y = 0f;
+
+ private Vector3 _lastMousePos = Vector3.zero;
+
+ public XKeyboard()
+ {
+ for (int i = 0; i < XTouch.MultiTouchCount; i++)
+ {
+ this._touches[i] = new XTouchItem();
+ }
+ }
+
+ public XTouchItem GetTouch(int idx)
+ {
+ return this._touches[idx];
+ }
+
+ public void Update()
+ {
+ this._touch_count_this_frame = 0;
+ this._bAxis = false;
+ bool mouseButton = Input.GetMouseButton(0);
+ if (mouseButton)
+ {
+ this._touches[this._touch_count_this_frame].faketouch.fingerId = XFastEnumIntEqualityComparer<XFingerId>.ToInt(XFingerId.XCommon_0);
+ this._touches[this._touch_count_this_frame].faketouch.position = Input.mousePosition;
+ this._touches[this._touch_count_this_frame].faketouch.deltaTime = Time.smoothDeltaTime;
+ this._touches[this._touch_count_this_frame].faketouch.deltaPosition = Input.mousePosition - this._lastMousePos;
+ this._touches[this._touch_count_this_frame].faketouch.phase = (Input.GetMouseButtonDown(0) ? (TouchPhase) 0 : ((this._touches[this._touch_count_this_frame].faketouch.deltaPosition.sqrMagnitude > 1f) ? (TouchPhase)1 : (TouchPhase)2));
+ this._touches[this._touch_count_this_frame].faketouch.tapCount = 1;
+ this._touches[this._touch_count_this_frame].Fake = true;
+ this._lastMousePos = Input.mousePosition;
+ this._touch_count_this_frame++;
+ }
+ else
+ {
+ bool mouseButtonUp = Input.GetMouseButtonUp(0);
+ if (mouseButtonUp)
+ {
+ this._touches[this._touch_count_this_frame].faketouch.fingerId = XFastEnumIntEqualityComparer<XFingerId>.ToInt(XFingerId.XCommon_0);
+ this._touches[this._touch_count_this_frame].faketouch.position = Input.mousePosition;
+ this._touches[this._touch_count_this_frame].faketouch.deltaTime = Time.smoothDeltaTime;
+ this._touches[this._touch_count_this_frame].faketouch.phase = (TouchPhase)3;
+ this._touches[this._touch_count_this_frame].faketouch.tapCount = 1;
+ this._touches[this._touch_count_this_frame].Fake = true;
+ this._touch_count_this_frame++;
+ }
+ }
+ this._bAxis = true;
+ int num = 0; // horizontal
+ int num2 = 0; // verticle
+ bool key = Input.GetKey((KeyCode) 97);
+ if (key)
+ {
+ num--;
+ }
+ bool key2 = Input.GetKey((KeyCode)100);
+ if (key2)
+ {
+ num++;
+ }
+ bool key3 = Input.GetKey((KeyCode)115);
+ if (key3)
+ {
+ num2--;
+ }
+ bool key4 = Input.GetKey((KeyCode)119);
+ if (key4)
+ {
+ num2++;
+ }
+ bool flag = num != 0 || num2 != 0;
+ if (flag)
+ {
+ this._touches[this._touch_count_this_frame].faketouch.fingerId = XFastEnumIntEqualityComparer<XFingerId>.ToInt(XFingerId.XCommon_1);
+ this._touches[this._touch_count_this_frame].faketouch.deltaTime = Time.smoothDeltaTime;
+ this._touches[this._touch_count_this_frame].faketouch.phase = ((this._x == 0f && this._y == 0f) ? (TouchPhase)0 : (TouchPhase)1);
+ //this._touches[this._touch_count_this_frame].faketouch.position = ((this._touches[this._touch_count_this_frame].faketouch.phase == null) ? new Vector2(XSingleton<XVirtualTab>.singleton.MaxDistance, XSingleton<XVirtualTab>.singleton.MaxDistance) : ((num != 0 && num2 != 0) ? new Vector2(XSingleton<XVirtualTab>.singleton.MaxDistance + (float)num * XSingleton<XVirtualTab>.singleton.MaxDistance * 0.707f, XSingleton<XVirtualTab>.singleton.MaxDistance + (float)num2 * XSingleton<XVirtualTab>.singleton.MaxDistance * 0.707f) : new Vector2(XSingleton<XVirtualTab>.singleton.MaxDistance + (float)num * XSingleton<XVirtualTab>.singleton.MaxDistance, XSingleton<XVirtualTab>.singleton.MaxDistance + (float)num2 * XSingleton<XVirtualTab>.singleton.MaxDistance)));
+ this._touches[this._touch_count_this_frame].faketouch.position = ((this._touches[this._touch_count_this_frame].faketouch.phase == TouchPhase.Began) ? new Vector2(XSingleton<XVirtualTab>.singleton.MaxDistance, XSingleton<XVirtualTab>.singleton.MaxDistance) : ((num != 0 && num2 != 0) ? new Vector2(XSingleton<XVirtualTab>.singleton.MaxDistance + (float)num * XSingleton<XVirtualTab>.singleton.MaxDistance * 0.707f, XSingleton<XVirtualTab>.singleton.MaxDistance + (float)num2 * XSingleton<XVirtualTab>.singleton.MaxDistance * 0.707f) : new Vector2(XSingleton<XVirtualTab>.singleton.MaxDistance + (float)num * XSingleton<XVirtualTab>.singleton.MaxDistance, XSingleton<XVirtualTab>.singleton.MaxDistance + (float)num2 * XSingleton<XVirtualTab>.singleton.MaxDistance)));
+ this._touches[this._touch_count_this_frame].faketouch.tapCount = 1;
+ this._touches[this._touch_count_this_frame].Fake = true;
+ this._touch_count_this_frame++;
+ }
+ else
+ {
+ bool flag2 = this._x != 0f || this._y != 0f;
+ if (flag2)
+ {
+ this._touches[this._touch_count_this_frame].faketouch.fingerId = XFastEnumIntEqualityComparer<XFingerId>.ToInt(XFingerId.XCommon_1);
+ this._touches[this._touch_count_this_frame].faketouch.position = new Vector2(XSingleton<XVirtualTab>.singleton.MaxDistance, XSingleton<XVirtualTab>.singleton.MaxDistance);
+ this._touches[this._touch_count_this_frame].faketouch.deltaTime = Time.smoothDeltaTime;
+ this._touches[this._touch_count_this_frame].faketouch.phase = (TouchPhase) 3;
+ this._touches[this._touch_count_this_frame].faketouch.tapCount = 1;
+ this._touches[this._touch_count_this_frame].Fake = true;
+ this._touch_count_this_frame++;
+ }
+ }
+ this._x = (float)num;
+ this._y = (float)num2;
+ bool flag3 = !this._bAxis;
+ if (flag3)
+ {
+ this._x = 0f;
+ this._y = 0f;
+ }
+ }
+ }
+}