找到目录Build下面的UnityLoader.js文件,并且在文件中找到以下代码,注释原来代码并修改如下:
1.修改提示框
compatibilityCheck:function(e,t,r){
UnityLoader.SystemInfo.hasWebGL?
UnityLoader.SystemInfo.mobile?
t()
:["Firefox","Chrome","Safari"].indexOf(UnityLoader.SystemInfo.browser)==-1?
t()
:t()
:e.popup("Your browser does not support WebGL",[{text:"OK",callback:r}])
},
// compatibilityCheck:function(e,t,r){
// UnityLoader.SystemInfo.hasWebGL?
// UnityLoader.SystemInfo.mobile?
// e.popup("Please note that Unity WebGL is not currently supported on mobiles. Press OK if you wish to continue anyway.",[{text:"OK",callback:t}])
// :["Firefox","Chrome","Safari"].indexOf(UnityLoader.SystemInfo.browser)==-1?
// e.popup("Please note that your browser is not currently supported for this Unity WebGL content. Press OK if you wish to continue anyway.",[{text:"OK",callback:t}])
// :t()
// :e.popup("Your browser does not support WebGL",[{text:"OK",callback:r}])
// },
Blobs:{},loa...(省略)
2. 修改进度条
在文件夹下TemplateData→style.css替换掉progress**的图片
3.替换背景:
在json文件下,将"backgroundColor": "blue",改为"backgroundUrl": "yang.GIF",
Hbuilder解决谷歌跨域:运行-运行配置-参数栏输入:
--disable-web-security --user-data-dir=C:\Program Files (x86)\Google\Chrome\Application\Chrome
后台配置跨域,加上这两行代码就好啦:
@RequestMapping(value = "",method = RequestMethod.POST)
response.setHeader("Access-Control-Allow-Origin", "*");
<script type="text/javascript">
$(document).ready(function(){
var Request = location.search;
var id = Request.substring(1, Request.length)
/*var id = 2*/
loadDataUpdate(id)
});
/* window.alert = function(str){
return ;
}*/
var gameInstance = UnityLoader.instantiate("gameContainer", "Build/H5Demo.json", {onProgress: UnityProgress});
function testSend()
{
gameInstance.SendMessage("Home", "getJsData", "datasd");
}
function myfunction(){
alert("可执行")
}
function loadDataUpdate(id){
$.ajax({
url:"http://localhost:8080/后台方法",
type:"post",
data:{id:id},
datatype:"json",
success:function (data){
var html="";
var piyin = data.data;
/*html=html+"<img class='avatar' src='"+piyin.avatar+"'/>";
$("#avatar").html(html);*/
alert(piyin)
},
error:function(error){
console.log(error);
}
});
}
</script>
解决跨域问题最后是后端来做:
Hbuilder解决谷歌跨域:运行-运行配置-参数栏输入:
--disable-web-security --user-data-dir=C:\Program Files (x86)\Google\Chrome\Application\Chrome
java后台解决跨域:
@RequestMapping(value = "方法名",method = RequestMethod.POST)
@ResponseBody
public MymusicVo models(String id, HttpServletResponse response){
/*Integer mymusicid = Integer.valueOf(map.get("id"));*/
/*Integer mymusicid = 2;*/
int ids = Integer.valueOf(2);
MymusicVo music = mymusicService.fenxiang(ids);
response.setHeader("Access-Control-Allow-Origin", "*");//解决js跨域问题
return music ;
}