diff options
Diffstat (limited to 'Client/Assets/Scripts/XMainClient/XSirJoystick.cs')
-rw-r--r-- | Client/Assets/Scripts/XMainClient/XSirJoystick.cs | 174 |
1 files changed, 174 insertions, 0 deletions
diff --git a/Client/Assets/Scripts/XMainClient/XSirJoystick.cs b/Client/Assets/Scripts/XMainClient/XSirJoystick.cs new file mode 100644 index 00000000..cfbac3e8 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/XSirJoystick.cs @@ -0,0 +1,174 @@ +using System;
+using UnityEngine;
+using XUpdater;
+using XUtliPoolLib;
+
+namespace XMainClient
+{
+ internal class XSirJoystick : XSingleton<XSirJoystick>
+ {
+ private IXGameSirControl SirControl
+ {
+ get
+ {
+ return XSingleton<XUpdater.XUpdater>.singleton.GameSirControl;
+ }
+ }
+
+ public int touchCount
+ {
+ get
+ {
+ return this._touch_count_this_frame;
+ }
+ }
+
+ public bool Enabled
+ {
+ get
+ {
+ return this.SirControl != null && this.SirControl.IsConnected();
+ }
+ }
+
+ private XTouchItem[] _touches = new XTouchItem[XSirJoystick._touch_count_total_frame];
+
+ private Vector2 _RotatePos = new Vector2((float)Screen.width * 0.75f, (float)Screen.height * 0.5f);
+
+ private Vector2 _RockerPos = new Vector2((float)Screen.width * 0.2f, (float)Screen.height * 0.25f);
+
+ private Vector2 _RotateRangeX = new Vector2((float)Screen.width * 0.5f, (float)Screen.width * 1f);
+
+ private Vector2 _RotateRangeY = new Vector2((float)Screen.height * 0.2f, (float)Screen.height * 0.8f);
+
+ private int _touch_count_this_frame = 0;
+
+ private static int _touch_count_total_frame = 2;
+
+ private float _x = 0f;
+
+ private float _y = 0f;
+
+ private float _z = 0f;
+
+ private float _rz = 0f;
+
+ private Vector2 _tempPos;
+
+ private int _RotateStep = 10;
+
+ public XSirJoystick()
+ {
+ for (int i = 0; i < XSirJoystick._touch_count_total_frame; i++)
+ {
+ this._touches[i] = new XTouchItem();
+ }
+ }
+
+ public XTouchItem GetTouch(int touch)
+ {
+ return this._touches[touch];
+ }
+
+ public void Update()
+ {
+ this._touch_count_this_frame = 0;
+ this.OnTouch();
+ this.UpdateRocker();
+ this.UpdateRotate();
+ }
+
+ private void OnTouch()
+ {
+ bool button = this.SirControl.GetButton(XGameSirKeyCode.BTN_THUMBL);
+ if (button)
+ {
+ XSingleton<XScene>.singleton.GameCamera.BackToPlayer();
+ }
+ }
+
+ private void UpdateRocker()
+ {
+ float axis = this.SirControl.GetAxis(XGameSirKeyCode.AXIS_X);
+ float num = -this.SirControl.GetAxis(XGameSirKeyCode.AXIS_Y);
+ bool flag = axis != 0f || num != 0f;
+ if (flag)
+ {
+ this._touches[this._touch_count_this_frame].faketouch.fingerId = XFastEnumIntEqualityComparer<XFingerId>.ToInt(XFingerId.XJoystick_1);
+ this._touches[this._touch_count_this_frame].faketouch.deltaTime = Time.smoothDeltaTime;
+ this._touches[this._touch_count_this_frame].faketouch.phase = ((this._x == 0f && this._y == 0f) ?(TouchPhase) 0 :(TouchPhase) 1);
+ this._touches[this._touch_count_this_frame].faketouch.position = ((this._touches[this._touch_count_this_frame].faketouch.phase == null) ? this._RockerPos : ((axis != 0f && num != 0f) ? new Vector2(this._RockerPos.x + axis * XSingleton<XVirtualTab>.singleton.MaxDistance * 0.707f, this._RockerPos.y + num * XSingleton<XVirtualTab>.singleton.MaxDistance * 0.707f) : new Vector2(this._RockerPos.x + axis * XSingleton<XVirtualTab>.singleton.MaxDistance, this._RockerPos.y + num * XSingleton<XVirtualTab>.singleton.MaxDistance)));
+ this._touches[this._touch_count_this_frame].faketouch.tapCount = 1;
+ this._touches[this._touch_count_this_frame].Fake = true;
+ this._touch_count_this_frame++;
+ }
+ else
+ {
+ bool flag2 = this._x != 0f || this._y != 0f;
+ if (flag2)
+ {
+ this._touches[this._touch_count_this_frame].faketouch.fingerId = XFastEnumIntEqualityComparer<XFingerId>.ToInt(XFingerId.XJoystick_1);
+ this._touches[this._touch_count_this_frame].faketouch.position = this._RockerPos;
+ this._touches[this._touch_count_this_frame].faketouch.deltaTime = Time.smoothDeltaTime;
+ this._touches[this._touch_count_this_frame].faketouch.phase = (TouchPhase)3;
+ this._touches[this._touch_count_this_frame].faketouch.tapCount = 1;
+ this._touches[this._touch_count_this_frame].Fake = true;
+ this._touch_count_this_frame++;
+ }
+ }
+ this._x = axis;
+ this._y = num;
+ }
+
+ private void UpdateRotate()
+ {
+ float axis = this.SirControl.GetAxis(XGameSirKeyCode.AXIS_Z);
+ float num = -this.SirControl.GetAxis(XGameSirKeyCode.AXIS_RZ);
+ bool flag = axis != 0f || num != 0f;
+ if (flag)
+ {
+ this._touches[this._touch_count_this_frame].faketouch.fingerId = XFastEnumIntEqualityComparer<XFingerId>.ToInt(XFingerId.XJoystick_0);
+ this._touches[this._touch_count_this_frame].faketouch.deltaTime = Time.smoothDeltaTime;
+ this._touches[this._touch_count_this_frame].faketouch.deltaPosition = new Vector2(axis, num);
+ bool flag2 = this._z == 0f && this._rz == 0f;
+ if (flag2)
+ {
+ this._touches[this._touch_count_this_frame].faketouch.phase = 0;
+ this._touches[this._touch_count_this_frame].faketouch.position = this._RotatePos;
+ this._tempPos = this._RotatePos;
+ }
+ else
+ {
+ bool flag3 = this._touches[this._touch_count_this_frame].faketouch.deltaPosition.sqrMagnitude >= 0.5f;
+ if (flag3)
+ {
+ this._tempPos += this._touches[this._touch_count_this_frame].faketouch.deltaPosition * (float)this._RotateStep;
+ this._tempPos.x = Mathf.Clamp(this._tempPos.x, this._RotateRangeX.x, this._RotateRangeX.y);
+ this._tempPos.y = Mathf.Clamp(this._tempPos.y, this._RotateRangeY.x, this._RotateRangeY.y);
+ this._touches[this._touch_count_this_frame].faketouch.phase = (TouchPhase)1;
+ this._touches[this._touch_count_this_frame].faketouch.position = this._tempPos;
+ }
+ }
+ this._touches[this._touch_count_this_frame].faketouch.tapCount = 1;
+ this._touches[this._touch_count_this_frame].Fake = true;
+ this._touch_count_this_frame++;
+ }
+ else
+ {
+ bool flag4 = this._z != 0f || this._rz != 0f;
+ if (flag4)
+ {
+ this._touches[this._touch_count_this_frame].faketouch.fingerId = XFastEnumIntEqualityComparer<XFingerId>.ToInt(XFingerId.XJoystick_0);
+ this._touches[this._touch_count_this_frame].faketouch.position = this._tempPos;
+ this._touches[this._touch_count_this_frame].faketouch.deltaTime = Time.smoothDeltaTime;
+ this._touches[this._touch_count_this_frame].faketouch.phase = (TouchPhase)3;
+ this._touches[this._touch_count_this_frame].faketouch.tapCount = 1;
+ this._touches[this._touch_count_this_frame].Fake = true;
+ this._touch_count_this_frame++;
+ }
+ }
+ this._z = axis;
+ this._rz = num;
+ }
+ }
+}
|