UpdateメソッドとFixedUpdateメソッドの開始時に、1フレームごとにOVRInput.Update()とOVRInput.FixedUpdate()をそれぞれ追加します。以下はその例です。public class XRInputManager : MonoBehaviour {
void Update() {
OVRInput.Update();
// Handle input logic here
}
void FixedUpdate() {
OVRInput.FixedUpdate();
// Handle physics-based input here
}
}
InputManager.asset構成ファイルで参照できます。Get(): ボタン、軸、タッチセンサーの現在の状態を返しますGetDown(): ボタンがこのフレームで押されたかどうかを返しますGetUp(): ボタンがこのフレームで離されたかどうかを返しますif (OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger, OVRInput.Controller.RTouch)) {
// Trigger pressed on right controller
}
OVRManager.display.RecenterPose()を使用して、コントローラーとヘッドセットのポーズを現在の位置にリセットします。GetLocalControllerPosition(): 位置をVector3で返しますGetLocalControllerRotation(): 向きをQuaternionで返しますPrimary: 左コントローラーSecondary: 右コントローラーGet()のバリエーションが用意されています。以下が含まれます。| コントロール | 列挙 |
|---|---|
OVRInput.Button | ゲームパッドやコントローラーに付いた従来型のボタン、戻るボタン。 |
OVRInput.Touch | コントローラーの静電容量反応式コントロールサーフェス。 |
OVRInput.NearTouch | コントローラーの接近反応式コントロールサーフェス。 |
OVRInput.Axis1D | 浮動小数点の状態を報告するトリガーなどの、1次元コントロール。 |
OVRInput.Axis2D | サムスティックなどの2次元コントロール。Vector2の状態を報告します。 |
| コントロール |
|---|
OVRInput.RawButton |
OVRInput.RawTouch |
OVRInput.RawNearTouch |
OVRInput.RawAxis1D |
OVRInput.RawAxis2D |
Touch)、そして接近(NearTouch)したことを感知する静電容量反応式コントロールサーフェスを備えています。これにより、特定のコントロールサーフェスとのユーザーのインタラクションの複数の状態を明確に感知することができます。例えば、ユーザーの人差し指がコントロールサーフェスから完全に離れたとき、そのコントロールのNearTouchはfalseを報告します。ユーザーの指がコントロールに近づき、接近した状態になると、指が物理的に接触する前にNearTouchはtrueを報告します。ユーザーが物理的に接触すると、そのコントロールのTouchはtrueを報告します。ユーザーがインデックストリガーを押すと、そのコントロールのButtonはtrueを報告します。明確に区別されるこれらの状態は、ユーザーとコントローラーのインタラクションを正確に感知し、さまざまなコントロールスキームを可能にします。// returns true if the primary button (typically “A”) is currently pressed. OVRInput.Get(OVRInput.Button.One); // returns true if the primary button (typically “A”) was pressed this frame. OVRInput.GetDown(OVRInput.Button.One); // returns true if the “X” button was released this frame. OVRInput.GetUp(OVRInput.RawButton.X); // returns a Vector2 of the primary (typically the Left) thumbstick’s current state. // (X/Y range of -1.0f to 1.0f) OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick); // returns true if the primary thumbstick is currently pressed (clicked as a button) OVRInput.Get(OVRInput.Button.PrimaryThumbstick); // returns true if the primary thumbstick has been moved upwards more than halfway. // (Up/Down/Left/Right - Interpret the thumbstick as a D-pad). OVRInput.Get(OVRInput.Button.PrimaryThumbstickUp); // returns a float of the secondary (typically the Right) index finger trigger’s current state. // (range of 0.0f to 1.0f) OVRInput.Get(OVRInput.Axis1D.SecondaryIndexTrigger); // returns a float of the left index finger trigger’s current state. // (range of 0.0f to 1.0f) OVRInput.Get(OVRInput.RawAxis1D.LIndexTrigger); // returns true if the left index finger trigger has been pressed more than halfway. // (Interpret the trigger as a button). OVRInput.Get(OVRInput.RawButton.LIndexTrigger); // returns true if the secondary gamepad button, typically “B”, is currently touched by the user. OVRInput.Get(OVRInput.Touch.Two);
Get()は、コントロールを指定するだけでなく、任意のコントローラーパラメーターも取得します。サポートされるコントローラーのリストは、OVRInputのコントローラーのリストのセクションで定義されています。Get()にコントローラーパラメーターを指定しない場合、最後にユーザー入力を報告したActiveコントローラーがデフォルトで使用されます。例えば、ユーザーがコントローラーのペアを使用しているときに、それを下に置き、Xboxコントローラーを手に取ると、ユーザーが入力を提供したときにアクティブコントローラーがXboxコントローラーへと切り替わります。現在のアクティブなコントローラーのクエリには<OVRInput.GetActiveController()を使用でき、接続されているすべてのコントローラーのビットマスクのクエリにはOVRInput.GetConnectedControllers()を使用できます。// returns a float of the hand trigger's current state on the left controller. OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, OVRInput.Controller.Touch); // returns a float of the hand trigger's current state on the right controller. OVRInput.Get(OVRInput.Axis1D.SecondaryHandTrigger, OVRInput.Controller.Touch);
OVRInput.Controller.Touchを使用して)組み合わせたペアとして指定することも、(OVRInput.Controller.LTouchとRTouchを使用して)個別に指定することもできます。LTouchかRTouchかを指定することでバーチャル入力マッピングの異なるセットが使用され、手に依存しない入力コードの開発がさらに便利になるので、これは重要です。PrimaryHandTriggerを個々のコントローラーで使うことにより、手の関与しないインプットを示しています。ここで、Primaryは常に指定された手にマッピングされます。// returns a float of the hand trigger's current state on the left controller. OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, OVRInput.Controller.LTouch); // returns a float of the hand trigger's current state on the right controller. OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, OVRInput.Controller.RTouch);
// public variable that can be set to LTouch or RTouch in the Unity Inspector public OVRInput.Controller controller; // returns a float of the hand trigger’s current state on the controller // specified by the controller variable. OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, controller); // returns true if the primary button (“A” or “X”) is pressed on the controller // specified by the controller variable. OVRInput.Get(OVRInput.Button.One, controller);
OVRInput.Controller.Touchでコントローラーに組み合わせたペアとしてアクセスする場合、バーチャルマッピングは左右の手に分けられた典型的なゲームパッドのレイアウトとほぼ一致しています。
OVRInput.Controller.LTouchまたはOVRInput.Controller.RTouchでアクセスする場合、バーチャルマッピングが変わり、手に依存しない入力バインディングが可能になります。例えば、どの手に装着されているかに応じて、同じスクリプトが動的に左または右のコントローラーをクエリできます。Button.Oneは状況に応じてAまたはXボタンにマッピングされます。
