Top/Devel/OculusRift/ゲームパッド

ゲームパッド の変更点はてなブックマーク


#amazon(B004DL20UU,right)
WindowsのゲームパッドのAPIには旧規格のDirectInputと新規格のXInputがあり、~
[[Oculus Unity Integration>https://developer.oculus.com/downloads/]]付属のOVRGamepadController.csはこのうち%%XInputのみに対応しています。%% ((根拠は[[Oculus Unity Integration Guide>https://developer.oculus.com/documentation/]]の"On Windows systems, the gamepad must be XInput-compliant."という記述です。))~
%%そのため古いゲームパッドでは動作しない可能性があります。%%~
&color(#FF6633){【2015.5.30追記】0.5.0.1まではXInputのみに対応していました。0.6.0.0以降はDirectInputのゲームパッドにも対応しています。};~
&color(#FF6633){ただし、少なくとも現在の0.6.0.0ではエラーが発生してしまいます。解決方法は[[こちら>./#issue0_6_0_0]]。};~
~

Oculus VR社としてはXInput準拠の[[Xbox 360コントローラ>http://www.amazon.co.jp/exec/obidos/ASIN/B004DL20UU/cubic9com-22]]が推奨のようです。~
こちらを利用すれば間違いないでしょう。~
(詳しくは[[Oculus Unity Integration Guide>https://developer.oculus.com/documentation/]]に記述されています。)


*それでもDirectInput仕様のゲームパッドを使いたい
どうしてもDirectInputのみに対応したゲームパッドを使用したい場合、選択肢は2つあります。

~

+x360ceを使ってXInputに見せかける
+Unity標準のInputを使うようにOVRPlayerController.csを書き換える


**x360ceを使ってXInputに見せる
x360ce(XBOX 360 Controller emulator)というソフトで、~
DirectInput仕様のゲームパッドをXInput仕様のゲームパッドのように見せかけることが出来ます。


~

手順は次のとおり。
+アプリをビルドする。
+[[x360ce>https://github.com/x360ce/x360ce]]をダウンロードし、解凍する。
+x360ce.exeを起動する。
+"'x360ce.ini' was not found." "Do you want to create this file?"と聞かれるので、[Yes]をクリックする。
+"'xinput1_3.dll' was not found." "Do you want to create this file?"と聞かれるので、[Yes]をクリックする。
+そのままx360ceでゲームパッドの設定をし、終わったら[Save]をクリックして終了する。
+xinput1_3.dllをxinput9_1_0.dllにリネームする。
+ビルドしたアプリと同フォルダにx360ce.iniとxinput9_1_0.dllを入れる。
+アプリを起動する。

~

私のx360ce.iniの設定は次のようになりました。~
下記は[[JC-U3412S>http://www.amazon.co.jp/exec/obidos/ASIN/B005GY7Z7G/cubic9com-22]]の例です。ゲームパッドの種類によってAxisの番号やボタンの番号は異なります。

#code(,nonumber,nooutline,x360ce.ini)

**Unity標準のInputを使うようにOVRPlayerController.csを書き換える
Unity標準のInputを使うようにOVRPlayerController.csを書き換えてみます。~
下記は[[JC-U3412S>http://www.amazon.co.jp/exec/obidos/ASIN/B005GY7Z7G/cubic9com-22]]の例です。ゲームパッドの種類によってAxisの番号やボタンの番号は異なります。

~

+Unityエディタで[Editor]>[Project Settings]>[Input]を開く。
+Axes配下のSize欄の数字を5増やす。
+Name欄をRightHorizontalとし、Axis欄を3rd axisに設定する。他の項目は既存のHorizontal((Type欄がJoystick Axisの方のHorizontal))と同一にする。
+Name欄をDpadVerticalとし、Axis欄を6th axisに設定する。他の項目は既存のVertical((Type欄がJoystick Axisの方のVertical))と同一にする。
+Name欄をLeftShoulderとし、Positive Button欄をjoystick button 4に設定する。他の項目は既存のFire1((Positive Button欄がjoystick button 0の方のFire1))と同一にする。
+Name欄をRightShoulderとし、Positive Button欄をjoystick button 5に設定する。他の項目は既存のFire1((Positive Button欄がjoystick button 0の方のFire1))と同一にする。
+Name欄をLeftTriggerとし、Positive Button欄をjoystick button 6に設定する。他の項目は既存のFire1((Positive Button欄がjoystick button 0の方のFire1))と同一にする。
+OVRPlayerController.csを開く。
+左スティック部分を下記のように修正する。
--修正前
#code(Csharp,nonumber,nooutline){{
float leftAxisX = OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.LeftXAxis);
float leftAxisY = OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.LeftYAxis);
}}
--修正後
#code(Csharp,nonumber,nooutline){{
float leftAxisX = Input.GetAxis("Horizontal");
float leftAxisY = Input.GetAxis("Vertical");
}}
+右スティック部分を下記のように修正する。
--修正前
#code(Csharp,nonumber,nooutline){{
float rightAxisX = OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.RightXAxis);
}}
--修正後
#code(Csharp,nonumber,nooutline){{
float rightAxisX = Input.GetAxis("RightHorizontal");
}}
+十字キー部分を下記のように修正する。
--修正前
#code(Csharp,nonumber,nooutline){{
if (OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.Up))
}}
--修正後
#code(Csharp,nonumber,nooutline){{
if (Input.GetAxis("DpadVertical") > 0f)
}}
+十字キー部分を下記のように修正する。
--修正前
#code(Csharp,nonumber,nooutline){{
if (OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.Down))
}}
--修正後
#code(Csharp,nonumber,nooutline){{
if (Input.GetAxis("DpadVertical") < 0f)
}}
+LeftShoulder部分を下記のように修正する。
--修正前
#code(Csharp,nonumber,nooutline){{
bool curHatLeft = OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.LeftShoulder);
}}
--修正後
#code(Csharp,nonumber,nooutline){{
bool curHatLeft = Input.GetButton("LeftShoulder");
}}
+RightShoulder部分を下記のように修正する。
--修正前
#code(Csharp,nonumber,nooutline){{
bool curHatRight = OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.RightShoulder);
}}
--修正後
#code(Csharp,nonumber,nooutline){{
bool curHatRight = Input.GetButton("RightShoulder");
}}
+LeftTrigger部分を下記のように修正する。
--修正前
#code(Csharp,nonumber,nooutline){{
moveInfluence *= 1.0f + OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.LeftTrigger);
}}
--修正後
#code(Csharp,nonumber,nooutline){{
if (Input.GetButton("LeftTrigger"))
{
	moveInfluence *= 5f;
}
}}

