using System; using UnityEngine; using XUpdater; using XUtliPoolLib; namespace XMainClient { internal class XGyroscope : XSingleton { public float Scale { get { return this._scale; } } public float DeadZone { get { return this._deadzone; } } public float Frequency { get { return this._frequency; } } public bool Enabled { get { return this._enabled; } set { bool flag = this._enabled != value; if (flag) { this._touch_count_this_frame = 0; this._enabled = value; } Input.gyro.enabled = this._enabled; bool enabled = this._enabled; if (enabled) { this._scale = (XSingleton.singleton.EditorMode ? 1f : XSingleton.singleton.GyroScale); this._deadzone = XSingleton.singleton.GyroDeadZone; this._frequency = XSingleton.singleton.GyroFrequency; Input.gyro.updateInterval = 1f / this._frequency; } this.Cancel(); XSingleton.singleton.Cancel(); } } public int touchCount { get { return this._touch_count_this_frame; } } private XTouchItem _touches = new XTouchItem(); private bool _enabled = false; private static Vector2 _init_pos = new Vector2((float)Screen.width * 0.55f, (float)Screen.height * 0.55f); private static Vector2 _last_pos = XGyroscope._init_pos; private static Vector2 _curr_pos = XGyroscope._init_pos; private int _touch_count_this_frame = 0; private float _frequency = 30f; private float _scale = 0.2f; private float _deadzone = 0.01f; public void OnEnterScene() { XOptionsDocument specificDocument = XDocuments.GetSpecificDocument(XOptionsDocument.uuID); bool flag = specificDocument != null; if (flag) { this.Enabled = (specificDocument.GetValue(XOptionsDefine.OD_Gyro) != 0); } } public void Update() { this._touch_count_this_frame = 0; bool currentPos = this.GetCurrentPos(); if (currentPos) { this._touches.faketouch.fingerId = XFastEnumIntEqualityComparer.ToInt(XFingerId.XGyroscope_0); this._touches.faketouch.position = XGyroscope._curr_pos; this._touches.faketouch.deltaTime = Time.smoothDeltaTime; this._touches.faketouch.deltaPosition = XGyroscope._curr_pos - XGyroscope._last_pos; this._touches.faketouch.phase = ((XGyroscope._curr_pos == XGyroscope._init_pos) ? (TouchPhase)3 : ((XGyroscope._last_pos == XGyroscope._init_pos) ? (TouchPhase)0 : (TouchPhase)1)); this._touches.faketouch.tapCount = 1; this._touches.Fake = true; XGyroscope._last_pos = XGyroscope._curr_pos; this._touch_count_this_frame++; } } public XTouchItem GetTouch(int idx) { return this._touches; } public void Set(float scale, float times, float deadzone) { bool enabled = this.Enabled; if (enabled) { this._scale = (XSingleton.singleton.EditorMode ? 1f : scale); this._deadzone = deadzone; this._frequency = times; Input.gyro.updateInterval = 1f / this._frequency; } } private bool GetCurrentPos() { float num = 0f; float num2 = 0f; bool editorMode = XSingleton.singleton.EditorMode; if (editorMode) { bool key = Input.GetKey((KeyCode)276); if (key) { num -= 1f; } bool key2 = Input.GetKey((KeyCode)275); if (key2) { num += 1f; } bool key3 = Input.GetKey((KeyCode)274); if (key3) { num2 -= 1f; } bool key4 = Input.GetKey((KeyCode)273); if (key4) { num2 += 1f; } } else { Vector3 rotationRateUnbiased = Input.gyro.rotationRateUnbiased; rotationRateUnbiased.z = 0f; bool flag = rotationRateUnbiased.sqrMagnitude < this._deadzone * this._deadzone; if (flag) { num2 = (num = 0f); } else { num = -(rotationRateUnbiased.y * 57.29578f); num2 = rotationRateUnbiased.x * 57.29578f; } } bool flag2 = num != 0f || num2 != 0f; bool result; if (flag2) { XGyroscope._curr_pos = XGyroscope._last_pos + new Vector2(this._scale * num, this._scale * num2); result = true; } else { bool flag3 = XGyroscope._curr_pos != XGyroscope._init_pos; if (flag3) { XGyroscope._last_pos = XGyroscope._init_pos; XGyroscope._curr_pos = XGyroscope._init_pos; result = true; } else { result = false; } } return result; } public void Cancel() { XGyroscope._last_pos = XGyroscope._init_pos; XGyroscope._curr_pos = XGyroscope._init_pos; } } }