index.html 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. background-color: #fff;
  22. }
  23. </style>
  24. </head>
  25. <body style="text-align: center">
  26. <div class="loading">
  27. <img src="./TemplateData/cocorobo-loading.gif" />
  28. </div>
  29. <canvas style="display: none;" id="unity-canvas"></canvas>
  30. <script src="Build/dist.loader.js"></script>
  31. <script>
  32. var myGameInstance = null;
  33. createUnityInstance(document.querySelector("#unity-canvas"), {
  34. dataUrl: "Build/dist.data",
  35. frameworkUrl: "Build/dist.framework.js",
  36. codeUrl: "Build/dist.wasm",
  37. streamingAssetsUrl: "StreamingAssets",
  38. companyName: "DefaultCompany",
  39. productName: "meta",
  40. productVersion: "0.1",
  41. // matchWebGLToCanvasSize: false, // Uncomment this to separately control WebGL canvas render size and DOMelement size.
  42. // devicePixelRatio: 1, // Uncomment this to override low DPI rendering on high DPI displays.
  43. }, (progress) => {}).then((unityInstance) => {
  44. myGameInstance = unityInstance;
  45. document.getElementsByClassName("loading")[0].style.display = "none";
  46. document.getElementById("unity-canvas").style.display = "";
  47. window.parent.postMessage({
  48. success: 1
  49. }, '*');
  50. });
  51. window.onload = function () {
  52. Reset();
  53. }
  54. window.onresize = function () {
  55. Reset();
  56. }
  57. function Reset() {
  58. var canvas = document.querySelector("#unity-canvas");
  59. canvas.height = document.body.clientHeight;
  60. canvas.width = document.body.clientWidth;
  61. }
  62. function send(obj) {
  63. myGameInstance.SendMessage('Canvas', 'SetScene', obj);
  64. }
  65. function doS() {
  66. myGameInstance.SendMessage('GameObject', 'forwardTow');
  67. }
  68. function openCamera() {
  69. myGameInstance.SendMessage('GameObject', 'openCamera');
  70. }
  71. function noActive(params) {
  72. window.parent.postMessage({
  73. active: params ? true : false
  74. }, '*');
  75. }
  76. function noCamera(str) {
  77. window.parent.postMessage({
  78. noCamera: str
  79. }, '*');
  80. }
  81. window.addEventListener('message', function (e) { // 监听 message 事件
  82. if (e.data.type) {
  83. send(e.data.type);
  84. }
  85. if (e.data.do) {
  86. if (e.data.do == "1") {
  87. openCamera();
  88. }
  89. }
  90. });
  91. </script>
  92. </body>
  93. </html>