Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
test script for Xbox BluetoothController on Unity/UWP/HoloLens. it is draft
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if WINDOWS_UWP
using Windows.Gaming.Input;
#endif
public class XboxPadTest : MonoBehaviour {
#if WINDOWS_UWP
public Gamepad controller;
#endif
// Use this for initialization
void Start () {
Debug.Log("XboxPad:start");
#if WINDOWS_UWP
// Gamepadを探す
if(Gamepad.Gamepads.Count > 0) {
Debug.Log("Gamepad found.");
// controller = Gamepad.Gamepads.First();
} else
{
Debug.Log("Gamepad not found.");
}
// ゲームパッド追加時イベント処理を追加
Gamepad.GamepadAdded += Gamepad_GamepadAdded;
#endif
}
// Update is called once per frame
void Update () {
float x = Input.GetAxis("Horizontal");
if (x != 0f)
Debug.Log(x);
if (Input.GetButton("Fire1"))
Debug.Log("Fire1");
if (Input.GetButton("Fire2"))
Debug.Log("Fire2");
if (Input.GetButton("Fire3"))
Debug.Log("Fire3");
if (Input.GetButton("Jump"))
Debug.Log("Jump");
if (Input.GetButton("XB1LeftShoulder"))
Debug.Log("XB1LeftShoulder");
if (Input.GetButton("XB1RightShoulder"))
Debug.Log("XB1RightShoulder");
if (Input.GetButton("XB1View"))
Debug.Log("XB1View");
if (Input.GetButton("XB1Menu"))
Debug.Log("XB1Menu");
if (Input.GetButton("LStick"))
Debug.Log("LStick");
if (Input.GetButton("RStick"))
Debug.Log("RStick");
if (Input.GetButton("B10"))
Debug.Log("B10");
if (Input.GetButton("B11"))
Debug.Log("B11");
if (Input.GetButton("B12"))
Debug.Log("B12");
if (Input.GetButton("B13"))
Debug.Log("B13");
if (Input.GetKey(KeyCode.UpArrow))
Debug.Log("UpArrow");
if (Input.GetKey(KeyCode.LeftArrow))
Debug.Log("LeftArrow");
x = Input.GetAxis("LStickH");
if (x != 0f)
Debug.Log("LStickH:" + x );
x = Input.GetAxis("LStickV");
if (x != 0f)
Debug.Log("LStickV:" + x);
x = Input.GetAxis("PadPlusH");
if (x != 0f)
Debug.Log("PadPlusH:" + x);
x = Input.GetAxis("PadPlusV");
if (x != 0f)
Debug.Log("PadPlusV:" + x);
x = Input.GetAxis("RStickH");
if (x != 0f)
Debug.Log("RStickH:" + x);
x = Input.GetAxis("RStickV");
if (x != 0f)
Debug.Log("RStickV:" + x);
x = Input.GetAxis("Trigger");
if (x != 0f)
Debug.Log("Trigger:" + x);
}
#if WINDOWS_UWP
// ゲームパッド追加時のイベント処理
private void Gamepad_GamepadAdded(object sender, Gamepad e)
{
controller = e;
Debug.Log("Gamepad added");
}
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment