<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                本文章由cartzhang編寫,轉載請注明出處。 所有權利保留。 文章鏈接:[http://blog.csdn.net/cartzhang/article/details/50419709](http://blog.csdn.net/cartzhang/article/details/50419709) 作者:cartzhang ### Unity 的OCulus VR開發遇到的坑—OC版本差異 ### 一、關于Unity和Oculus插件版本 針對Unity的Oculus開發,Oculus官方給出了官方插件,不同的Unity版本,對應不同的插件版本,但是在使用中,發現有些不同或是bug. Oculus的Unity 插件官方地址:[https://developer.oculus.com/doc/0.1.0.0-unity/index.html](https://developer.oculus.com/doc/0.1.0.0-unity/index.html) 我作為Unity新人,沒有用過Unity5之前的任何版本,不熟悉任何操作。所以,就根據官方推薦,使用了5.1.1版本,然后根據官方版本對應推薦,果斷選擇下載了PC端的OC的0.6.0.1版本,對應的Unity開發工具當時是下載的0.010beta版本。 官方推薦的各個版本對應的runtime表: [https://developer.oculus.com/documentation/game-engines/latest/concepts/unity-sdk-version-compatibility/](https://developer.oculus.com/documentation/game-engines/latest/concepts/unity-sdk-version-compatibility/) 問題是,根據游戲情節要求,需要在某個時刻或場景下鎖定頭盔,不能讓它轉動了。(先說需要,關于需求是否合理,這個下次接著再說)。 ### 二、初步了解插件 首先,先初步了解下插件啊。 下載完畢插件,建立個Unity空項目,拖拽到工程下,可以看到導入后,在資源目錄下如圖: ![Unity OC插件導入](https://box.kancloud.cn/2016-03-09_56dfda86e2375.jpg "") 在prefabs下有三個預制,而在0.4.4或0.4.2版本下有兩個預制。 ![插件預制體](https://box.kancloud.cn/2016-03-09_56dfda87011eb.jpg "") 就是實現不讓頭盔來回旋轉,這個鎖定相機就好了嘛,很簡單啊。關鍵是找對地方,代碼修改一下,就搞定了。結果并不如我想象。 ### 三、說的容易 要找的代碼速度找到,OC插件的重要使用腳本文件有三個, ~~~ ?OVRCameraRig head tracking and stereo rendering. Exposes the user's head pose with "anchor" bones. ?OVRPlayerController Represents a standing user and enables locomotion in the world. ?OVRManager A singleton that exposes the VR configuration and status to Unity. ~~~ 要實現鎖定相機,并不是要在Update中實時的給相機的旋轉角度賦值為某個值的過程。 要是真這么實現,會有什么影響么? 答案是肯定的。鎖不住,你動下,它就動下,來回晃。 我只需要OVRCameraRig.cs文件的一個函數就可以,找到函數: ~~~ private void UpdateAnchors() { bool monoscopic = OVRManager.instance.monoscopic; OVRPose tracker = OVRManager.tracker.GetPose(0d); trackerAnchor.localRotation = tracker.orientation; centerEyeAnchor.localRotation = VR.InputTracking.GetLocalRotation(VR.VRNode.CenterEye); leftEyeAnchor.localRotation = monoscopic ? centerEyeAnchor.localRotation : VR.InputTracking.GetLocalRotation(VR.VRNode.LeftEye); rightEyeAnchor.localRotation = monoscopic ? centerEyeAnchor.localRotation : VR.InputTracking.GetLocalRotation(VR.VRNode.RightEye); trackerAnchor.localPosition = tracker.position; centerEyeAnchor.localPosition = VR.InputTracking.GetLocalPosition(VR.VRNode.CenterEye); leftEyeAnchor.localPosition = monoscopic ? centerEyeAnchor.localPosition : VR.InputTracking.GetLocalPosition(VR.VRNode.LeftEye); rightEyeAnchor.localPosition = monoscopic ? centerEyeAnchor.localPosition : VR.InputTracking.GetLocalPosition(VR.VRNode.RightEye); if (UpdatedAnchors != null) { UpdatedAnchors(this); } } ~~~ 在OVRCameraRig.cs文件的122行附近。 怎么辦呢?寫個變量來控制,就是在外面加個if判斷,屏蔽掉所有代碼即可。 結果,是然并卵。 ### 四、做著難,咋就不行呢 我迅速的郁悶了。 各種糾結和嘗試之后,卸載OC,重新安裝0.4.4版本。我回退了我的OC插件版本,重建工程,使用了0.4.4版本的插件,同樣的文件,同樣的函數,同樣操作,奇跡就發生了。 附0.4.4版本的OVRCameraRig.cs文件的UpdateAnchors函數: ~~~ private void UpdateAnchors() { OVRPose leftEye = OVRManager.display.GetEyePose(OVREye.Left); OVRPose rightEye = OVRManager.display.GetEyePose(OVREye.Right); leftEyeAnchor.localRotation = leftEye.orientation; centerEyeAnchor.localRotation = leftEye.orientation; // using left eye for now rightEyeAnchor.localRotation = rightEye.orientation; leftEyeAnchor.localPosition = leftEye.position; centerEyeAnchor.localPosition = 0.5f * (leftEye.position + rightEye.position); rightEyeAnchor.localPosition = rightEye.position; } ~~~ 那還有什么好說的。輕松實現了,鎖定頭盔,在場景中,你不可以亂看的效果(非常規的反人類的操作!) 就只好使用0.4.4來湊合吧!! ### 五、實踐是檢驗標準 總結: 在OC開發工程中,要時刻記得OC runtime版本與插件版本相配套。 上面這個結果的出現,可能是OC runtime版本的問題,但是也排除不了插件實現問題,比方說,用錯了接口,使用了當前OC版本之前的兼容版本接口,而OC內部怎么實現的,我一概不知啊! “0.1.0”–對應的OC 0.6 .0版本有19個接口,不算兼容的老的接口。 0.4.4—對應OC的0.4.4版本,接口實現有57個左右。 我只能說,接口對0.6.0,精簡了,但是我相信大的基礎功能肯定都是有的。 怎么才能避免跳入這樣的坑呢?沒有辦法,只有嘗試。 ### 六、其他 遇到老板提這么怪異的VR問題怎么解決? 下回再說吧!! 若有問題,請隨時聯系! 非常感謝!!!
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看