UnityはXBoxOneコントローラー入力を構成します



Unity Configures Xbox One Controller Input

参考資料:
XBoxキーの説明(中国語/英語版):
https://support.xbox.com/zh-CN/xbox-one/accessories/xbox-one-wireless-controller
https://support.xbox.com/en-US/xbox-one/accessories/xbox-one-wireless-controller
UnityでのXBoxコントローラーボタンのマッピング(英語版):
https://answers.unity.com/questions/1350081/xbox-one-controller-mapping-solved.html

リリースノート:
この記事の内容はUnity2017.4.4f1でテストされ、添付ファイルの内容はこのバージョンのUnityプロジェクトから取得されました。



ボタンマッピング

UnityでのXBoxOneコントローラーの主要なマッピング関係は、コメント内で次のとおりですAxisPositive Button String attribute valueでUnityで 入力マネージャー 次のページで使用されます:

/// /// XBox One controller button mapping information class. /// The axis attribute is used in the Input.GetAxis(string name) method The /// key attribute is used in the Input.GetKey(string name) method. ///All properties do not apply to the Input.GetButton(string name) method, if you want to use this method for a button, /// The value of the 'Name' property of this button in Unity's 'Input Manager' page should be passed instead of the value of the 'Positive Button' property. /// public class XBoxController { #region Rocker shaft (Stick) /// /// Left Stick Horizontal. /// Axis: X Axis. /// public string LSH { get { return 'LSH' } } /// /// Left Stick Vertical. /// Axis: Y Axis. /// public string LSV { get { return 'LSV' } } /// /// Right Stick Horizontal. /// Axis: 4th Axis. /// public string RSH { get { return 'RSH' } } /// /// Right Stick Vertical. /// Axis: 5th Axis. /// public string RSV { get { return 'RSV' } } #endregion #region Cross direction key (Directional Pad, D-Pad) /// /// D-Pad Horizontal. /// Axis: 6th Axis. /// public string DPadH { get { return 'DPadH' } } /// /// D-Pad Vertical. /// Axis: 7th Axis. /// public string DPadV { get { return 'DPadV' } } #endregion #region Trigger shaft (Trigger) /// /// Left Trigger. /// Axis: 9th Axis. /// public string LT { get { return 'LT' } } /// /// Right Trigger. /// Axis: 10th Axis. /// public string RT { get { return 'RT' } } /// /// Shared Trigger. /// Axis: 3rd Axis. /// public string Trigger { get { return 'Trigger' } } #endregion #region ABXY key /// /// A. /// Positive Button: joystick button 0. /// public string A { get { return 'joystick button 0' } } /// /// B. /// Positive Button: joystick button 1. /// public string B { get { return 'joystick button 1' } } /// /// X. /// Positive Button: joystick button 2. /// public string X { get { return 'joystick button 2' } } /// /// Y. /// Positive Button: joystick button 3. /// public string Y { get { return 'joystick button 3' } } #endregion #region Buffer button /// /// Left Bumper. /// Positive Button: joystick button 4. /// public string LB { get { return 'joystick button 4' } } /// /// Right Bumper. /// Positive Button: joystick button 5. /// public string RB { get { return 'joystick button 5' } } #endregion #region View (Back), Menu (Start), XBox button /// /// View. /// Positive Button: joystick button 6. /// public string View { get { return 'joystick button 6' } } /// /// Munu. /// Positive Button: joystick button 7. /// public string Menu { get { return 'joystick button 7' } } // public string XBox { get { return string.None } } // no corresponding #endregion #region Rocker button /// /// Left Stick Button. /// Positive Button: joystick button 8. /// public string LS { get { return 'joystick button 8' } } // JoystickButton8 /// /// Right Stick Button. /// Positive Button: joystick button 9. /// public string RS { get { return 'joystick button 9' } } // JoystickButton9 #endregion }

2.入力マネージャーの構成

Unityでコントローラーボタン入力を取得して使用するInput.GetKey(string name)メソッド、コントローラーロッカー、方向キー、トリガーキー入力を使用するInput.GetAxis(string axisName)方法。



2.1ボタンの構成

取得するために使用 ボタン 入力GetKey()メソッドのパラメータの内容は次のようにする必要があります 入力マネージャー パススルーPositive Buttonプロパティ設定、Unityの各ボタンには固定名があり、自由に入力することはできません。上記のコードコメントを参照してくださいPositive Buttonコンテンツが設定されていますが、このパラメータは設定されていません 入力マネージャー 真ん中Nameプロパティへの影響。ボタンTypeプロパティをに設定する必要があります キーまたはマウスボタン

