Unity Asset Storeからダウンロード
https://assetstore.unity.com/packages/tools/integration/oculus-integration-82022
My Assetsに追加した後、UnityでWindow > Package Manager
に行って、左上のPackages:
のドロップダウンをPackages: My Assets
にして、Oculus Integrationをインポートする。
Unityのメニューからedit > Project Settings > XR Plug-in Management
に行って、Install XR Plug-in Management
ボタンを押す。
XR Plug-in Managementメニューが見えたらOculusのところにチェックを付けるで完成。
Project ViewでAssets > Oculus > VR > Prefabs
からOVRCameraRigのPrefabを引っ張ってHierarchy Viewに置く。
Assets > Oculus > VR > Prefabs
に行って、
OVRPlayerControllerをシーンに追加して、それからOVRControllerPrefabの中に使いたいコントローラーのPrefabを取って(Projectビューに置く)、シーンにあるOVRPlayerControllerの中に左と右コントローラーのPrefabをOVRCameraRig > LeftHandAnchor > LeftControllerAnchor
とOVRCameraRig > RightHandAchor > RightControllerAnchor
に追加する。
コントローラーの位置を取得
// Vector3
OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch)
// Quarternion
OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch)
コントローラーの操作の例
//A ボタンを押すと何かする
if(OVRInput.GetDown(OVRInput.RawButton.A)) {
//何かする
}
プレイヤーの下にPlaneがないとプレイヤーが落下してしまう可能性がある。プレイヤーが落下したらコントローラー・手はぐちゃぐちゃになる。
コントローラー操作 https://framesynthesis.jp/tech/unity/touch/
弾を打つ https://answers.unity.com/questions/1105218/how-to-make-an-object-shoot-a-projectile.html