From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../Scripts/XMainClient/Input/XVirtualTab.cs | 266 +++++++++++++++++++++ 1 file changed, 266 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/Input/XVirtualTab.cs (limited to 'Client/Assets/Scripts/XMainClient/Input/XVirtualTab.cs') 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 + { + 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.singleton.Player != null && XSingleton.singleton.Player.Buffs.IsBuffStateOn(XBuffType.XBuffType_Puzzled); + Vector3 result; + if (flag) + { + result = XSingleton.singleton.HorizontalRotateVetor3(this._direction, (float)XSingleton.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.singleton.GetPanelRadius(); + this._inner_radius = DlgBase.singleton.GetJoystickRadius(); + this._max_distance = (XSingleton.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.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.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.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.singleton.Clockwise(this._tab_dir, vector); + this._tab_dir = XSingleton.singleton.HorizontalRotateVetor2(this._tab_dir, flag3 ? num : (-num), false); + bool flag4 = XSingleton.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.singleton.Clockwise(Vector2.up, this._tab_dir); + bool flag8 = XSingleton.singleton.GameCamera == null || XSingleton.singleton.GameCamera.CameraTrans == null; + if (!flag8) + { + Vector3 forward = XSingleton.singleton.GameCamera.CameraTrans.forward; + forward.y = 0f; + forward.Normalize(); + this._direction = XSingleton.singleton.HorizontalRotateVetor3(forward, flag7 ? num4 : (-num4), true); + DlgBase.singleton.ShowPanel(true, this._center); + DlgBase.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; + } + } + } +} -- cgit v1.1-26-g67d0