public static DeviceState GetState(int index)
        {
            DeviceState retState = new DeviceState();

#if !UNITY_EDITOR && UNITY_WSA
            lock (DeviceConnect.states)
            {
                if (index >= 0 && index < DeviceConnect.states.Count)
                {
                    lock (DeviceConnect.states[index])
                    {
                        retState.AssignFrom(DeviceConnect.states[index], false);
                    }
                }
            }
#endif

            return(retState);
        }
        public override void _Update()
        {
            base._Update();

            //Debug.Log("cs a: " + ControlsState.state.A);
            if (DeviceState.GetControllerCount() > 0)
            {
                DeviceState state = DeviceState.GetState(0);

                present = true;

                aButtonState.ApplyState(state.A);
                bButtonState.ApplyState(state.B);
                xButtonState.ApplyState(state.X);
                yButtonState.ApplyState(state.Y);
                startButtonState.ApplyState(state.start || state.logo);

                leftJoyVector  = state.LeftStick;
                rightJoyVector = state.RightStick;
                trigVector     = state.Triggers;
                padVector      = state.DPad;
            }
            else
            {
                present = false;
            }

            // Invert
            leftJoyVector.y = -leftJoyVector.y;

            // Deadzone
            float deadzone = 0.15f;

            if (leftJoyVector.sqrMagnitude < deadzone * deadzone)
            {
                leftJoyVector = Vector2.zero;
            }
        }
        private static void OpenDevice(string dId)
        {
            DeviceState newState = null;

            lock (states)
            {
                foreach (DeviceState ds in states)
                {
                    if (ds.DeviceId == dId)
                    {
                        return;
                    }
                }

                newState = new DeviceState();
                states.Add(newState);
            }

            if (newState != null)
            {
                newState.OpenDevice(dId);
            }
        }