web嵌入unity,传输协议

   <div id="unity-container" class="unity-desktop">
                                      <canvas id="unity-canvas" width=960 height=600></canvas>
                                      <div id="unity-loading-bar">
                                          <div id="unity-logo"></div>
                                          <div id="unity-progress-bar-empty">
                                              <div id="unity-progress-bar-full"></div>
                                          </div>
                                      </div>
                                      <div id="unity-warning"> </div>
                                  </div>

js

 var container = document.querySelector("#unity-container");
    var canvas = document.querySelector("#unity-canvas");
    var loadingBar = document.querySelector("#unity-loading-bar");
    var progressBarFull = document.querySelector("#unity-progress-bar-full");
    var warningBanner = document.querySelector("#unity-warning");
    function unityShowBanner(msg, type) {
        function updateBannerVisibility() {
            warningBanner.style.display = warningBanner.children.length ? 'block' : 'none';
        }
        var div = document.createElement('div');
        div.innerHTML = msg;
        warningBanner.appendChild(div);
        if (type == 'error') div.style = 'background: red; padding: 10px;';
        else {
            if (type == 'warning') div.style = 'background: yellow; padding: 10px;';
            setTimeout(function() {
                warningBanner.removeChild(div);
                updateBannerVisibility();
            }, 5000);
        }
        updateBannerVisibility();
    }
    var buildUrl = "../unity/Build";
    var loaderUrl = buildUrl + "/prize.asm.loader.js";
    var config = {
        dataUrl: buildUrl + "/prize.data",
        frameworkUrl: buildUrl + "/prize.asm.framework.js",
        codeUrl: buildUrl + "/prize.asm.js",
        memoryUrl: buildUrl + "/prize.asm.mem",
        streamingAssetsUrl: "StreamingAssets",
        companyName: "DefaultCompany",
        productName: "JW_Qiu",
        productVersion: "0.1",
        showBanner: unityShowBanner,
    };
    if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
        container.className = "unity-mobile";
        config.devicePixelRatio = 1;
        unityShowBanner('WebGL builds are not supported on mobile devices.');
    } else {
        canvas.style.width = "960px";
        canvas.style.height = "600px";
    }
    loadingBar.style.display = "block";

    var script = document.createElement("script");
    script.src = loaderUrl;
    var instance;
    script.onload = () => {
        createUnityInstance(canvas, config, (progress) => {
            progressBarFull.style.width = 100 * progress + "%";
        }).then((unityInstance) => {
            loadingBar.style.display = "none";
            instance = unityInstance;

        }).catch((message) => {
            alert(message);
        });
    };
    document.body.appendChild(script);
    //添加发射经纬度数据格式
    function jsonStringify(x1,y1,x2,y2){
        var jsonData = {};
        var jwS = {},jwE = {};
        jwS.x =x1*1;
        jwS.y = y1*1;
        jwE.x = x2*1;
        jwE.y = y2*1;
        jsonData.jwS = jwS;
        jsonData.jwE = jwE;
        jsonData.time = 6.000;
        jsonData.id = 1;
        jsonData.type = 'AddDD';
        var jsonStr = JSON.stringify(jsonData);
        return jsonStr
    }
    //添加防护罩 (classify,0防护罩,1目标)
    function fhzStringify(x1,y1,scale,classify){
        var jsonData = {};
        var jw = {};
        jw.x =x1*1;
        jw.y = y1*1;
        jsonData.jw = jw;
        jsonData.scale = scale*1;//半径
        jsonData.id = 1;
        jsonData.classify = classify*1;
        jsonData.type = 'AddObj';
        var jsonStr = JSON.stringify(jsonData);
        return jsonStr
    }

    //添加锥体
    //{"jw":{"x":123.0,"y":23.0},"id":1,"contour":{"x":500.0,"y":200.0},"angle":{"x":45.0,"y":0.0,"z":45.0},"alpha":1.000,"type":"AddCone"}
    function tjzt(x1,y1,x2,y2,x3,y3,z3){
        var jsonData = {};
        var jw = {};
        jw.x =x1*1;
        jw.y = y1*1;
        jsonData.jw = jw;
        jsonData.id = 1;
        var contour ={};
        contour.x =x2*1;                //高度(长度)
        contour.y = y2*1;               //最外圈半径
        jsonData.contour = contour;
        var angle ={};
        angle.x =x3*1;                  //角度
        angle.y = y3*1;                 //y轴不变
        angle.z = z3*1;
        jsonData.angle = angle;
        jsonData.alpha =0.1;            //透明度 建议0.2-0.5
        jsonData.type = 'AddCone';
        var jsonStr = JSON.stringify(jsonData);
        return jsonStr
    }
    //添加追踪型锥体
    //{"jw":{"x":74.0,"y":49.0},"id":1,"fllowdd":0,"height":500.0,"scale":50}
    function zzzt(x1,y1){
        var jsonData = {};
        var jw = {};
        jw.x =x1*1;
        jw.y = y1*1;
        jsonData.jw = jw;
        jsonData.id = 1;
        jsonData.fllowdd = 0;
        jsonData.height =500;
        jsonData.scale = 50;
        jsonData.type = 'AddFllowCone';
        var jsonStr = JSON.stringify(jsonData);
        return jsonStr
    }
    //当地球加载完毕。
    function onStart(){
        // instance.SendMessage("UnityFace","Message", tjzt(123,23,500,200,45,0,45));
        $.ajax({
            url: '/zhModel/survey/queryPowerList',
            success: function (res) {
                for (var i = 0; i < res.length; i++) {
                    var latitude = res[i].latitude*1
                    var longitude = res[i].longitude*1
                    var radius = res[i].radius*1
                    var isRun= res[i].isRun*1
                    if(isRun==2){
                        // console.log(latitude,longitude,10,1)
                        //instance.SendMessage("UnityFace","Message",fhzStringify(longitude,latitude,10,1));
                    }else if(isRun==1) {
                        // console.log(latitude, longitude, radius, 0)
                        //instance.SendMessage("UnityFace", "Message", fhzStringify(longitude,latitude , radius, 0));
                        //y 45°为正上方,90°为向西45°,135°为向西0°
                        instance.SendMessage("UnityFace","Message", tjzt(longitude,latitude,400,200,90,45,45));
                    }
                }
            }
        });
         //instance.SendMessage("UnityFace","Message",jsonStringify(45,23,-168,66));
    }
    //不明物体被侦测到发出预警
    function onYujing(str)
    {
        console.log(str)
        if(str!=""){
$("#bbwt").show();
        }

    }

    //发射不明物体
    $("#fs").click(function () {
        var fslongitude = $("#fslongitude").val();
        var fslatitude =$("#fslatitude").val();
        var mblongitude = $("#mblongitude").val();
        var mblatitude =$("#mblatitude").val();
        debugger
        instance.SendMessage("UnityFace","Message",jsonStringify(fslongitude,fslatitude,mblongitude,mblatitude));
    })
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值