index.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. </head>
  10. <body>
  11. <div id="unity-container">
  12. <canvas id="unity-canvas" width={{{ WIDTH }}} height={{{ HEIGHT }}} tabindex="-1"></canvas>
  13. <div id="unity-loading-bar">
  14. <div id="unity-logo"></div>
  15. <div id="unity-progress-bar-empty">
  16. <div id="unity-progress-bar-full"></div>
  17. </div>
  18. </div>
  19. <div id="unity-warning"> </div>
  20. </div>
  21. <script>
  22. window.addEventListener("load", function () {
  23. if ("serviceWorker" in navigator) {
  24. navigator.serviceWorker.register("ServiceWorker.js");
  25. }
  26. });
  27. var container = document.querySelector("#unity-container");
  28. var canvas = document.querySelector("#unity-canvas");
  29. var loadingBar = document.querySelector("#unity-loading-bar");
  30. var progressBarFull = document.querySelector("#unity-progress-bar-full");
  31. var warningBanner = document.querySelector("#unity-warning");
  32. // Shows a temporary message banner/ribbon for a few seconds, or
  33. // a permanent error message on top of the canvas if type=='error'.
  34. // If type=='warning', a yellow highlight color is used.
  35. // Modify or remove this function to customize the visually presented
  36. // way that non-critical warnings and error messages are presented to the
  37. // user.
  38. function unityShowBanner(msg, type) {
  39. function updateBannerVisibility() {
  40. warningBanner.style.display = warningBanner.children.length ? 'block' : 'none';
  41. }
  42. var div = document.createElement('div');
  43. div.innerHTML = msg;
  44. warningBanner.appendChild(div);
  45. if (type == 'error') div.style = 'background: red; padding: 10px;';
  46. else {
  47. if (type == 'warning') div.style = 'background: yellow; padding: 10px;';
  48. setTimeout(function() {
  49. warningBanner.removeChild(div);
  50. updateBannerVisibility();
  51. }, 5000);
  52. }
  53. updateBannerVisibility();
  54. }
  55. var buildUrl = "Build";
  56. var loaderUrl = buildUrl + "/{{{ LOADER_FILENAME }}}";
  57. var config = {
  58. dataUrl: buildUrl + "/{{{ DATA_FILENAME }}}",
  59. frameworkUrl: buildUrl + "/{{{ FRAMEWORK_FILENAME }}}",
  60. #if USE_THREADS
  61. workerUrl: buildUrl + "/{{{ WORKER_FILENAME }}}",
  62. #endif
  63. #if USE_WASM
  64. codeUrl: buildUrl + "/{{{ CODE_FILENAME }}}",
  65. #endif
  66. #if MEMORY_FILENAME
  67. memoryUrl: buildUrl + "/{{{ MEMORY_FILENAME }}}",
  68. #endif
  69. #if SYMBOLS_FILENAME
  70. symbolsUrl: buildUrl + "/{{{ SYMBOLS_FILENAME }}}",
  71. #endif
  72. streamingAssetsUrl: "StreamingAssets",
  73. companyName: {{{ JSON.stringify(COMPANY_NAME) }}},
  74. productName: {{{ JSON.stringify(PRODUCT_NAME) }}},
  75. productVersion: {{{ JSON.stringify(PRODUCT_VERSION) }}},
  76. showBanner: unityShowBanner,
  77. };
  78. // By default Unity keeps WebGL canvas render target size matched with
  79. // the DOM size of the canvas element (scaled by window.devicePixelRatio)
  80. // Set this to false if you want to decouple this synchronization from
  81. // happening inside the engine, and you would instead like to size up
  82. // the canvas DOM size and WebGL render target sizes yourself.
  83. // config.matchWebGLToCanvasSize = false;
  84. if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
  85. // Mobile device style: fill the whole browser client area with the game canvas:
  86. var meta = document.createElement('meta');
  87. meta.name = 'viewport';
  88. meta.content = 'width=device-width, height=device-height, initial-scale=1.0, user-scalable=no, shrink-to-fit=yes';
  89. document.getElementsByTagName('head')[0].appendChild(meta);
  90. }
  91. #if BACKGROUND_FILENAME
  92. canvas.style.background = "url('" + buildUrl + "/{{{ BACKGROUND_FILENAME.replace(/'/g, '%27') }}}') center / cover";
  93. #endif
  94. loadingBar.style.display = "block";
  95. var script = document.createElement("script");
  96. script.src = loaderUrl;
  97. script.onload = () => {
  98. createUnityInstance(canvas, config, (progress) => {
  99. progressBarFull.style.width = 100 * progress + "%";
  100. }).then((unityInstance) => {
  101. loadingBar.style.display = "none";
  102. }).catch((message) => {
  103. alert(message);
  104. });
  105. };
  106. document.body.appendChild(script);
  107. </script>
  108. </body>
  109. </html>