index.html 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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>无尽藏</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. <link rel="stylesheet" href="./index.css">
  11. </head>
  12. <body>
  13. <div id="unity-container">
  14. <canvas id="unity-canvas" tabindex="-1"></canvas>
  15. <div id="unity-loading">
  16. <img id="unity-loading-bg" src="./TemplateData/bg_game.png" alt="" />
  17. <img id="unity-loading-paper" src="./TemplateData/img_paper.png" alt="" />
  18. <img id="unity-loading-brush" src="./TemplateData/img_brush.png" alt="" />
  19. <img id="unity-loading-progress" src="./TemplateData/progress.png" alt="" />
  20. <span id="unity-loading-progress-text"></span>
  21. </div>
  22. <div id="unity-warning"> </div>
  23. </div>
  24. <script>
  25. window.addEventListener("load", function () {
  26. if ("serviceWorker" in navigator) {
  27. navigator.serviceWorker.register("ServiceWorker.js");
  28. }
  29. });
  30. let container = document.querySelector("#unity-container");
  31. let canvas = document.querySelector("#unity-canvas");
  32. let warningBanner = document.querySelector("#unity-warning");
  33. // Shows a temporary message banner/ribbon for a few seconds, or
  34. // a permanent error message on top of the canvas if type=='error'.
  35. // If type=='warning', a yellow highlight color is used.
  36. // Modify or remove this function to customize the visually presented
  37. // way that non-critical warnings and error messages are presented to the
  38. // user.
  39. function unityShowBanner(msg, type) {
  40. function updateBannerVisibility() {
  41. warningBanner.style.display = warningBanner.children.length ? 'block' : 'none';
  42. }
  43. let
  44. div = document.createElement('div');
  45. div.innerHTML = msg;
  46. warningBanner.appendChild(div);
  47. if (type == 'error') div.style = 'background: red; padding: 10px;';
  48. else {
  49. if (type == 'warning') div.style = 'background: yellow; padding: 10px;';
  50. setTimeout(function() {
  51. warningBanner.removeChild(div);
  52. updateBannerVisibility();
  53. }, 5000);
  54. }
  55. updateBannerVisibility();
  56. }
  57. let buildUrl = "Build";
  58. let loaderUrl = buildUrl + "/Build.loader.js";
  59. let config = {
  60. dataUrl: buildUrl + "/Build.data.unityweb",
  61. frameworkUrl: buildUrl + "/Build.framework.js.unityweb",
  62. codeUrl: buildUrl + "/Build.wasm.unityweb",
  63. streamingAssetsUrl: "StreamingAssets",
  64. companyName: "4Dage",
  65. productName: "H5Game-NanjingMuseum",
  66. productVersion: "1.0.6",
  67. showBanner: unityShowBanner,
  68. };
  69. // By default Unity keeps WebGL canvas render target size matched with
  70. // the DOM size of the canvas element (scaled by window.devicePixelRatio)
  71. // Set this to false if you want to decouple this synchronization from
  72. // happening inside the engine, and you would instead like to size up
  73. // the canvas DOM size and WebGL render target sizes yourself.
  74. // config.matchWebGLToCanvasSize = false;
  75. if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
  76. // Mobile device style: fill the whole browser client area with the game canvas:
  77. let meta = document.createElement('meta');
  78. meta.name = 'viewport';
  79. meta.content = 'width=device-width, height=device-height, initial-scale=1.0, user-scalable=no, shrink-to-fit=yes';
  80. document.getElementsByTagName('head')[0].appendChild(meta);
  81. }
  82. let isShowLoading = true;
  83. const loadingDom = document.querySelector('#unity-loading');
  84. const loadingPaperDom = document.querySelector('#unity-loading-paper');
  85. const loadingBrushDom = document.querySelector('#unity-loading-brush');
  86. const loadingBgDom = document.querySelector('#unity-loading-bg');
  87. const progressDom = document.querySelector('#unity-loading-progress');
  88. const progressText = document.querySelector('#unity-loading-progress-text');
  89. progressText.innerHTML = "0%";
  90. let opacity = 1;
  91. function fadeOutVideo(){
  92. if (opacity > 0) {
  93. setTimeout(function() {
  94. opacity = opacity - 0.05;
  95. progressDom.style.opacity = opacity;
  96. loadingPaperDom.style.opacity = opacity;
  97. loadingBrushDom.style.opacity = opacity;
  98. loadingBgDom.style.opacity = opacity;
  99. fadeOutVideo();
  100. }, 20)
  101. } else {
  102. window.removeEventListener('resize', refreshLoadingPaperBlockSize);
  103. loadingDom.remove();
  104. }
  105. }
  106. let script = document.createElement("script");
  107. script.src = loaderUrl;
  108. script.onload = () => {
  109. createUnityInstance(canvas, config, (progress) => {
  110. progressText.innerHTML = parseInt(progress * 100) + "%";
  111. }).then((unityInstance) => {
  112. window.unityInstance = unityInstance;
  113. fadeOutVideo();
  114. }).catch((message) => {
  115. alert(message);
  116. });
  117. };
  118. document.body.appendChild(script);
  119. function refreshLoadingPaperBlockSize() {
  120. // Unity画布宽高比
  121. const unityCanvasWidth = 1920;
  122. const unityCanvasHeight = 1080;
  123. const unityPanelWidth = 650;
  124. const unityPanelHeight = 1098;
  125. const unityPanelOffsetY = 35;
  126. const unityPanelOffsetX = 0;
  127. const unityPanelBrushWidth = 462;
  128. const unityPanelBrushHeight = 608;
  129. const unityPanelBrushOffsetY = -115;
  130. const unityPanelBrushOffsetX = 555;
  131. const innerWidth = window.innerWidth;
  132. const innerHeight = window.innerHeight;
  133. const scale = (unityCanvasWidth / unityPanelHeight) >
  134. (innerWidth / innerHeight) ? (innerWidth / unityCanvasWidth) : (innerHeight / unityCanvasHeight);
  135. loadingPaperDom.style.width = (unityPanelWidth * scale) + 'px';
  136. loadingPaperDom.style.height = (unityPanelHeight * scale) + 'px';
  137. loadingBrushDom.style.width = (unityPanelBrushWidth * scale) + 'px';
  138. loadingBrushDom.style.height = (unityPanelBrushHeight * scale) + 'px';
  139. if (unityPanelOffsetY > 0) {
  140. loadingPaperDom.style.marginTop = (unityPanelOffsetY * scale * 2) + 'px';
  141. } else {
  142. loadingPaperDom.style.marginBottom = (-unityPanelOffsetY * scale * 2) + 'px';
  143. }
  144. if (unityPanelOffsetX > 0) {
  145. loadingPaperDom.style.marginLeft = (unityPanelOffsetX * scale * 2) + 'px';
  146. } else {
  147. loadingPaperDom.style.marginRight = (-unityPanelOffsetX * scale * 2) + 'px';
  148. }
  149. if (unityPanelBrushOffsetY > 0) {
  150. loadingBrushDom.style.marginTop = (unityPanelBrushOffsetY * scale * 2) + 'px';
  151. } else {
  152. loadingBrushDom.style.marginBottom = (-unityPanelBrushOffsetY * scale * 2) + 'px';
  153. }
  154. if (unityPanelBrushOffsetX > 0) {
  155. loadingBrushDom.style.marginLeft = (unityPanelBrushOffsetX * scale * 2) + 'px';
  156. } else {
  157. loadingBrushDom.style.marginRight = (-unityPanelBrushOffsetX * scale * 2) + 'px';
  158. }
  159. }
  160. refreshLoadingPaperBlockSize();
  161. window.addEventListener('resize', refreshLoadingPaperBlockSize);
  162. </script>
  163. <script src="./index.js"></script>
  164. </body>
  165. </html>