Unity3D高级手册0906:发布活动内容(active content)

2014-11-08 12:22:26|?次阅读|上传:huigezrx【已有?条评论】发表评论

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

Unity Manual > Advanced > Web Player Deployment > Publishing active content

Unity手册->高级->web播放器部署->发布活动内容

When publishing active content, like Unity Web Player content, developers must consider how that content will be handled in various browsers. Specifically, developers need to consider how that content will be handled by Microsoft's Internet Explorer browser as it offers slightly different behavior than all other supported browsers today. Depending on how your content is embedded within your web page it may require the end-user to activate the content before it will be sensitive to mouse and keyboard input. In order to activate the content the end-user will have to either click once on the content itself, or click OK in a dialog box to load the ActiveX Control. While this doesn't prevent web player content from being used in Internet Explorer, it does offer a potentially confusing and less than optimal end-user experience. Fortunately, Microsoft has provided page design solutions so that developers can create or update their web pages in such a way that end-users do not have to click to activate web player content. Below you will find details on how to implement one of those solutions.

当发布活动内容时,像Unity的Web播放器内容,开发人员必须考虑如何将这些内容在不同的浏览器处理。具体来说,开发人员需要考虑如何将这些内容通过微软的IE浏览器处理的,因为今天它提供了稍微不同的比其他所有支持的浏览器行为。根据你的内容是如何在你的网页嵌入它可能需要最终用户激活的内容,然后将敏感的鼠标和键盘输入。为了激活内容,最终用户将不得不或者单击一次在对话框中的内容本身,或单击确定以加载ActiveX控件。虽然这并不妨碍在Internet Explorer中使用网络播放的内容,它提供了一个潜在的混乱,不是最佳的最终用户体验。幸运的是,微软提供了网页设计解决方案,使开发人员可以创建或更新这些企业的网页,最终用户不需要点击激活web播放器的内容。下面你会发现就如何落实这些解决方案之一的细节。

For more information on activating ActiveX Controls in Internet Explorer please read Activating ActiveX Controls.

欲了解更多有关激活的Internet Explorer ActiveX控件信息,请阅读激活ActiveX控件。

In order to prevent your end-user from having to activate your Unity Web Player content prior to using it you must use an external JavaScript file to dynamically write the required object tags into your web page at run-time. In order to keep things simple, the solution outlined here will use an external JavaScript file to write both the object and embed tags so the page loads and plays the same in all browsers. In the simplest case you would create an external JavaScript file with a function that when called, writes out the required object and embed tags using document.write() calls.

为了防止你的最终用户不必激活Unity的Web播放器内容使之前用它,你必须使用一个外部JavaScript文件去动态写入所需要的object标签到你的网页里在运行时。为了简单起见,这里列出的解决方案将使用一个外部JavaScript文件写入object及embed标签,以便在页面加载和播放相同在所有的浏览器里。在最简单的情况下,你将创建一个具有函数调用的外部JavaScript文件,编写出需要object和embed标签使用document.write()调用。

Here is an example JavaScript function that uses document.write() calls to dynamically create the necessary object and embed tags:

下面是一个JavaScript示例函数,使用document.write()调用动态创建必要的object和embed标签:


<script type="text/javascript" language="javascript">
function writeUnityTags (aSrc, aWidth, aHeight) {
    // write the content object and embed tags
    document.write("<object ");
    document.write("    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='" + aWidth + "' height='" + aHeight + "'  > 
");
    document.write("    <param name='src' value='" + aSrc + "' /> 
");
    document.write("    <embed type='application/vnd.unity' pluginspage='http://www.unity3d.com/unity-web-player-2.x' 
");
    document.write("        id='UnityEmbed' width='" + aWidth + "' height='" + aHeight + "' src='" + aSrc + "' 
");
    document.write("    /> 
");
    document.write("</object>");
}
</script>

Notice that when the function is called you must pass three arguments, those arguments being the path to the web player data file as well as the width and height of the content to be displayed. Using those arguments the function then writes out the object and embed tags directly into the web page that called the function.

注意,当该函数被调用,您必须传递3个参数,这些参数作为web播放器的数据文件的路径,以及宽度和高度的内容显示。使用这些参数的函数,然后写出到网页调用该函数的object和直接embed标签。

Here is an example of using the writeUnityTags() JavaScript function in a web page, where that function is defined in an external JavaScript file named unityweb.js:

下面是一个使用在一个网页里使用writeUnityTags()JavaScript函数的例子,那个函数被定义子一个外部JavaScript文件名为unityweb.js:


<script type="text/javascript" language="javascript" src="unityweb.js"></script>
<script type="text/javascript" language="javascript">
 
    // call the writeUnityTags function
    writeUnityTags("MyFile.unity3d", 640, 480);
 
</script>

Using an external JavaScript file with a simple function whose sole purpose is to write out the object and embed tags is sufficient to avoid requiring your end-user to activate the content prior to using and interacting with it. Additionally the above solution functions properly in all browsers and therefore implementing it ensures that the end-user experience is consistent regardless of their browser and platform combination.

使用一个简单的函数,其唯一目的是写出object和embed标签外部的JavaScript文件,足以避免要求你的最终用户激活内容之前使用和相互影响。此外,上述解决办法正常运作,在所有的浏览器,因此,执行它确保最终用户的体验是一致的,无论其浏览器和平台组合。

Combining the technique described here along with the web player detection routine discussed in Detecting the Unity Web Player using browser scripting yields a predictable and optimized end-user experience. Here is an example of using both the detectUnityWebPlayer() and writeUnityTags() functions, where both functions are defined in an external JavaScript file named unityweb.js:

结合此处所述的技术随着网络播放器检测例行检测的Unity Web播放器使用浏览器脚本得到,讨论了预测和优化的最终用户体验。下面是一个同时使用detectUnityWebPlayer()和writeUnityTags()函数的例子,如果两个函数都在外部JavaScript文件名为unityweb.js定义:


<script type="text/javascript" language="javascript" src="unityweb.js"></script>
<script type="text/javascript" language="javascript">
 
    // check for the Unity Web Player and respond appropriately
    var tIsInstalled = detectUnityWebPlayer();
    if (tIsInstalled) {
 
        // call the writeUnityTags function
        writeUnityTags("MyFile.unity3d", 640, 480);
 
    } 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>
发表评论0条 】
网友评论(共?条评论)..
Unity3D高级手册0906:发布活动内容(active content)