Unity3D高级手册0905:使用浏览脚本检测Unity WEB播放器

2014-09-28 19:34:46|?次阅读|上传:wustguangh【已有?条评论】发表评论

关键词:游戏, 虚拟现实, Unity3D|来源:唯设编程网

当上面的函数被调用,它检查Unity Web播放器并返回一个布尔值结果。返回的值为真表明Unity web播放器是安装的,而返回一个假值表明没有安装。当编译web播放器包含一个非常类似的功能时,通过Unity生成HTML文件。

The detection is performed separately for Internet Explorer and all the other browsers:

该检测是为Internet Explorer和所有其他的浏览器分别执行的:

*       For IE, a VBScript snippet is used. VBScript is used instead of JavaScript because after detection it releases the plugin resource immediately (whereas in JavaScript it would only happen the next time garbage collection is performed). The script tries to create an ActiveX object named "UnityWebPlayer.UnityWebPlayer.1" which is the name of Unity Web Player ActiveX control.

*       对于IE,一个VBScript代码段使用。 VBScript是用来代替JavaScript,因为在检查它之后立即释放插件资源(而在JavaScript中仅发生下一次垃圾收集完成时)。该脚本尝试创建一个ActiveX对象名为“UnityWebPlayer.UnityWebPlayer.1”,这是Unity 的Web Player ActiveX控件的名称。

*       For other browsers it is checked whether a MIME type "application/vnd.unity" is understood and plugin named "Unity Player" is installed and enabled.

*       对于其它浏览器,这是检查是否一个MIME类型“application/ vnd.unity”是理解以及插件名为“Unity player”是安装并启用。

Here is an example of using the function within a HTML page to detect the Unity Web Player and then respond appropriately:

下面是一个使用函数在一个HTML页内部的例子来检测Unity Web播放器以及然后作出适当的反应:

<script type="text/javascript" language="javascript">

<!--

-- check for the Unity Web Player

var tIsInstalled = detectUnityWebPlayer();

if (tIsInstalled)

{

    // write the content object and embed tags

    document.write("<object classid='clsid:444785F1-DE89-4295-863A-D46C3A781394' ");

    document.write("  codebase='http://webplayer.unity3d.com/download_webplayer/UnityWebPlayer.cab#version=2,0,0,0' 
");

    document.write("  id='UnityObject' width='600' height='450' > 
");

    document.write("  <param name='src' value='MyDataFile.unity3d' /> 
");

    document.write("  <embed type='application/vnd.unity' pluginspage='http://www.unity3d.com/unity-web-player-2.x' 
");

    document.write("    id='UnityEmbed' width='600' height='450' src='MyDataFile.unity3d' 
");

    document.write("  /> 
");

    document.write("</object>");

}

else

{

    // write out a simple message prompting the user to install the Unity Web Player

    document.write("<div align='center'> 
");

    document.write("  This content requires the Unity Web Player,");

    document.write("  please use the link below to install the player today:<br /><br />
");

    document.write("  <a href='http://www.unity3d.com/unity-web-player-2.x'> 
");

    document.write("    Install the Unity Web Player 
");

    document.write("  </a> 
");

    document.write("</div> 
");

}

-->

</script>

As you can see the function is used to detect the Unity Web Player, then if the web player is found the required object and embed tags are written into the page. Note that if the web player is not found then a message is displayed prompting the user to install the Unity Web Player.

正如你所看到的函数是用来检测Unity Web播放器,那么如果web播放器找到所需要的object和embed标签被写入到页面中。请注意,如果web播放器没有找到,则显示一条消息,提示用户安装Unity Web播放器。

<12>
发表评论0条 】
网友评论(共?条评论)..
Unity3D高级手册0905:使用浏览脚本检测Unity WEB播放器