js code :
[code lang=”js”]
<script>
var unity = null;
var has_no_unity;
function GetUnity() {
if (typeof unityObject != "undefined") {
return unityObject.getObjectById("unityPlayer");
}
return null;
}
function updateAssetBundleVersion() { //unity call it
if (unity != null) unity.SendMessage("Game","SetAssetBundleVersion","<?php echo $server_version;?>");
}
function startGame() {
if (unity != null) {
unity.SendMessage("Game","StartMyGame","<?php echo $StartMyGame;?>");
}
}
function startgame_la(game_width,game_height){
if (typeof unityObject != "undefined") {
//var game_width = 1280;
// var game_height = 720;
var params = {
disableContextMenu: true,
disableFullScreen : false,
textcolor: ‘ffffff’,
backgroundcolor: ‘000000’,
bordercolor: ‘000000’,
progressframeimage: "http://static2.mengjiagames.com/mengjiagames/gameweb/Tpl/default/sgs/images/WebLoadingBar_Prog7.png",//背景
progressbarimage: "http://static2.mengjiagames.com/mengjiagames/gameweb/Tpl/default/sgs/images/WebLoadingBar_Prog_red7.png",//前景
logoimage: "http://static2.mengjiagames.com/mengjiagames/gameweb/Tpl/default/sgs/images/2013_4_1_logo.png",
autoupdateURL : "http://wp-china.unity3d.com/autodownload_webplugin-3.x",
autoupdateURLSignature :"02a5f78b3066d7d31fb063186a2eec36fdf1205d49c6b0808eb37ef85ed9902e2e1904d87f599238a802ba0abbfe4f18aa82dd2eb5171e99ba839a5cea9e6ea9c1be9eae505937b56fe4a5fd254cffe08958d961f42d970136b5eab9e6c2cd08b81bc8a11e5ade57dc63dcfef2248d89689e4d4feed3cdfe7374c848fd57ebd4"
};
unityObject.setBaseDownloadUrl("http://wp-china.unity3d.com/download_webplayer-3.x/");
unityObject.enableJavaInstall(false);//ie浏览器启用的自动安装,此方法禁止java安装方式,否则点击后会出现java安全提示。
unityObject.enableGoogleAnalytics(false);
unityObject.embedUnity("unityPlayer", "<?php echo $server_clienturl;?>", game_width, game_height,params,"",function(obj){
if (obj.success) {
unity = unityObject.getObjectById(obj.id);
}else{
has_no_unity = true;
}
});
}
}
function reLoadUnity()//插件安装完成后自动开始游戏 add by shanmao
{
if (has_no_unity) return;
var unity_obj = GetUnity();
if (!unity_obj)
{
startgame_la(1280,720);
}
}
startgame_la(1280,720);//开始游戏。
setTimeout(‘reLoadUnity()’, 4000);
</script>
[/code]
IE自动安装提示:点击后是一个安装url如:(http://wp-china.unity3d.com/download_webplayer-3.x/3.0/co/UnityWebPlayer.application?installer=http%3A%2F%2Fwp-china.unity3d.com%2Fdownload_webplayer-3.x%2FUnityWebPlayer.exe)
IEjava安装提示:点击的是一个javascript:java(); 执行一个java方法。
自定义安装图片,和下载链接:
js code:
[code]
function check_unity_down(){//added by shanmao
var img = $("#unityPlayer").find("img");
if((img.attr("src")=="http://webplayer.unity3d.com/installation/getunity.png" && img.attr("id")=="unityPlayer_img") || img.attr("src")=="http://wp-china.unity3d.com/installation/getunity.png"){
var sbody = ‘<a href="http://wp-china.unity3d.com/download_webplayer-3.x/UnityWebPlayer.exe" title="点击下载安装unity插件!" ><img src="http://static2.mengjiagames.com/mengjiagames/gameweb/Tpl/default/sgs/img4_14/Unityins.jpg" width="1000" height="673" border="0"></a>’;
$("#unityPlayer").css({background:"#000","text-align":"center"}).html(sbody);
}
}
setTimeout("check_unity_down()",1000);
[/code]