unity制作html游戏,Unity与HTML通信

Unity Manual>Advanced>Web PlayerDeployment > Unity Web Playerand browser communication

Unity手册->高级->web播放器部署-> Unity WEB播放器和浏览器通信

Unity Web Player and browser communication Unity WEB播放器和浏览器通信

The HTML page that contains Unity Web Playercontent can communicate with that content and vice versa. Basically there aretwo communication directions:

HTML页面,其中包含Unity Web播放的内容可以通信的内容,反之亦然。基本上有两种通信方向:

1.The web page calls functions inside theUnity web player content.

该网页内调用Unityweb播放器内容内部的功能。

2.The Unity web player content callsfunctions in the web page.

Unity web播放器的内容调用功能在在web页中。

Eachof these communication directions is described in more detail below.

这些通信方向的每一个详细描述如下。

Calling Unity web player content functionsfrom the web page

从web页面调用Unity web播放器内容

The Unity Web Player plugin and ActiveX Controls bothhave a function,SendMessage(), that can be called from a web page inorder to call functions within Unity web player content. This function is verysimilar to theGameObject.SendMessagefunction in the Unity scripting API. When called from a web page you pass anobject name, a function name and a single argument, andSendMessage()will call the given function in the given game object.

在Unity的Web Player插件和ActiveX控件都有一个函数,SendMessage(),可以从网页上一个web页面被调用,为了调用Unity web播放器内容内部功能。这个功能是非常类似于GameObject.SendMessage函数在Unity脚本API里。当从所谓的网页上你传递一个对象的名称,一个函数名和一个简单参数,和SendMessage()将调用给定的函数在在给定对象的游戏里。

Inorder to call the Unity Web Player'sSendMessage() function you mustfirst get a reference to the Unity web player content object being displayed.You can use JavaScript'sdocument object and its getElementById()function to obtain a reference to the content. Here is an example JavaScriptfunction that would execute theSendMessage() function on the Unity webplayer content with an object/embed tag id value ofUnityContent; inturn SendMessage() will then call the functionMyFunction() onthe game object namedMyObject, passing a piece of string data as anargument:

为了调用Unity Web播放器的SendMessage()函数必须先得到网站的Unity播放器内容对象的一个引用被显示出来。你可以使用JavaScript的文档对象和getElementById()函数来获取对内容的引用。下面是一个JavaScript示例函数将利用object/ embed标签的UnityContent id值在Unityweb播放器内容上执行SendMessage()函数,然后反过来SendMessage()将会调用函数调用MyFunction()在游戏对象名称上的MyObject来传递的一个字符串数据作为参数:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值