unitywebGL使用

找到目录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 ;
}

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值