如何在Three.js场景中包含OVRManager? [英] How to include OVRManager in Three.js Scene?

查看:213
本文介绍了如何在Three.js场景中包含OVRManager?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在新的Oculus Go中创建了几个正在尝试的Three.js/Javascript演示应用程序.我试图使Go Controller能够在我的应用程序中执行操作,根据Oculus开发人员中心的说法,最好的办法是在场景中包含OVRManager,以便我可以访问该API.听起来不错,但对于所有文档( https://developer .oculus.com/documentation/unity/latest/concepts/unity-ovrinput/)我看不到如何将OVRManager添加到场景中!我以前没有使用过Unity,但是从文档中可以看出,应该没有任何兼容性问题(应该吗?)

I have created several Three.js/Javascript demo applications that I'm experimenting with in my new Oculus Go. I'm trying to enable the Go Controller to do stuff in my applications, and according to the Oculus Developer Center, the best thing to do is to include OVRManager in my scene so I have access to that API. That sounds good, but for all the documentation (https://developer.oculus.com/documentation/unity/latest/concepts/unity-ovrinput/) I can't see HOW to add OVRManager to my scene! I have not worked with Unity before, but from what I can tell in the documentation there shouldn't be any compatibility issues (should there?)

所以我想做的事情是这样的:

So what I'd think to do is something like:

<script src="OVRManager.js or something like that"></script>

然后调用所需的函数,就像我对OrbitControls.js和其他外部依赖项所做的那样.

and then call the functions I need, as I've done with OrbitControls.js and other external dependencies.

但是对于我一生来说,Google搜索只是将我发送到圈子中.我看到针对C ++和C#提出的问题,但这对我没有用.如何在Three.js场景中使用此API?我在哪里找到它,还有其他方法可以包含它吗?

But for the life of me, Google searching is just sending me in circles. I see questions posed for C++ and C# but that's of no use to me. How do I get this API working in my Three.js scene? Where do I find it and is there some other way to include it?

谢谢!

推荐答案

创建一个统一的WebGL构建,并在附加到GameObject的Unity脚本中公开所需的API作为公共方法.

Create a unity WebGL build and expose the API you need as public methods in a Unity Script you attach to a GameObject.

然后,您应该能够按照如何从中调用Unity函数的指示进行操作javascript (在下面复制)中,介绍如何从javascript代码中调用这些方法.

Then, you should be able to follow the directions at How to call Unity functions from javascript (copied below) on how to call those methods from your javascript code.

如果使用旧版本的Unity,则可以使用与JavaScript大致相似的UnityScript编写脚本.在撰写本文时,Oculus 推荐认为的版本2017.4.11f1可能仍支持UnityScript.

You may be able to use UnityScript, which is vaguely similar to JavaScript, to write the Script if you use an old version of Unity. As of this writing, Oculus recommends version 2017.4.11f1, which I think might still support UnityScript.

看到如此少的UnityScript信息的主要原因之一是,Unity已经从UnityScript转移到仅支持C#.

One major reason you see so much less UnityScript information is that Unity has been moving away from UnityScript, into only supporting C#.

但是无论您是用C#还是UnityScript编写OVRManager脚本, Unity都可以从JavaScript中调用这些方法.

But regardless of if you code your OVRManager script in C# or UnityScript, Unity will make the methods callable from your JavaScript.

从JavaScript调用Unity脚本功能

有时您需要向Unity发送一些数据或通知 浏览器的JavaScript中的脚本.推荐的做法 是在您内容中的GameObject上调用方法.如果你正在做 来自嵌入在您的项目中的JavaScript插件的调用,您可以 使用以下代码:

Calling Unity scripts functions from JavaScript

Sometimes you need to send some data or notification to the Unity script from the browser’s JavaScript. The recommended way of doing it is to call methods on GameObjects in your content. If you are making the call from a JavaScript plugin, embedded in your project, you can use the following code:

SendMessage(objectName, methodName, value);

objectName是场景中对象的名称; methodName是 脚本中当前附加到该对象的方法的名称; 值可以是字符串,数字或为空.例如:

Where objectName is the name of an object in your scene; methodName is the name of a method in the script, currently attached to that object; value can be a string, a number, or can be empty. For example:

SendMessage('MyGameObject', 'MyFunction');
SendMessage('MyGameObject', 'MyFunction', 5);

SendMessage('MyGameObject', 'MyFunction', 'MyString');

如果您想从全球范围内拨打电话 嵌入页面,请参见下面的代码可见性"部分.

If you would like to make a call from the global scope of the embedding page, see the Code Visibility section below.

从Unity 5.6开始,所有构建代码均独立执行 范围.这种方法可以将您的游戏嵌入到 任意页面,而不会与嵌入页面代码产生冲突, 并可以将多个版本嵌入到同一版本中 页面.

Starting from Unity 5.6 all the build code is executed in its own scope. This approach makes it possible to embed your game on an arbitrary page without causing conflicts with the embedding page code, as well as makes it possible to embed more than one build on the same page.

如果您拥有所有.jslib插件形式的JavaScript代码 在您的项目中,然后此JavaScript代码将在 与已编译的版本具有相同的作用域,您的代码应该可以正常工作 与以前的Unity版本相同(例如, 以下对象和功能应直接从 JavaScript插件代码:Module,SendMessage,HEAP8,ccall等).

If you have all your JavaScript code in the form of .jslib plugins inside your project, then this JavaScript code will run inside the same scope as the compiled build and your code should work pretty much the same way as in previous versions of Unity (for example, the following objects and functions should be directly visible from the JavaScript plugin code: Module, SendMessage, HEAP8, ccall etc.).

但是,如果您打算调用内部JavaScript函数 在嵌入页面的全局范围内,您应始终假设 页面上嵌入了多个内部版本,因​​此您应该 明确指定您要引用的内部版本.例如,如果 您的游戏已被实例化为:

However, if you are planning to call the internal JavaScript functions from the global scope of the embedding page, you should always assume that there are multiple builds embedded on the page, so you should explicitly specify which build you are referencing to. For example, if your game has been instantiated as:

var gameInstance = UnityLoader.instantiate("gameContainer", "Build/build.json", {onProgress: UnityProgress});

然后您可以使用以下命令向构建发送消息 gameInstance.SendMessage(),或使用以下命令访问构建模块对象 gameInstance.Module.

Then you can send a message to the build using gameInstance.SendMessage(), or access the build Module object using gameInstance.Module.

这篇关于如何在Three.js场景中包含OVRManager?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