model.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <!DOCTYPE html>
  2. <html lang="en-us">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <title>常中e大观园</title>
  7. <link rel="shortcut icon" href="TemplateData/favicon.ico">
  8. <link rel="stylesheet" href="TemplateData/style.css">
  9. <link rel="manifest" href="manifest.webmanifest">
  10. <!-- 引用自己的样式 -->
  11. <link rel="stylesheet" href="./myCode/style.css">
  12. </head>
  13. <body>
  14. <div id="unity-container">
  15. <canvas id="unity-canvas" tabindex="-1"></canvas>
  16. <div id="unity-loading-bar">
  17. <div id="unity-logo"></div>
  18. <div id="unity-progress-bar-empty">
  19. <div id="unity-progress-bar-full"></div>
  20. </div>
  21. </div>
  22. <div id="unity-warning"> </div>
  23. </div>
  24. <!-- 加载中文字 -->
  25. <div id="lodingTxt">加载中...</div>
  26. <!-- 分享海报 -->
  27. <div class="shareBox">
  28. <img src="./StreamingAssets/share.png" alt="">
  29. <div class="shareTit">长按图片保存</div>
  30. <div class="shareBtn">关闭</div>
  31. </div>
  32. <script>
  33. if(window.innerWidth>=500){
  34. document.querySelector('.shareTit').innerHTML='点击鼠标右键保存'
  35. }
  36. let unityExamples = null
  37. window.addEventListener("load", function () {
  38. if ("serviceWorker" in navigator) {
  39. navigator.serviceWorker.register("ServiceWorker.js");
  40. }
  41. });
  42. var container = document.querySelector("#unity-container");
  43. var canvas = document.querySelector("#unity-canvas");
  44. // 动态设置 canvas的 宽高
  45. canvas.width=window.innerWidth>=500?500:window.innerWidth
  46. canvas.height =window.innerHeight
  47. var loadingBar = document.querySelector("#unity-loading-bar");
  48. var progressBarFull = document.querySelector("#unity-progress-bar-full");
  49. var warningBanner = document.querySelector("#unity-warning");
  50. // Shows a temporary message banner/ribbon for a few seconds, or
  51. // a permanent error message on top of the canvas if type=='error'.
  52. // If type=='warning', a yellow highlight color is used.
  53. // Modify or remove this function to customize the visually presented
  54. // way that non-critical warnings and error messages are presented to the
  55. // user.
  56. function unityShowBanner(msg, type) {
  57. function updateBannerVisibility() {
  58. warningBanner.style.display = warningBanner.children.length ? 'block' : 'none';
  59. }
  60. var div = document.createElement('div');
  61. div.innerHTML = msg;
  62. warningBanner.appendChild(div);
  63. if (type == 'error') div.style = 'background: red; padding: 10px;';
  64. else {
  65. if (type == 'warning') div.style = 'background: yellow; padding: 10px;';
  66. setTimeout(function () {
  67. warningBanner.removeChild(div);
  68. updateBannerVisibility();
  69. }, 5000);
  70. }
  71. updateBannerVisibility();
  72. }
  73. var buildUrl = "Build";
  74. var loaderUrl = buildUrl + "/ChangZhouHospital_2.4.loader.js";
  75. var config = {
  76. dataUrl: buildUrl + "/ChangZhouHospital_2.4.data.unityweb",
  77. frameworkUrl: buildUrl + "/ChangZhouHospital_2.4.framework.js.unityweb",
  78. codeUrl: buildUrl + "/ChangZhouHospital_2.4.wasm.unityweb",
  79. streamingAssetsUrl: "StreamingAssets",
  80. companyName: "DefaultCompany",
  81. productName: "ChangZhouHospital",
  82. productVersion: "1.2",
  83. showBanner: unityShowBanner,
  84. };
  85. // By default Unity keeps WebGL canvas render target size matched with
  86. // the DOM size of the canvas element (scaled by window.devicePixelRatio)
  87. // Set this to false if you want to decouple this synchronization from
  88. // happening inside the engine, and you would instead like to size up
  89. // the canvas DOM size and WebGL render target sizes yourself.
  90. // config.matchWebGLToCanvasSize = false;
  91. if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
  92. // Mobile device style: fill the whole browser client area with the game canvas:
  93. var meta = document.createElement('meta');
  94. meta.name = 'viewport';
  95. meta.content = 'width=device-width, height=device-height, initial-scale=1.0, user-scalable=no, shrink-to-fit=yes';
  96. document.getElementsByTagName('head')[0].appendChild(meta);
  97. }
  98. loadingBar.style.display = "block";
  99. var script = document.createElement("script");
  100. script.src = loaderUrl;
  101. script.onload = () => {
  102. createUnityInstance(canvas, config, (progress) => {
  103. progressBarFull.style.width = 100 * progress + "%";
  104. }).then((unityInstance) => {
  105. loadingBar.style.display = "none";
  106. // 把unity的实例保存起来
  107. unityExamples = unityInstance
  108. // 隐藏加载中文字
  109. document.querySelector('#lodingTxt').style.display = 'none'
  110. }).catch((message) => {
  111. alert(message);
  112. });
  113. };
  114. document.body.appendChild(script);
  115. </script>
  116. <!-- 引入自己的js -->
  117. <script src="./myCode/index.js"></script>
  118. </body>
  119. </html>