2.2ジョイスティック、方向キー、およびトリガーの構成

取得するために使用 入力GetAxis()メソッドのパラメータの内容は次のようにする必要があります 入力マネージャー パススルーNameプロパティ設定、ここで名前を設定できます。Unityに制限はありません。軸Typeプロパティをに設定する必要があります ジョイスティック軸Axisプロパティは、上記のコードコメントで参照されています。Axis内容は設定されており、自由に選択することはできません。

Unity Input Managerの設定例:
入力マネージャー



3.添付ファイル-InputManager.asset

以下をプロジェクトフォルダにコピーできます。 ProjectSettings / InputManager.asset 上記のコードと回路図に対応するXBox入力構成がファイルに生成されます。
注意 これを行う カバー 元の入力構成!

%YAML 1.1 %TAG !u! tag:unity3d.com,2011: --- !u!13 &1 InputManager: m_ObjectHideFlags: 0 serializedVersion: 2 m_Axes: - serializedVersion: 3 m_Name: A descriptiveName: XBox Controller Button 'A'. descriptiveNegativeName: negativeButton: positiveButton: joystick button 0 altNegativeButton: altPositiveButton: gravity: 1000 dead: 0.001 sensitivity: 1000 snap: 0 invert: 0 type: 0 axis: 0 joyNum: 0 - serializedVersion: 3 m_Name: B descriptiveName: XBox Controller Button 'B'. descriptiveNegativeName: negativeButton: positiveButton: joystick button 1 altNegativeButton: altPositiveButton: gravity: 1000 dead: 0.001 sensitivity: 1000 snap: 0 invert: 0 type: 0 axis: 0 joyNum: 0 - serializedVersion: 3 m_Name: X descriptiveName: 'XBox Controller Button u201CXu201D.' descriptiveNegativeName: negativeButton: positiveButton: joystick button 2 altNegativeButton: altPositiveButton: gravity: 1000 dead: 0.001 sensitivity: 1000 snap: 0 invert: 0 type: 0 axis: 0 joyNum: 0 - serializedVersion: 3 m_Name: Y descriptiveName: 'XBox Controller Button u201CYu201D.' descriptiveNegativeName: negativeButton: positiveButton: joystick button 3 altNegativeButton: altPositiveButton: gravity: 1000 dead: 0.001 sensitivity: 1000 snap: 0 invert: 0 type: 0 axis: 0 joyNum: 0 - serializedVersion: 3 m_Name: LB descriptiveName: 'XBox Controller Button u201DLeft Bumperu201C.' descriptiveNegativeName: negativeButton: positiveButton: joystick button 4 altNegativeButton: altPositiveButton: gravity: 1000 dead: 0.001 sensitivity: 1000 snap: 0 invert: 0 type: 0 axis: 0 joyNum: 0 - serializedVersion: 3 m_Name: RB descriptiveName: 'XBox Controller Button u201DRight Bumperu201C.' descriptiveNegativeName: negativeButton: positiveButton: joystick button 5 altNegativeButton: altPositiveButton: gravity: 1000 dead: 0.001 sensitivity: 1000 snap: 0 invert: 0 type: 0 axis: 0 joyNum: 0 - serializedVersion: 3 m_Name: View descriptiveName: XBox Controller Button 'View'. descriptiveNegativeName: negativeButton: positiveButton: joystick button 6 altNegativeButton: altPositiveButton: gravity: 1000 dead: 0.001 sensitivity: 1000 snap: 0 invert: 0 type: 0 axis: 0 joyNum: 0 - serializedVersion: 3 m_Name: Menu descriptiveName: XBox Controller Button 'Menu'. descriptiveNegativeName: negativeButton: positiveButton: joystick button 7 altNegativeButton: altPositiveButton: gravity: 1000 dead: 0.001 sensitivity: 1000 snap: 0 invert: 0 type: 0 axis: 0 joyNum: 0 - serializedVersion: 3 m_Name: LS descriptiveName: XBox Controller Button 'Left Stick Button'. descriptiveNegativeName: negativeButton: positiveButton: joystick button 8 altNegativeButton: altPositiveButton: gravity: 1000 dead: 0.001 sensitivity: 1000 snap: 0 invert: 0 type: 0 axis: 0 joyNum: 0 - serializedVersion: 3 m_Name: RS descriptiveName: XBox Controller Button 'Right Stick Button'. descriptiveNegativeName: negativeButton: positiveButton: joystick button 9 altNegativeButton: altPositiveButton: gravity: 1000 dead: 0.001 sensitivity: 1000 snap: 0 invert: 0 type: 0 axis: 0 joyNum: 0 - serializedVersion: 3 m_Name: LSH descriptiveName: XBox Controller Axis 'Left Stick Horizontal'. descriptiveNegativeName: negativeButton: positiveButton: altNegativeButton: altPositiveButton: gravity: 0 dead: 0.19 sensitivity: 1 snap: 0 invert: 0 type: 2 axis: 0 joyNum: 0 - serializedVersion: 3 m_Name: LSV descriptiveName: XBox Controller Axis 'Left Stick Vertical'. descriptiveNegativeName: negativeButton: positiveButton: altNegativeButton: altPositiveButton: gravity: 0 dead: 0.19 sensitivity: 1 snap: 0 invert: 1 type: 2 axis: 1 joyNum: 0 - serializedVersion: 3 m_Name: RSH descriptiveName: XBox Controller Axis 'Right Stick Horizontal'. descriptiveNegativeName: negativeButton: positiveButton: altNegativeButton: altPositiveButton: gravity: 0 dead: 0.19 sensitivity: 1 snap: 0 invert: 0 type: 2 axis: 3 joyNum: 0 - serializedVersion: 3 m_Name: RSV descriptiveName: XBox Controller Axis 'Right Stick Vertical'. descriptiveNegativeName: negativeButton: positiveButton: altNegativeButton: altPositiveButton: gravity: 0 dead: 0.19 sensitivity: 1 snap: 0 invert: 1 type: 2 axis: 4 joyNum: 0 - serializedVersion: 3 m_Name: DPadH descriptiveName: XBox Controller Axis 'D-Pad Horizontal'. descriptiveNegativeName: negativeButton: positiveButton: altNegativeButton: altPositiveButton: gravity: 0 dead: 0.19 sensitivity: 1 snap: 0 invert: 0 type: 2 axis: 5 joyNum: 0 - serializedVersion: 3 m_Name: DPadV descriptiveName: XBox Controller Axis 'D-Pad Vertical'. descriptiveNegativeName: negativeButton: positiveButton: altNegativeButton: altPositiveButton: gravity: 0 dead: 0.19 sensitivity: 1 snap: 0 invert: 0 type: 2 axis: 6 joyNum: 0 - serializedVersion: 3 m_Name: LT descriptiveName: XBox Controller Axis 'Left Trigger'. descriptiveNegativeName: negativeButton: positiveButton: altNegativeButton: altPositiveButton: gravity: 0 dead: 0.19 sensitivity: 1 snap: 0 invert: 0 type: 2 axis: 8 joyNum: 0 - serializedVersion: 3 m_Name: RT descriptiveName: XBox Controller Axis 'Right Trigger'. descriptiveNegativeName: negativeButton: positiveButton: altNegativeButton: altPositiveButton: gravity: 0 dead: 0.19 sensitivity: 1 snap: 0 invert: 0 type: 2 axis: 9 joyNum: 0 - serializedVersion: 3 m_Name: Trigger descriptiveName: XBox Controller Axis 'Shared Trigger'. descriptiveNegativeName: negativeButton: positiveButton: altNegativeButton: altPositiveButton: gravity: 0 dead: 0.19 sensitivity: 1 snap: 0 invert: 0 type: 2 axis: 2 joyNum: 0 - serializedVersion: 3 m_Name: Horizontal descriptiveName: Keyboard Axis 'Horizontal'. descriptiveNegativeName: negativeButton: left positiveButton: right altNegativeButton: a altPositiveButton: d gravity: 3 dead: 0.001 sensitivity: 3 snap: 1 invert: 0 type: 0 axis: 0 joyNum: 0 - serializedVersion: 3 m_Name: Vertical descriptiveName: Keyboard Axis 'Vertical'. descriptiveNegativeName: negativeButton: down positiveButton: up altNegativeButton: s altPositiveButton: w gravity: 3 dead: 0.001 sensitivity: 3 snap: 1 invert: 0 type: 0 axis: 1 joyNum: 0 - serializedVersion: 3 m_Name: Horizontal descriptiveName: XBox Controller Axis 'Horizontal'. descriptiveNegativeName: negativeButton: positiveButton: altNegativeButton: altPositiveButton: gravity: 0 dead: 0.19 sensitivity: 1 snap: 0 invert: 0 type: 2 axis: 0 joyNum: 0 - serializedVersion: 3 m_Name: Vertical descriptiveName: XBox Controller Axis 'Vertical'. descriptiveNegativeName: negativeButton: positiveButton: altNegativeButton: altPositiveButton: gravity: 0 dead: 0.19 sensitivity: 1 snap: 0 invert: 1 type: 2 axis: 1 joyNum: 0