*Oculus Unity Integration 0.6.0.0を導入するとエラーが出る件の回避策 [#issue0_6_0_0]

Oculus Unity Integration 0.6.0.0を導入すると、OVRGamepadController.csで下記のようなエラーが発生します。

#code(,nonumber,nooutline){{
ArgumentException: Input Button Desktop_Up is not setup.
 To change the input settings use: Edit -> Project Settings -> Input
OVRGamepadController.DefaultReadButton (Button button) (at Assets/OVR/Scripts/Util/OVRGamepadController.cs:292)
OVRGamepadController.GPC_GetButton (Button button) (at Assets/OVR/Scripts/Util/OVRGamepadController.cs:303)
OVRPlayerController.UpdateMovement () (at Assets/OVR/Scripts/Util/OVRPlayerController.cs:226)
OVRPlayerController.Update () (at Assets/OVR/Scripts/Util/OVRPlayerController.cs:174)
}}

原因はOVRGamepadController.csが求める定義がInputManagerにないためです。

~

定義をすれば済むのですが、面倒なので、簡単に導入できるようにしました。

下記をダウンロード、解凍し、ご自分のプロジェクトのフォルダ内のProjectSettingsフォルダ内の"InputManager.asset"ファイルと置き換えてください。

#ref(InputManager_20150520.zip)
(公式フォーラムの[[こちらの投稿>https://forums.oculus.com/viewtopic.php?f=37&t=23388#p272777]]に添付したものと同一です。)

~

もちろんご自分のファイルのバックアップをお忘れなく。

なお、Unity 5.0.2p1で作成したファイルであるため、他のバージョンのUnityでは使用できない可能性があります。

~

また、あくまで回避策であり、恒久的な対処については公式の対応をお待ちください。

*参考
-[[Wikipedia:DirectInput]]
-[[XInput と DirectInput (MSDN)>https://msdn.microsoft.com/ja-jp/library/ee417014(v=vs.85).aspx]]

*Amazon
#amazon(B004DL20UU,left)
#amazon(B00CDG799E,left)
#amazon(B0199DNJHO,left)
#amazon(B00WMCTJW4,left)
#amazon(4798137464,left)
#amazon(479737490X,left)
#amazon(B012VRQX4G,left)
#amazon(B0058QFZYC,left)
#amazon(4091848184,left)


差分 一覧