index.html 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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="videoBox">
  28. <video src="./myCode/video.mp4" controls muted></video>
  29. <div class="skipTxt">跳 过</div>
  30. </div>
  31. <!-- 分享海报 -->
  32. <div class="shareBox">
  33. <img src="./StreamingAssets/share.png" alt="">
  34. <div class="shareTit">长按图片保存</div>
  35. <div class="shareBtn">关闭</div>
  36. </div>
  37. <script>
  38. let unityExamples = null
  39. window.addEventListener("load", function () {
  40. if ("serviceWorker" in navigator) {
  41. navigator.serviceWorker.register("ServiceWorker.js");
  42. }
  43. });
  44. var container = document.querySelector("#unity-container");
  45. var canvas = document.querySelector("#unity-canvas");
  46. var loadingBar = document.querySelector("#unity-loading-bar");
  47. var progressBarFull = document.querySelector("#unity-progress-bar-full");
  48. var warningBanner = document.querySelector("#unity-warning");
  49. // Shows a temporary message banner/ribbon for a few seconds, or
  50. // a permanent error message on top of the canvas if type=='error'.
  51. // If type=='warning', a yellow highlight color is used.
  52. // Modify or remove this function to customize the visually presented
  53. // way that non-critical warnings and error messages are presented to the
  54. // user.
  55. function unityShowBanner(msg, type) {
  56. function updateBannerVisibility() {
  57. warningBanner.style.display = warningBanner.children.length ? 'block' : 'none';
  58. }
  59. var div = document.createElement('div');
  60. div.innerHTML = msg;
  61. warningBanner.appendChild(div);
  62. if (type == 'error') div.style = 'background: red; padding: 10px;';
  63. else {
  64. if (type == 'warning') div.style = 'background: yellow; padding: 10px;';
  65. setTimeout(function () {
  66. warningBanner.removeChild(div);
  67. updateBannerVisibility();
  68. }, 5000);
  69. }
  70. updateBannerVisibility();
  71. }
  72. var buildUrl = "Build";
  73. var loaderUrl = buildUrl + "/ChangZhouHospital_2.1.loader.js";
  74. var config = {
  75. dataUrl: buildUrl + "/ChangZhouHospital_2.1.data.unityweb",
  76. frameworkUrl: buildUrl + "/ChangZhouHospital_2.1.framework.js.unityweb",
  77. codeUrl: buildUrl + "/ChangZhouHospital_2.1.wasm.unityweb",
  78. streamingAssetsUrl: "StreamingAssets",
  79. companyName: "DefaultCompany",
  80. productName: "ChangZhouHospital",
  81. productVersion: "1.1",
  82. showBanner: unityShowBanner,
  83. };
  84. // By default Unity keeps WebGL canvas render target size matched with
  85. // the DOM size of the canvas element (scaled by window.devicePixelRatio)
  86. // Set this to false if you want to decouple this synchronization from
  87. // happening inside the engine, and you would instead like to size up
  88. // the canvas DOM size and WebGL render target sizes yourself.
  89. // config.matchWebGLToCanvasSize = false;
  90. if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
  91. // Mobile device style: fill the whole browser client area with the game canvas:
  92. var meta = document.createElement('meta');
  93. meta.name = 'viewport';
  94. meta.content = 'width=device-width, height=device-height, initial-scale=1.0, user-scalable=no, shrink-to-fit=yes';
  95. document.getElementsByTagName('head')[0].appendChild(meta);
  96. }
  97. loadingBar.style.display = "block";
  98. var script = document.createElement("script");
  99. script.src = loaderUrl;
  100. script.onload = () => {
  101. createUnityInstance(canvas, config, (progress) => {
  102. progressBarFull.style.width = 100 * progress + "%";
  103. }).then((unityInstance) => {
  104. loadingBar.style.display = "none";
  105. // 兼容苹果手机,移除视频dom
  106. setTimeout(() => {
  107. const videoBox = document.querySelector('.videoBox')
  108. if (videoBox) document.querySelector('body').removeChild(videoBox)
  109. }, 500);
  110. // 把unity的实例保存起来
  111. unityExamples = unityInstance
  112. // 隐藏加载中文字
  113. document.querySelector('#lodingTxt').style.display = 'none'
  114. }).catch((message) => {
  115. alert(message);
  116. });
  117. };
  118. document.body.appendChild(script);
  119. </script>
  120. <!-- 引入自己的js -->
  121. <script src="./myCode/index.js"></script>
  122. </body>
  123. </html>