index.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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/img_bg.jpg" alt="" />
  17. <img id="unity-loading-paper" src="./TemplateData/img_paper.png" alt="" />
  18. <img id="unity-loading-progress" src="./TemplateData/progress.png" alt="" />
  19. <span id="unity-loading-progress-text"></span>
  20. </div>
  21. <div id="unity-warning"> </div>
  22. </div>
  23. <div class="save-image-block">
  24. <img src="" class="save-image-backgroup" alt="">
  25. </div>
  26. <script>
  27. window.addEventListener("load", function () {
  28. if ("serviceWorker" in navigator) {
  29. navigator.serviceWorker.register("ServiceWorker.js");
  30. }
  31. });
  32. let container = document.querySelector("#unity-container");
  33. let canvas = document.querySelector("#unity-canvas");
  34. let warningBanner = document.querySelector("#unity-warning");
  35. // Shows a temporary message banner/ribbon for a few seconds, or
  36. // a permanent error message on top of the canvas if type=='error'.
  37. // If type=='warning', a yellow highlight color is used.
  38. // Modify or remove this function to customize the visually presented
  39. // way that non-critical warnings and error messages are presented to the
  40. // user.
  41. function unityShowBanner(msg, type) {
  42. function updateBannerVisibility() {
  43. warningBanner.style.display = warningBanner.children.length ? 'block' : 'none';
  44. }
  45. let
  46. div = document.createElement('div');
  47. div.innerHTML = msg;
  48. warningBanner.appendChild(div);
  49. if (type == 'error') div.style = 'background: red; padding: 10px;';
  50. else {
  51. if (type == 'warning') div.style = 'background: yellow; padding: 10px;';
  52. setTimeout(function() {
  53. warningBanner.removeChild(div);
  54. updateBannerVisibility();
  55. }, 5000);
  56. }
  57. updateBannerVisibility();
  58. }
  59. let buildUrl = "Build";
  60. let loaderUrl = buildUrl + "/Build.loader.js";
  61. let config = {
  62. dataUrl: buildUrl + "/Build.data.unityweb",
  63. frameworkUrl: buildUrl + "/Build.framework.js.unityweb",
  64. codeUrl: buildUrl + "/Build.wasm.unityweb",
  65. streamingAssetsUrl: "StreamingAssets",
  66. companyName: "4Dage",
  67. productName: "H5Game-NanjingMuseum",
  68. productVersion: "1.1.3",
  69. showBanner: unityShowBanner,
  70. };
  71. // By default Unity keeps WebGL canvas render target size matched with
  72. // the DOM size of the canvas element (scaled by window.devicePixelRatio)
  73. // Set this to false if you want to decouple this synchronization from
  74. // happening inside the engine, and you would instead like to size up
  75. // the canvas DOM size and WebGL render target sizes yourself.
  76. // config.matchWebGLToCanvasSize = false;
  77. if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
  78. // Mobile device style: fill the whole browser client area with the game canvas:
  79. let meta = document.createElement('meta');
  80. meta.name = 'viewport';
  81. meta.content = 'width=device-width, height=device-height, initial-scale=1.0, user-scalable=no, shrink-to-fit=yes';
  82. document.getElementsByTagName('head')[0].appendChild(meta);
  83. }
  84. let isShowLoading = true;
  85. const loadingDom = document.querySelector('#unity-loading');
  86. const loadingPaperDom = document.querySelector('#unity-loading-paper');
  87. const loadingBgDom = document.querySelector('#unity-loading-bg');
  88. const progressDom = document.querySelector('#unity-loading-progress');
  89. const progressText = document.querySelector('#unity-loading-progress-text');
  90. progressText.innerHTML = "0%";
  91. let opacity = 1;
  92. function fadeOutVideo(){
  93. if (opacity > 0) {
  94. setTimeout(function() {
  95. opacity = opacity - 0.05;
  96. progressDom.style.opacity = opacity;
  97. loadingPaperDom.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 = 1560;
  122. const unityCanvasHeight = 3376;
  123. const unityPanelWidth = 1560;
  124. const unityPanelHeight = 3301;
  125. const unityPanelOffsetY = 97.5;
  126. const unityPanelOffsetX = -34;
  127. const innerWidth = window.innerWidth;
  128. const innerHeight = window.innerHeight;
  129. const scale = (unityCanvasWidth / unityPanelHeight) >
  130. (innerWidth / innerHeight) ? (innerWidth / unityCanvasWidth) : (innerHeight / unityCanvasHeight);
  131. loadingPaperDom.style.width = (unityPanelWidth * scale) + 'px';
  132. loadingPaperDom.style.height = (unityPanelHeight * scale) + 'px';
  133. if (unityPanelOffsetY > 0){
  134. loadingPaperDom.style.marginTop = (unityPanelOffsetY * scale * 2) + 'px';
  135. } else {
  136. loadingPaperDom.style.marginBottom = (-unityPanelOffsetY * scale * 2) + 'px';
  137. }
  138. if (unityPanelOffsetX > 0){
  139. loadingPaperDom.style.marginLeft = (unityPanelOffsetX * scale * 2) + 'px';
  140. } else {
  141. loadingPaperDom.style.marginRight = (-unityPanelOffsetX * scale * 2) + 'px';
  142. }
  143. }
  144. refreshLoadingPaperBlockSize();
  145. window.addEventListener('resize', refreshLoadingPaperBlockSize);
  146. </script>
  147. <script src="./index.js"></script>
  148. </body>
  149. </html>