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/Input/XTouch.cs | 140 ++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/Input/XTouch.cs (limited to 'Client/Assets/Scripts/XMainClient/Input/XTouch.cs') 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 + { + 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.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.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.singleton.Enabled; + if (enabled) + { + XSingleton.singleton.Update(); + for (int i = 0; i < XSingleton.singleton.touchCount; i++) + { + XTouchItem touchItem = XSingleton.singleton.GetTouch(i); + Debug.Log("touch=" + touchItem); + this.HandleTouch(touchItem); + } + } + bool enabled2 = XSingleton.singleton.Enabled; + if (enabled2) + { + XSingleton.singleton.Update(); + for (int j = 0; j < XSingleton.singleton.touchCount; j++) + { + this.HandleTouch(XSingleton.singleton.GetTouch(j)); + } + } + bool enabled3 = XSingleton.singleton.Enabled; + if (enabled3) + { + XSingleton.singleton.Update(); + for (int k = 0; k < XSingleton.singleton.touchCount; k++) + { + this.HandleTouch(XSingleton.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.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.singleton.ScreenSaveLimit; + if (flag3) + { + this._on_screen_save = true; + this._screenSave = 0f; + XSingleton.singleton.XPlatform.SetScreenLightness(XSingleton.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.singleton.Feed(touch); + XSingleton.singleton.Feed(touch); + } + } +} -- cgit v1.1-26-g67d0