index.html 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 | meta</title>
  7. <style>
  8. html,
  9. body {
  10. width: 100%;
  11. height: 100%;
  12. margin: 0;
  13. padding: 0;
  14. }
  15. .loading {
  16. width: 100%;
  17. height: 100%;
  18. display: flex;
  19. align-items: center;
  20. justify-content: center;
  21. }
  22. </style>
  23. </head>
  24. <body style="text-align: center">
  25. <div class="loading">
  26. <img src="./TemplateData/cocorobo-loading.gif" />
  27. </div>
  28. <canvas id="unity-canvas"></canvas>
  29. <script src="Build/dist.loader.js"></script>
  30. <script>
  31. var myGameInstance = null;
  32. createUnityInstance(document.querySelector("#unity-canvas"), {
  33. dataUrl: "Build/dist.data",
  34. frameworkUrl: "Build/dist.framework.js",
  35. codeUrl: "Build/dist.wasm",
  36. streamingAssetsUrl: "StreamingAssets",
  37. companyName: "DefaultCompany",
  38. productName: "meta",
  39. productVersion: "0.1",
  40. // matchWebGLToCanvasSize: false, // Uncomment this to separately control WebGL canvas render size and DOMelement size.
  41. // devicePixelRatio: 1, // Uncomment this to override low DPI rendering on high DPI displays.
  42. }, (progress) => {}).then((unityInstance) => {
  43. myGameInstance = unityInstance;
  44. document.getElementsByClassName("loading")[0].style.display = "none";
  45. window.parent.postMessage({
  46. success: 1
  47. }, '*');
  48. });
  49. window.onload = function () {
  50. Reset();
  51. }
  52. window.onresize = function () {
  53. Reset();
  54. }
  55. function Reset() {
  56. var canvas = document.querySelector("#unity-canvas");
  57. canvas.height = document.body.clientHeight;
  58. canvas.width = document.body.clientWidth;
  59. }
  60. function send(obj) {
  61. myGameInstance.SendMessage('Canvas', 'SetScene', obj);
  62. }
  63. window.addEventListener('message', function (e) { // 监听 message 事件
  64. if (e.data.type) {
  65. send(e.data.type);
  66. }
  67. });
  68. </script>
  69. </body>
  70. </html>