index.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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>Unity WebGL Player | {{{ PRODUCT_NAME }}}</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" class="unity-desktop">
  12. <canvas id="unity-canvas" width={{{ WIDTH }}} height={{{ HEIGHT }}}></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 id="unity-footer">
  21. <div id="unity-webgl-logo"></div>
  22. <div id="unity-fullscreen-button"></div>
  23. <div id="unity-build-title">{{{ PRODUCT_NAME }}}</div>
  24. </div>
  25. </div>
  26. <script src="web3/index.js"></script>
  27. <script>
  28. var container = document.querySelector("#unity-container");
  29. var canvas = document.querySelector("#unity-canvas");
  30. var loadingBar = document.querySelector("#unity-loading-bar");
  31. var progressBarFull = document.querySelector("#unity-progress-bar-full");
  32. var fullscreenButton = document.querySelector("#unity-fullscreen-button");
  33. var warningBanner = document.querySelector("#unity-warning");
  34. // Shows a temporary message banner/ribbon for a few seconds, or
  35. // a permanent error message on top of the canvas if type=='error'.
  36. // If type=='warning', a yellow highlight color is used.
  37. // Modify or remove this function to customize the visually presented
  38. // way that non-critical warnings and error messages are presented to the
  39. // user.
  40. function unityShowBanner(msg, type) {
  41. function updateBannerVisibility() {
  42. warningBanner.style.display = warningBanner.children.length ? 'block' : 'none';
  43. }
  44. var 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. var buildUrl = "Build";
  58. var loaderUrl = buildUrl + "/{{{ LOADER_FILENAME }}}";
  59. var config = {
  60. dataUrl: buildUrl + "/{{{ DATA_FILENAME }}}",
  61. frameworkUrl: buildUrl + "/{{{ FRAMEWORK_FILENAME }}}",
  62. codeUrl: buildUrl + "/{{{ CODE_FILENAME }}}",
  63. #if MEMORY_FILENAME
  64. memoryUrl: buildUrl + "/{{{ MEMORY_FILENAME }}}",
  65. #endif
  66. #if SYMBOLS_FILENAME
  67. symbolsUrl: buildUrl + "/{{{ SYMBOLS_FILENAME }}}",
  68. #endif
  69. streamingAssetsUrl: "StreamingAssets",
  70. companyName: "{{{ COMPANY_NAME }}}",
  71. productName: "{{{ PRODUCT_NAME }}}",
  72. productVersion: "{{{ PRODUCT_VERSION }}}",
  73. showBanner: unityShowBanner,
  74. };
  75. // By default Unity keeps WebGL canvas render target size matched with
  76. // the DOM size of the canvas element (scaled by window.devicePixelRatio)
  77. // Set this to false if you want to decouple this synchronization from
  78. // happening inside the engine, and you would instead like to size up
  79. // the canvas DOM size and WebGL render target sizes yourself.
  80. // config.matchWebGLToCanvasSize = false;
  81. if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
  82. container.className = "unity-mobile";
  83. // Avoid draining fillrate performance on mobile devices,
  84. // and default/override low DPI mode on mobile browsers.
  85. config.devicePixelRatio = 1;
  86. unityShowBanner('WebGL builds are not supported on mobile devices.');
  87. } else {
  88. canvas.style.width = "{{{ WIDTH }}}px";
  89. canvas.style.height = "{{{ HEIGHT }}}px";
  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. fullscreenButton.onclick = () => {
  103. unityInstance.SetFullscreen(1);
  104. };
  105. }).catch((message) => {
  106. alert(message);
  107. });
  108. };
  109. document.body.appendChild(script);
  110. </script>
  111. </body>
  112. </html>