diff options
Diffstat (limited to 'Client/Assets/Scripts/XMainClient/Input')
6 files changed, 521 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);
+ }
+ }
+}
diff --git a/Client/Assets/Scripts/XMainClient/Input/XTouch.cs.meta b/Client/Assets/Scripts/XMainClient/Input/XTouch.cs.meta new file mode 100644 index 00000000..5514441d --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/Input/XTouch.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 6ba1f33f2f1ba684a90a3981e8ebfc73 +timeCreated: 1611403892 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Client/Assets/Scripts/XMainClient/Input/XTouchItem.cs b/Client/Assets/Scripts/XMainClient/Input/XTouchItem.cs new file mode 100644 index 00000000..a360ddeb --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/Input/XTouchItem.cs @@ -0,0 +1,79 @@ +using System;
+using UnityEngine;
+
+namespace XMainClient
+{
+ internal class XTouchItem
+ {
+ public bool Fake { get; set; }
+
+ public float DeltaTime
+ {
+ get
+ {
+ return this.Fake ? this.faketouch.deltaTime : this.touch.deltaTime;
+ }
+ }
+
+ public int FingerId
+ {
+ get
+ {
+ return this.Fake ? this.faketouch.fingerId : this.touch.fingerId;
+ }
+ }
+
+ public TouchPhase Phase
+ {
+ get
+ {
+ return this.Fake ? this.faketouch.phase : this.touch.phase;
+ }
+ }
+
+ public Vector2 Position
+ {
+ get
+ {
+ return this.Fake ? this.faketouch.position : this.touch.position;
+ }
+ }
+
+ public Vector2 RawPosition
+ {
+ get
+ {
+ return this.Fake ? this.faketouch.rawPosition : this.touch.rawPosition;
+ }
+ }
+
+ public int TapCount
+ {
+ get
+ {
+ return this.Fake ? this.faketouch.tapCount : this.touch.tapCount;
+ }
+ }
+
+ public Touch touch;
+
+ public XFakeTouch faketouch;
+
+ public void Convert2FakeTouch(TouchPhase phase)
+ {
+ this.faketouch.fingerId = this.touch.fingerId;
+ this.faketouch.position = this.touch.position;
+ this.faketouch.deltaTime = this.touch.deltaTime;
+ this.faketouch.deltaPosition = this.touch.deltaPosition;
+ this.faketouch.phase = phase;
+ this.faketouch.tapCount = this.touch.tapCount;
+ this.Fake = true;
+ }
+
+ public override string ToString()
+ {
+ return "DeltaTime=" + DeltaTime + ", FingerId=" + FingerId + ", Phase=" + Phase + ", Pos=" + Position + ", RawPos=" + RawPosition + ", TapCount=" + TapCount;
+ }
+
+ }
+}
diff --git a/Client/Assets/Scripts/XMainClient/Input/XTouchItem.cs.meta b/Client/Assets/Scripts/XMainClient/Input/XTouchItem.cs.meta new file mode 100644 index 00000000..4ce1e6a4 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/Input/XTouchItem.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 8a1c2055e959bd544b0b00d6514fb5bf +timeCreated: 1611404090 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Client/Assets/Scripts/XMainClient/Input/XVirtualTab.cs b/Client/Assets/Scripts/XMainClient/Input/XVirtualTab.cs new file mode 100644 index 00000000..c68068e7 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/Input/XVirtualTab.cs @@ -0,0 +1,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;
+ }
+ }
+ }
+}
diff --git a/Client/Assets/Scripts/XMainClient/Input/XVirtualTab.cs.meta b/Client/Assets/Scripts/XMainClient/Input/XVirtualTab.cs.meta new file mode 100644 index 00000000..e4bb8a04 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/Input/XVirtualTab.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 3ecc24643af9abd4195051948af49ba5 +timeCreated: 1611403609 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: |