diff options
author | chai <chaifix@163.com> | 2021-01-25 14:28:30 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-01-25 14:28:30 +0800 |
commit | 6eb915c129fc90c6f4c82ae097dd6ffad5239efc (patch) | |
tree | 7dd2be50edf41f36b60fac84696e731c13afe617 /Client/Assets/Scripts/XMainClient/Input/XTouch.cs |
+scripts
Diffstat (limited to 'Client/Assets/Scripts/XMainClient/Input/XTouch.cs')
-rw-r--r-- | Client/Assets/Scripts/XMainClient/Input/XTouch.cs | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/Client/Assets/Scripts/XMainClient/Input/XTouch.cs b/Client/Assets/Scripts/XMainClient/Input/XTouch.cs new file mode 100644 index 00000000..25823344 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/Input/XTouch.cs @@ -0,0 +1,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);
+ }
+ }
+}
|