index.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <title>Chenzhebei-ShanxiMuseum</title>
  7. <link rel="shortcut icon" href="TemplateData/favicon.ico">
  8. <link rel="stylesheet" href="TemplateData/style.css">
  9. <script src="./unityExport.js"></script>
  10. </head>
  11. <body>
  12. <div id="unity-container">
  13. <canvas id="unity-canvas" width=960 height=600 tabindex="-1"></canvas>
  14. <div id="unity-loading-bar">
  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. </body>
  22. <script>
  23. var container = document.querySelector("#unity-container");
  24. var canvas = document.querySelector("#unity-canvas");
  25. var loadingBar = document.querySelector("#unity-loading-bar");
  26. var progressBarFull = document.querySelector("#unity-progress-bar-full");
  27. var warningBanner = document.querySelector("#unity-warning");
  28. // Shows a temporary message banner/ribbon for a few seconds, or
  29. // a permanent error message on top of the canvas if type=='error'.
  30. // If type=='warning', a yellow highlight color is used.
  31. // Modify or remove this function to customize the visually presented
  32. // way that non-critical warnings and error messages are presented to the
  33. // user.
  34. function unityShowBanner(msg, type) {
  35. function updateBannerVisibility() {
  36. warningBanner.style.display = warningBanner.children.length ? 'block' : 'none';
  37. }
  38. var div = document.createElement('div');
  39. div.innerHTML = msg;
  40. warningBanner.appendChild(div);
  41. if (type == 'error') div.style = 'background: red; padding: 10px;';
  42. else {
  43. if (type == 'warning') div.style = 'background: yellow; padding: 10px;';
  44. setTimeout(function () {
  45. warningBanner.removeChild(div);
  46. updateBannerVisibility();
  47. }, 5000);
  48. }
  49. updateBannerVisibility();
  50. }
  51. var buildUrl = "Build";
  52. var loaderUrl = buildUrl + "/Build.loader.js";
  53. var config = {
  54. dataUrl: buildUrl + "/Build.data.unityweb",
  55. frameworkUrl: buildUrl + "/Build.framework.js.unityweb",
  56. codeUrl: buildUrl + "/Build.wasm.unityweb",
  57. streamingAssetsUrl: "StreamingAssets",
  58. devicePixelRatio: 2,
  59. companyName: "FDage",
  60. productName: "Chenzhebei-ShanxiMuseum",
  61. productVersion: "0.1",
  62. showBanner: unityShowBanner,
  63. };
  64. // By default Unity keeps WebGL canvas render target size matched with
  65. // the DOM size of the canvas element (scaled by window.devicePixelRatio)
  66. // Set this to false if you want to decouple this synchronization from
  67. // happening inside the engine, and you would instead like to size up
  68. // the canvas DOM size and WebGL render target sizes yourself.
  69. // config.matchWebGLToCanvasSize = false;
  70. if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
  71. // Mobile device style: fill the whole browser client area with the game canvas:
  72. var meta = document.createElement('meta');
  73. meta.name = 'viewport';
  74. meta.content = 'width=device-width, height=device-height, initial-scale=1.0, user-scalable=no, shrink-to-fit=yes';
  75. document.getElementsByTagName('head')[0].appendChild(meta);
  76. document.querySelector("#unity-container").className = "unity-mobile";
  77. canvas.className = "unity-mobile";
  78. // To lower canvas resolution on mobile devices to gain some
  79. // performance, uncomment the following line:
  80. // config.devicePixelRatio = 1;
  81. }
  82. loadingBar.style.display = "block";
  83. var script = document.createElement("script");
  84. script.src = loaderUrl;
  85. script.onload = () => {
  86. createUnityInstance(canvas, config, (progress) => {
  87. if (window.parent && window.parent !== window) {
  88. window.parent.unityLoading(progress);
  89. }
  90. progressBarFull.style.width = 100 * progress + "%";
  91. }).then((unityInstance) => {
  92. loadingBar.style.display = "none";
  93. window.unityInstance = unityInstance;
  94. if (window.parent && window.parent !== window) {
  95. window.parent.unityLoading(1);
  96. }
  97. }).catch((message) => {
  98. alert(message);
  99. });
  100. };
  101. document.body.appendChild(script);
  102. </script>
  103. </html>