// Update is called once per frame
        void Update()
        {
            // ボタンとスティックの入力を取得して通知
#if WINDOWS_UWP
            if (gamepad != null)
            {
                var reader = gamepad.GetCurrentReading();
                var lx     = (float)reader.LeftThumbstickX;
                var ly     = (float)reader.LeftThumbstickY;
                if (Mathf.Abs(lx) > 0.1f || Mathf.Abs(ly) > 0.1f)
                {
                    getAxis.Invoke(XBoxStick.LeftThumbstick, new Vector2(lx, ly));
                }
                var rx = (float)reader.RightThumbstickX;
                var ry = (float)reader.RightThumbstickY;
                if (Mathf.Abs(rx) > 0.1f || Mathf.Abs(ry) > 0.1f)
                {
                    getAxis.Invoke(XBoxStick.RightThumbstick, new Vector2(rx, ry));
                }
                var lt = (float)reader.LeftTrigger;
                var rt = (float)reader.RightTrigger;
                if (Mathf.Abs(lt) > 0.1f || Mathf.Abs(rt) > 0.1f)
                {
                    getAxis.Invoke(XBoxStick.Trigger, new Vector2(lt, rt));
                }
                getButton.Invoke((XBoxInput)reader.Buttons);
            }
#else
            // No support (DPad, RightThumbstick, Trigger)
            // UWP以外ではXBoxコントローラーの十字キー,右側スティック,左右のトリガーは非サポート
            var gamepad = UnityEngine.Input.GetJoystickNames();
            if (((gamepad.Length > 0) ? true : false) == true && gamepad[0] != "")
            {
                var axisX = UnityEngine.Input.GetAxis("Horizontal");
                var axisY = UnityEngine.Input.GetAxis("Vertical");
                if (Mathf.Abs(axisX) > 0.1f || Mathf.Abs(axisY) > 0.1f)
                {
                    getAxis.Invoke(XBoxStick.LeftThumbstick, new Vector2(axisX, axisY));
                }

                XBoxInput xBoxInput = 0;
                if (UnityEngine.Input.GetKey("joystick button 0"))
                {
                    xBoxInput = xBoxInput | XBoxInput.A;
                }
                if (UnityEngine.Input.GetKey("joystick button 1"))
                {
                    xBoxInput = xBoxInput | XBoxInput.B;
                }
                if (UnityEngine.Input.GetKey("joystick button 2"))
                {
                    xBoxInput = xBoxInput | XBoxInput.X;
                }
                if (UnityEngine.Input.GetKey("joystick button 3"))
                {
                    xBoxInput = xBoxInput | XBoxInput.Y;
                }
                if (UnityEngine.Input.GetKey("joystick button 4"))
                {
                    xBoxInput = xBoxInput | XBoxInput.LeftShoulder;
                }
                if (UnityEngine.Input.GetKey("joystick button 5"))
                {
                    xBoxInput = xBoxInput | XBoxInput.RightShoulder;
                }
                if (UnityEngine.Input.GetKey("joystick button 6"))
                {
                    xBoxInput = xBoxInput | XBoxInput.View;
                }
                if (UnityEngine.Input.GetKey("joystick button 7"))
                {
                    xBoxInput = xBoxInput | XBoxInput.Menu;
                }
                if (UnityEngine.Input.GetKey("joystick button 8"))
                {
                    xBoxInput = xBoxInput | XBoxInput.LeftThumbstick;
                }
                if (UnityEngine.Input.GetKey("joystick button 9"))
                {
                    xBoxInput = xBoxInput | XBoxInput.RightThumbstick;
                }
                getButton.Invoke(xBoxInput);
            }
#endif
        }
Example #2
0
 private void ButtonAction_Click(object sender, RoutedEventArgs e)
 {
     ButtonActionEvent.Invoke(sender, e);
 }
Example #3
0
 public void CallButtonActionEvent(ButtonAction buttonAction)
 {
     ButtonActionEvent?.Invoke(buttonAction);
 }