diff options
Diffstat (limited to 'Client/Assembly-CSharp/ScreenJoystick.cs')
-rw-r--r-- | Client/Assembly-CSharp/ScreenJoystick.cs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/Client/Assembly-CSharp/ScreenJoystick.cs b/Client/Assembly-CSharp/ScreenJoystick.cs new file mode 100644 index 0000000..f787ea3 --- /dev/null +++ b/Client/Assembly-CSharp/ScreenJoystick.cs @@ -0,0 +1,54 @@ +using System; +using UnityEngine; + +public class ScreenJoystick : MonoBehaviour, IVirtualJoystick +{ + public Vector2 Delta { get; private set; } + + private Collider2D[] hitBuffer = new Collider2D[20]; + + private Controller myController = new Controller(); + + private int touchId = -1; + + private void FixedUpdate() + { + this.myController.Update(); + if (this.touchId <= -1) + { + for (int i = 0; i < this.myController.Touches.Length; i++) + { + Controller.TouchState touchState = this.myController.Touches[i]; + if (touchState.TouchStart) + { + bool flag = false; + int num = Physics2D.OverlapPointNonAlloc(touchState.Position, this.hitBuffer, Constants.NotShipMask); + for (int j = 0; j < num; j++) + { + Collider2D collider2D = this.hitBuffer[j]; + if (collider2D.GetComponent<ButtonBehavior>() || collider2D.GetComponent<PassiveButton>()) + { + flag = true; + break; + } + } + if (!flag) + { + this.touchId = i; + return; + } + } + } + return; + } + Controller.TouchState touchState2 = this.myController.Touches[this.touchId]; + if (touchState2.IsDown) + { + Vector2 b = Camera.main.ViewportToWorldPoint(new Vector2(0.5f, 0.5f)); + this.Delta = (touchState2.Position - b).normalized; + return; + } + this.touchId = -1; + this.Delta = Vector2.zero; + } +} |