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

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

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

Unity Manual>Advanced>Web Player Deployment>Detecting the Unity Web Player using browser scripting

Unity手册->高级->web播放器部署->使用浏览脚本检测Unity WEB播放器

Any time you build and post Web Player content you should take steps to ensure the end-user has the Unity Web Player before attempting to display the content. While the default HTML file generated when you publish web player content contains a noembed tag for the cases where the end-user doesn't have the player, that tag isn't used or displayed consistently across all browsers and fails to offer a consistent and predictable user experience. Therefore instead of relying on the browser's handling of the noembed tag you can use browser script to determine whether the end-user has the Unity Web Player installed and respond appropriately.

任何时候你建立和发送web播放器内容,你应该采取步骤,确保最终用户有Unity Web播放器在尝试显示内容之前。虽然默认的HTML文件生成当你发布web播放器内容时包含一个noembed标签的情况下最终用户那里没有播放器,该标记是不被使用或通过所有浏览器一贯的显示和不能提供一个一致的可预见的用户体验。因此,替代依赖浏览器的noembed的标签处理,你可以使用浏览器的脚本来确定是否最终用户拥有Unity Web播放器安装,并采取适当的响应。

Detecting the Unity Web Player in all browsers can be done using a combination of JavaScript and VBScript browser code. The process of detecting the web player involves the following steps:

在所有浏览器里检测Unity Web播放器可以做到使用一个JavaScript和VBScript浏览器代码组合。在检测web播放器包括以下步骤:

*       Browser Detection: is the page being viewed on Windows using Microsoft Internet Explorer or some other browser?

*       浏览器检测:是正在浏览的网页上使用Microsoft Internet Explorer或其他浏览器窗口?

*       ActiveX Control Detection: If the page is being viewed on Windows in Internet Explorer, is the web player's ActiveX Control installed?

*       ActiveX控件检测:如果web 被浏览在Windows Internet Explorer中,它的网页播放器的ActiveX控件是是否安装?

*       Plugin Detection: if the page is being viewed in any other browser, is the mime type understood and the plugin installed?

*       插件检测:如果网页被任何其他浏览器中查看,是mime类型理解和插件安装?

Here is an example JavaScript and VBScript function that performs the above steps in order to detect the Unity Web Player:

这里有一个例子JavaScript和VBScript函数执行上述步骤,以检测Unity Web播放器:

<script language='VBScript'>

function detectUnityWebPlayerActiveX

    on error resume next

    dim tControl, res, ua, re, matches, major

    res = 0

    set tControl = CreateObject("UnityWebPlayer.UnityWebPlayer.1")

    if IsObject(tControl) then

        if tControl.GetPluginVersion() = "2.5.0f5" then

            ' 2.5.0f5 on Vista and later has an auto-update issue

            ' on Internet Explorer. Detect Vista (6.0 or later)

            ' and in that case treat it as not installed

            ua = Navigator.UserAgent

            set re = new RegExp

            re.Pattern = "Windows NT (d+)."

            set matches = re.Execute(ua)

            if matches.Count = 1 then

                major = CInt(matches(0).SubMatches(0))

                if major < 6 then

                    res = 1

                end if

            end if

        else

            res = 1

        end if

    end if

    detectUnityWebPlayerActiveX = res

end function

</script>

<script language="javascript1.1" type="text/javascript">

function detectUnityWebPlayer () {

    var tInstalled = false;

    if (navigator.appVersion.indexOf("MSIE") != -1 &&

        navigator.appVersion.toLowerCase().indexOf("win") != -1)

    {

        tInstalled = detectUnityWebPlayerActiveX();

    }

    else if (navigator.mimeTypes && navigator.mimeTypes["application/vnd.unity"])

    {

        if (navigator.mimeTypes["application/vnd.unity"].enabledPlugin &&

            navigator.plugins && navigator.plugins["Unity Player"])

        {

            tInstalled = true;     

        }

    }        

    return tInstalled;

}

</script>

When the function above is called, it checks for the Unity Web Player and returns a boolean value as a result. A return value of true indicates that the Unity Web Player is installed whereas a return value of false indicates that it is not. The HTML file generated by Unity when building web player contains a very similar function.

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