From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- Client/Assets/Scripts/XMainClient/XKeyboard.cs | 141 +++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/XKeyboard.cs (limited to 'Client/Assets/Scripts/XMainClient/XKeyboard.cs') 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 + { + public bool Enabled + { + get + { + return XSingleton.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.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.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.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.singleton.MaxDistance, XSingleton.singleton.MaxDistance) : ((num != 0 && num2 != 0) ? new Vector2(XSingleton.singleton.MaxDistance + (float)num * XSingleton.singleton.MaxDistance * 0.707f, XSingleton.singleton.MaxDistance + (float)num2 * XSingleton.singleton.MaxDistance * 0.707f) : new Vector2(XSingleton.singleton.MaxDistance + (float)num * XSingleton.singleton.MaxDistance, XSingleton.singleton.MaxDistance + (float)num2 * XSingleton.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.singleton.MaxDistance, XSingleton.singleton.MaxDistance) : ((num != 0 && num2 != 0) ? new Vector2(XSingleton.singleton.MaxDistance + (float)num * XSingleton.singleton.MaxDistance * 0.707f, XSingleton.singleton.MaxDistance + (float)num2 * XSingleton.singleton.MaxDistance * 0.707f) : new Vector2(XSingleton.singleton.MaxDistance + (float)num * XSingleton.singleton.MaxDistance, XSingleton.singleton.MaxDistance + (float)num2 * XSingleton.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.ToInt(XFingerId.XCommon_1); + this._touches[this._touch_count_this_frame].faketouch.position = new Vector2(XSingleton.singleton.MaxDistance, XSingleton.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; + } + } + } +} -- cgit v1.1-26-g67d0