index.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 | test3</title>
  7. <link rel="shortcut icon" href="TemplateData/favicon.ico">
  8. <link rel="stylesheet" href="TemplateData/style.css">
  9. </head>
  10. <body onresize="Reset()" scroll="no" style="overflow:hidden">
  11. <div id="unity-container" class="unity-desktop" style="width: 100%; height: 100%;margin:auto">
  12. <canvas id="unity-canvas" width=960 height=600></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">test3</div>
  24. </div>
  25. </div>
  26. <script>
  27. function Reset() {
  28. var canvas = document.getElementById("#canvas");//获取#canvas
  29. canvas.height = document.documentElement.clientHeight;//获取body可见区域高度
  30. canvas.width = document.documentElement.clientWidth;//获取body可见区域高度
  31. }
  32. var container = document.querySelector("#unity-container");
  33. var canvas = document.querySelector("#unity-canvas");
  34. var loadingBar = document.querySelector("#unity-loading-bar");
  35. var progressBarFull = document.querySelector("#unity-progress-bar-full");
  36. var fullscreenButton = document.querySelector("#unity-fullscreen-button");
  37. var warningBanner = document.querySelector("#unity-warning");
  38. // Shows a temporary message banner/ribbon for a few seconds, or
  39. // a permanent error message on top of the canvas if type=='error'.
  40. // If type=='warning', a yellow highlight color is used.
  41. // Modify or remove this function to customize the visually presented
  42. // way that non-critical warnings and error messages are presented to the
  43. // user.
  44. function unityShowBanner(msg, type) {
  45. function updateBannerVisibility() {
  46. warningBanner.style.display = warningBanner.children.length ? 'block' : 'none';
  47. }
  48. var div = document.createElement('div');
  49. div.innerHTML = msg;
  50. warningBanner.appendChild(div);
  51. if (type == 'error') div.style = 'background: red; padding: 10px;';
  52. else {
  53. if (type == 'warning') div.style = 'background: yellow; padding: 10px;';
  54. setTimeout(function () {
  55. warningBanner.removeChild(div);
  56. updateBannerVisibility();
  57. }, 5000);
  58. }
  59. updateBannerVisibility();
  60. }
  61. var buildUrl = "Build";
  62. var loaderUrl = buildUrl + "/dist.loader.js";
  63. var config = {
  64. dataUrl: buildUrl + "/dist.data.gz",
  65. frameworkUrl: buildUrl + "/dist.framework.js.gz",
  66. codeUrl: buildUrl + "/dist.wasm.gz",
  67. streamingAssetsUrl: "StreamingAssets",
  68. companyName: "DefaultCompany",
  69. productName: "test3",
  70. productVersion: "0.1",
  71. showBanner: unityShowBanner,
  72. };
  73. // By default Unity keeps WebGL canvas render target size matched with
  74. // the DOM size of the canvas element (scaled by window.devicePixelRatio)
  75. // Set this to false if you want to decouple this synchronization from
  76. // happening inside the engine, and you would instead like to size up
  77. // the canvas DOM size and WebGL render target sizes yourself.
  78. // config.matchWebGLToCanvasSize = false;
  79. if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
  80. container.className = "unity-mobile";
  81. // Avoid draining fillrate performance on mobile devices,
  82. // and default/override low DPI mode on mobile browsers.
  83. config.devicePixelRatio = 1;
  84. unityShowBanner('WebGL builds are not supported on mobile devices.');
  85. } else {
  86. canvas.style.width = "100%";
  87. canvas.style.height = "100%";
  88. }
  89. loadingBar.style.display = "block";
  90. var script = document.createElement("script");
  91. script.src = loaderUrl;
  92. script.onload = () => {
  93. createUnityInstance(canvas, config, (progress) => {
  94. progressBarFull.style.width = 100 * progress + "%";
  95. }).then((unityInstance) => {
  96. loadingBar.style.display = "none";
  97. fullscreenButton.onclick = () => {
  98. unityInstance.SetFullscreen(1);
  99. };
  100. }).catch((message) => {
  101. alert(message);
  102. });
  103. };
  104. document.body.appendChild(script);
  105. </script>
  106. </body>
  107. </html>