index.html 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 | TEST01</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=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">TEST01</div> -->
  24. </div>
  25. </div>
  26. <script>
  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 fullscreenButton = document.querySelector("#unity-fullscreen-button");
  32. var warningBanner = document.querySelector("#unity-warning");
  33. // Shows a temporary message banner/ribbon for a few seconds, or
  34. // a permanent error message on top of the canvas if type=='error'.
  35. // If type=='warning', a yellow highlight color is used.
  36. // Modify or remove this function to customize the visually presented
  37. // way that non-critical warnings and error messages are presented to the
  38. // user.
  39. function unityShowBanner(msg, type) {
  40. function updateBannerVisibility() {
  41. warningBanner.style.display = warningBanner.children.length ? 'block' : 'none';
  42. }
  43. var div = document.createElement('div');
  44. div.innerHTML = msg;
  45. warningBanner.appendChild(div);
  46. if (type == 'error') div.style = 'background: red; padding: 10px;';
  47. else {
  48. if (type == 'warning') div.style = 'background: yellow; padding: 10px;';
  49. setTimeout(function () {
  50. warningBanner.removeChild(div);
  51. updateBannerVisibility();
  52. }, 5000);
  53. }
  54. updateBannerVisibility();
  55. }
  56. var buildUrl = "Build";
  57. var loaderUrl = buildUrl + "/222.loader.js";
  58. var config = {
  59. dataUrl: buildUrl + "/222.data.unityweb",
  60. frameworkUrl: buildUrl + "/222.framework.js.unityweb",
  61. codeUrl: buildUrl + "/222.wasm.unityweb",
  62. streamingAssetsUrl: "StreamingAssets",
  63. companyName: "DefaultCompany",
  64. productName: "TEST01",
  65. productVersion: "0.1",
  66. showBanner: unityShowBanner,
  67. };
  68. // By default Unity keeps WebGL canvas render target size matched with
  69. // the DOM size of the canvas element (scaled by window.devicePixelRatio)
  70. // Set this to false if you want to decouple this synchronization from
  71. // happening inside the engine, and you would instead like to size up
  72. // the canvas DOM size and WebGL render target sizes yourself.
  73. // config.matchWebGLToCanvasSize = false;
  74. if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
  75. container.className = "unity-mobile";
  76. // Avoid draining fillrate performance on mobile devices,
  77. // and default/override low DPI mode on mobile browsers.
  78. config.devicePixelRatio = 1;
  79. unityShowBanner('WebGL builds are not supported on mobile devices.');
  80. } else {
  81. canvas.style.width = "960px";
  82. canvas.style.height = "600px";
  83. }
  84. loadingBar.style.display = "block";
  85. const gameInstance = null;
  86. var script = document.createElement("script");
  87. script.src = loaderUrl;
  88. script.onload = () => {
  89. createUnityInstance(canvas, config, (progress) => {
  90. progressBarFull.style.width = 100 * progress + "%";
  91. }).then((unityInstance) => {
  92. loadingBar.style.display = "none";
  93. // fullscreenButton.onclick = () => {
  94. // unityInstance.SetFullscreen(1);
  95. // };
  96. this.gameInstance = unityInstance;
  97. }).catch((message) => {
  98. alert(message);
  99. });
  100. };
  101. window.ReportReady = function () {
  102. console.log("加载成功!!!")
  103. }
  104. function screenwidth(width) {
  105. this.gameInstance.SendMessage("littlefire", "screenwidth", width);
  106. }
  107. function screenheight(height) {
  108. this.gameInstance.SendMessage("littlefire", "screenheight", height);
  109. }
  110. function changeSize(width, height) {
  111. screenwidth(width)
  112. screenheight(height)
  113. canvas.style.width = width + 'px';
  114. canvas.style.height = height + 'px';
  115. }
  116. function Bloomsize(size) {
  117. this.gameInstance.SendMessage("littlefire", "sssize", size);
  118. }
  119. document.body.appendChild(script);
  120. </script>
  121. <script>
  122. // function sssize(size) {
  123. // this.gameInstance.SendMessage("littlefire", "sssize", size);
  124. // }
  125. // setTimeout("sssize(0.6)", 5000);
  126. </script>
  127. </body>
  128. </html>