index.html 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 | Balance</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 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 id="unity-footer">
  21. <div id="unity-webgl-logo"></div>
  22. <div id="unity-fullscreen-button"></div>
  23. <div id="unity-build-title">Balance</div>
  24. </div>
  25. <div>
  26. <button id = "btnStart">开始传输</button>
  27. </div>
  28. </div>
  29. <script>
  30. var container = document.querySelector("#unity-container");
  31. var canvas = document.querySelector("#unity-canvas");
  32. var loadingBar = document.querySelector("#unity-loading-bar");
  33. var progressBarFull = document.querySelector("#unity-progress-bar-full");
  34. var fullscreenButton = document.querySelector("#unity-fullscreen-button");
  35. var warningBanner = document.querySelector("#unity-warning");
  36. // Shows a temporary message banner/ribbon for a few seconds, or
  37. // a permanent error message on top of the canvas if type=='error'.
  38. // If type=='warning', a yellow highlight color is used.
  39. // Modify or remove this function to customize the visually presented
  40. // way that non-critical warnings and error messages are presented to the
  41. // user.
  42. function unityShowBanner(msg, type) {
  43. function updateBannerVisibility() {
  44. warningBanner.style.display = warningBanner.children.length ? 'block' : 'none';
  45. }
  46. var div = document.createElement('div');
  47. div.innerHTML = msg;
  48. warningBanner.appendChild(div);
  49. if (type == 'error') div.style = 'background: red; padding: 10px;';
  50. else {
  51. if (type == 'warning') div.style = 'background: yellow; padding: 10px;';
  52. setTimeout(function() {
  53. warningBanner.removeChild(div);
  54. updateBannerVisibility();
  55. }, 5000);
  56. }
  57. updateBannerVisibility();
  58. }
  59. var buildUrl = "Build";
  60. var loaderUrl = buildUrl + "/Tianping.loader.js";
  61. var config = {
  62. dataUrl: buildUrl + "/Tianping.data",
  63. frameworkUrl: buildUrl + "/Tianping.framework.js",
  64. codeUrl: buildUrl + "/Tianping.wasm",
  65. streamingAssetsUrl: "StreamingAssets",
  66. companyName: "DefaultCompany",
  67. productName: "Balance",
  68. productVersion: "0.1",
  69. showBanner: unityShowBanner,
  70. };
  71. // By default, Unity keeps WebGL canvas render target size matched with
  72. // the DOM size of the canvas element (scaled by window.devicePixelRatio)
  73. // Set this to false if you want to decouple this synchronization from
  74. // happening inside the engine, and you would instead like to size up
  75. // the canvas DOM size and WebGL render target sizes yourself.
  76. // config.matchWebGLToCanvasSize = false;
  77. if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
  78. // Mobile device style: fill the whole browser client area with the game canvas:
  79. var meta = document.createElement('meta');
  80. meta.name = 'viewport';
  81. meta.content = 'width=device-width, height=device-height, initial-scale=1.0, user-scalable=no, shrink-to-fit=yes';
  82. document.getElementsByTagName('head')[0].appendChild(meta);
  83. container.className = "unity-mobile";
  84. canvas.className = "unity-mobile";
  85. // To lower canvas resolution on mobile devices to gain some
  86. // performance, uncomment the following line:
  87. // config.devicePixelRatio = 1;
  88. } else {
  89. // Desktop style: Render the game canvas in a window that can be maximized to fullscreen:
  90. canvas.style.width = "960px";
  91. canvas.style.height = "600px";
  92. }
  93. loadingBar.style.display = "block";
  94. var script = document.createElement("script");
  95. script.src = loaderUrl;
  96. script.onload = () => {
  97. createUnityInstance(canvas, config, (progress) => {
  98. progressBarFull.style.width = 100 * progress + "%";
  99. }).then((unityInstance) => {
  100. loadingBar.style.display = "none";
  101. fullscreenButton.onclick = () => {
  102. unityInstance.SetFullscreen(1);
  103. };
  104. this.gameInstance = unityInstance;
  105. }).catch((message) => {
  106. alert(message);
  107. });
  108. };
  109. document.body.appendChild(script);
  110. var btnStart = document.getElementById("btnStart");
  111. btnStart.onclick = function(){
  112. gameInstance.SendMessage("Tianping","Balance","2.00,52.00");
  113. console.log(gameInstance);
  114. };
  115. </script>
  116. </body>
  117. </html>