123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <!DOCTYPE html>
- <html lang="en-us">
- <head>
- <meta charset="utf-8">
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <title>Unity WebGL Player | meta</title>
- <style>
- html,
- body {
- width: 100%;
- height: 100%;
- margin: 0;
- padding: 0;
- }
- .loading {
- width: 100%;
- height: 100%;
- display: flex;
- align-items: center;
- justify-content: center;
- background-color: #fff;
- }
- </style>
- </head>
- <body style="text-align: center">
- <div class="loading">
- <img src="./TemplateData/cocorobo-loading.gif" />
- </div>
- <canvas style="display: none;" id="unity-canvas"></canvas>
- <script src="Build/dist.loader.js"></script>
- <script>
- var myGameInstance = null;
- createUnityInstance(document.querySelector("#unity-canvas"), {
- dataUrl: "Build/dist.data",
- frameworkUrl: "Build/dist.framework.js",
- codeUrl: "Build/dist.wasm",
- streamingAssetsUrl: "StreamingAssets",
- companyName: "DefaultCompany",
- productName: "meta",
- productVersion: "0.1",
- // matchWebGLToCanvasSize: false, // Uncomment this to separately control WebGL canvas render size and DOMelement size.
- // devicePixelRatio: 1, // Uncomment this to override low DPI rendering on high DPI displays.
- }, (progress) => {}).then((unityInstance) => {
- myGameInstance = unityInstance;
- document.getElementsByClassName("loading")[0].style.display = "none";
- document.getElementById("unity-canvas").style.display = "";
- window.parent.postMessage({
- success: 1
- }, '*');
- });
- window.onload = function () {
- Reset();
- }
- window.onresize = function () {
- Reset();
- }
- function Reset() {
- var canvas = document.querySelector("#unity-canvas");
- canvas.height = document.body.clientHeight;
- canvas.width = document.body.clientWidth;
- }
- function send(obj) {
- myGameInstance.SendMessage('Canvas', 'SetScene', obj);
- }
- function doS() {
- myGameInstance.SendMessage('GameObject', 'forwardTow');
- }
- function openCamera() {
- myGameInstance.SendMessage('GameObject', 'openCamera');
- }
- function noActive(params) {
- window.parent.postMessage({
- active: params ? true : false
- }, '*');
- }
- function noCamera(str) {
- window.parent.postMessage({
- noCamera: str
- }, '*');
- }
- window.addEventListener('message', function (e) { // 监听 message 事件
- if (e.data.type) {
- send(e.data.type);
- }
- if (e.data.do) {
- if (e.data.do == "1") {
- openCamera();
- }
- }
- });
- </script>
- </body>
- </html>
|