1不包含index_c3840.html 以及main.cs
替换UI
进入到webgl\TemplateData 文件夹下
1.修改style.css
如下
.webgl-content * {border: 0; margin: 0; padding: 0}
.webgl-content {position: absolute; top: 50%; left: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%);}
.webgl-content .logo, .progress {position: absolute; left: 50%; top: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%);}
.webgl-content .progress {height: 38px; width: 280px; margin-top: 90px;}
.webgl-content .progress .empty {background: url('progressEmpty.Light.png') no-repeat right / cover; float: right; width: 100%; height: 100%; display: inline-block;}
.webgl-content .progress .full {background: url('progressFull.Light.png') no-repeat left / cover; float: left; width: 0%; height: 100%; display: inline-block;}
.webgl-content .progress.Dark .empty {background-image: url('progressEmpty.Dark.png');}
.webgl-content .progress.Dark .full {background-image: url('progressFull.Dark.png');}
.webgl-content .footer {margin-top: 5px; height: 38px; line-height: 38px; font-family: Helvetica, Verdana, Arial, sans-serif; font-size: 18px;}
.webgl-content .footer .webgl-logo, .title, .fullscreen {height: 100%; display: inline-block; background: transparent center no-repeat;}
.webgl-content .footer .webgl-logo {background-image: url('webgl-logo.png'); width: 204px; float: left;}
.webgl-content .footer .title {margin-right: 10px; float: right;}
.webgl-content .footer .fullscreen {background-image: url('fullscreen.png'); width: 38px; float: right;}
2.修改UnityProgress.js
如下
function UnityProgress(unityInstance, progress) {
if (!unityInstance.Module)
return;
if (!unityInstance.logo) {
unityInstance.logo = document.createElement("div");
unityInstance.logo.className = "logo " + unityInstance.Module.splashScreenStyle;
unityInstance.container.appendChild(unityInstance.logo);
}
if (!unityInstance.progress) {
unityInstance.progress = document.createElement("div");
unityInstance.progress.className = "progress " + unityInstance.Module.splashScreenStyle;
unityInstance.progress.empty = document.createElement("div");
unityInstance.progress.empty.className = "empty";
unityInstance.progress.appendChild(unityInstance.progress.empty);
unityInstance.progress.full = document.createElement("div");
unityInstance.progress.full.className = "full";
unityInstance.progress.appendChild(unityInstance.progress.full);
unityInstance.container.appendChild(unityInstance.progress);
}
unityInstance.progress.full.style.width = (100 * progress) + "%";
unityInstance.progress.empty.style.width = (100 * (1 - progress)) + "%";
if (progress == 1)
unityInstance.logo.style.display = unityInstance.progress.style.display = "none";
}
3.加入新的js代码类Equips /EquipDoc
class Equips {
constructor(id) {
this.id = id;
}
//判断 所有设备
GetMyEquipMap() {
var map = new Map();
return map;
}
//视频点位对应的视频地址
GetVideoInfo() {
var map = new Map();
//192.168.30.199 公司iP
// 现场iP
let nowIp = "192.168.92.10";
map.set("209A-1F监控摄像头01", "http://" + nowIp + ":8888/hk46/stream.m3u8");//46
return map;
}
//获取隐面ip
GetYMIp() {
return "http://192.168.30.199:1889/#/view/";
}
//是否是S4平台
//对应url
//对应的工装或设备界面url
GetMyMap() {
var map = new Map();
map.set("S1-LF", { Is209Platform: "1", EquipUrl: "1798537918864805889" });
return map;
}
//获取视频流对应地址
GetVideoRtsp(str) {
var map = this.GetVideoInfo();
console.log("GetVideoRtsp", str);
if (map.has(str)) {
return map.get(str);
}
else {
return "";
}
}
GetIsContainEquip(str) {
var map = this.GetMyEquipMap();
console.log("GetIsContainEquip", str);
if (map.has(str)) {
return "1";
}
else {
return "0";
}
}
}
export { Equips };
class EquipDoc {
constructor(id) {
this.id = id;
}
// 获取所有物体对应设备编码
GetDocMap() {
let url_P="http://192.168.30.199:1889/#/view/";
var map = new Map();
map.set("S1-LF", url_P+"");
return map;
}
}
export { EquipDoc };
加入main.js
import { Equips } from './TemplateData/Equips.js';
import { EquipDoc } from './TemplateData/EquipDoc.js';
//let myEquipManager = new Equips(100);
//console.log("456",myEquipManager);
//myEquipManager.FindEquip("?");
主要作用就是,将TemplateData文件加下新增文件导入进来,方便调用
html中的最终调用
在html 的 “module”中将 自己新增的两个类 Equips 以及EquipDoc导入到当前代码块中
通过window代码指定Equips和EquipDoc
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Unity WebGL Player | DS_Insight_Viewer</title>
<link rel="shortcut icon" href="TemplateData/favicon.ico">
<link rel="stylesheet" href="TemplateData/style.css">
<script src="TemplateData/UnityProgress.js"></script>
<script src="Build/UnityLoader.js"></script>
<script type="module">
import { Equips } from './TemplateData/Equips.js';
import { EquipDoc } from './TemplateData/EquipDoc.js';
window.equipsFromModule = Equips;
window.equipDocFromModule = EquipDoc;
window.addEventListener('message', function (e) {
console.log("xa消息", e.data);
unityInstance.SendMessage("HtmlMessage", "ReceiveHtmlMessage", JSON.stringify(e.data));
});
var unityInstance = UnityLoader.instantiate("unityContainer", "Build/webgl.json", { onProgress: UnityProgress });
</script>
<script>
function ReceiveUnityMessage(str) {
console.log("收到 Unity 消息: " + str);
var data = JSON.parse(str);
if (!data || !data.主题名称) {
console.error("收到空消息");
return;
}
let msg = {
type: "webGl",
time: Date.now(),
}
let myequips = new window.equipsFromModule(100);
let myequipDoc = new window.equipDocFromModule(101);
if (data.主题名称 == "登录") {
msg.data = [
{
flag: "left",
data: myequips.GetYMIp() + "1800458624120692737",
method: "changeIframe"
},
{
flag: "right",
data: myequips.GetYMIp() + "1800463754467516417",
method: "changeIframe"
},
{
flag: "top",
data: myequips.GetYMIp() + "1775422564135383041",
method: "changeIframe"
},
{
flag: "bottom",
data: myequips.GetYMIp() + "1775422842511339522",
method: "changeIframe"
},
]
}
else if (data.主题名称.search("监控") != -1) {
msg.data = [
{
flag: "whole",
data: myequips.GetYMIp() + "1770730214117126146",
method: "changeIframe"
},
{
"method": "writeVariable",
"data": [
{
"key": "url",
"value": myequips.GetVideoRtsp(data.主题名称),//"https://sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/hls/xgplayer-demo.m3u8"
"type": ""
}
]
}
]
}
else {
let IsContain = myequips.GetIsContainEquip(data.主题名称);
console.log(IsContain);
//是设备 钻孔设备属于设备 其他属于工装,钻孔设备尚未提供
if (IsContain == "1") {
}
//全部都是工装
else {
let isS4 = myequips.GetMyMap().get(data.主题名称).Is209Platform;
console.log(isS4);
let docMap = myequipDoc.GetDocMap();
// s4工装
if (isS4 == 1) {
console.log("s42");
msg.data = [
{
flag: "leftSmall",
data: "",
method: "changeIframe"
},
{
flag: "left",
data: myequips.GetYMIp() + myequips.GetMyMap().get(data.主题名称).EquipUrl,
method: "changeIframe"
},
{
flag: "right",
data: myequips.GetYMIp() + "1788137204145516545",
method: "changeIframe"
},
{
flag: "top",
data: myequips.GetYMIp() + "1768545351616221186",
method: "changeIframe"
},
{
flag: "bottom",
data: myequips.GetYMIp() + "1768533642419687426",
method: "changeIframe"
},
{
flag: "small",
data: myequips.GetYMIp() + "1788751319549407233",
method: "changeIframe"
}
,
{
"method": "writeVariable",
"data": [
{
"key": "equipId",
"value": data.主题名称,
"type": "global"
}
]
}
]
}
//s5工装
else {
console.log("s52");
msg.data = [
{
flag: "leftSmall",
data: "",
method: "changeIframe"
},
{
flag: "left",
data: myequips.GetYMIp() + myequips.GetMyMap().get(data.主题名称).EquipUrl,
method: "changeIframe"
},
{
flag: "right",
data: myequips.GetYMIp() + "1788137204145516545",
method: "changeIframe"
},
{
flag: "top",
data: myequips.GetYMIp() + "1768545351616221186",
method: "changeIframe"
},
{
flag: "bottom",
data: myequips.GetYMIp() + "1768533709172035586",
method: "changeIframe"
},
{
flag: "small",
data: myequips.GetYMIp() + "1788751319549407233",
method: "changeIframe"
}
,
{
"method": "writeVariable",
"data": [
{
"key": "equipId",
"value": data.主题名称,
"type": "global"
}
]
}
]
}
}
}
console.log("msg:", msg)
// 向隐面发送消息, 隐面会执行 iframe 的切换
if (msg.data) {
window.parent.postMessage(JSON.stringify(msg), '*');
}
}
</script>
</head>
<body>
<div class="webgl-content" style="width: 100%; height: 100%;overflow-y: hidden;">
<div id="unityContainer" style="width: 100%; height: 100%"></div>
</div>
</body>
</html>