index.html 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. </style>
  16. </head>
  17. <body style="text-align: center">
  18. <canvas id="unity-canvas"></canvas>
  19. <script src="Build/dist.loader.js"></script>
  20. <script>
  21. var myGameInstance = null;
  22. createUnityInstance(document.querySelector("#unity-canvas"), {
  23. dataUrl: "Build/dist.data",
  24. frameworkUrl: "Build/dist.framework.js",
  25. codeUrl: "Build/dist.wasm",
  26. streamingAssetsUrl: "StreamingAssets",
  27. companyName: "DefaultCompany",
  28. productName: "meta",
  29. productVersion: "0.1",
  30. // matchWebGLToCanvasSize: false, // Uncomment this to separately control WebGL canvas render size and DOMelement size.
  31. // devicePixelRatio: 1, // Uncomment this to override low DPI rendering on high DPI displays.
  32. }, (progress) => {}).then((unityInstance) => {
  33. myGameInstance = unityInstance;
  34. });
  35. window.onload = function () {
  36. Reset();
  37. }
  38. window.onresize = function () {
  39. Reset();
  40. }
  41. function Reset() {
  42. var canvas = document.querySelector("#unity-canvas");
  43. canvas.height = document.body.clientHeight;
  44. canvas.width = document.body.clientWidth;
  45. }
  46. function send(obj) {
  47. myGameInstance.SendMessage('Canvas', 'SetScene', obj);
  48. }
  49. window.addEventListener('message', function (e) { // 监听 message 事件
  50. if(e.data.type){
  51. send(e.data.type);
  52. }
  53. });
  54. </script>
  55. </body>
  56. </html>