index copy.html 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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 | HeNanMuseum</title>
  7. <link rel="shortcut icon" href="TemplateData/favicon.ico">
  8. <link rel="stylesheet" href="TemplateData/style.css">
  9. <link rel="manifest" href="manifest.webmanifest">
  10. </head>
  11. <body>
  12. <div id="unity-container">
  13. <canvas id="unity-canvas" width=960 height=600 tabindex="-1"></canvas>
  14. <div id="unity-loading-bar">
  15. <div id="unity-logo"></div>
  16. <div id="unity-progress-bar-empty">
  17. <div id="unity-progress-bar-full"></div>
  18. </div>
  19. </div>
  20. <div id="unity-warning"> </div>
  21. </div>
  22. <style>
  23. #unity-loading-bar {
  24. position: fixed;
  25. z-index: 999;
  26. top: 0;
  27. left: 0;
  28. transform: translate(0, 0);
  29. width: 100%;
  30. height: 100%;
  31. background-color: black;
  32. }
  33. #unity-logo {
  34. display: none !important;
  35. }
  36. #unity-progress-bar-empty {
  37. position: absolute;
  38. top: 0;
  39. left: 0;
  40. width: 100%;
  41. height: 100%;
  42. background: none;
  43. background-image: url('./loginSta.gif');
  44. background-size: 100% 100%;
  45. }
  46. #unity-progress-bar-full {
  47. display: none !important;
  48. }
  49. </style>
  50. <script>
  51. window.addEventListener("load", function () {
  52. if ("serviceWorker" in navigator) {
  53. navigator.serviceWorker.register("ServiceWorker.js");
  54. }
  55. });
  56. var container = document.querySelector("#unity-container");
  57. var canvas = document.querySelector("#unity-canvas");
  58. var loadingBar = document.querySelector("#unity-loading-bar");
  59. var progressBarFull = document.querySelector("#unity-progress-bar-full");
  60. var warningBanner = document.querySelector("#unity-warning");
  61. let unityInstance = null
  62. // Shows a temporary message banner/ribbon for a few seconds, or
  63. // a permanent error message on top of the canvas if type=='error'.
  64. // If type=='warning', a yellow highlight color is used.
  65. // Modify or remove this function to customize the visually presented
  66. // way that non-critical warnings and error messages are presented to the
  67. // user.
  68. function unityShowBanner(msg, type) {
  69. function updateBannerVisibility() {
  70. warningBanner.style.display = warningBanner.children.length ? 'block' : 'none';
  71. }
  72. var div = document.createElement('div');
  73. div.innerHTML = msg;
  74. warningBanner.appendChild(div);
  75. if (type == 'error') div.style = 'background: red; padding: 10px;';
  76. else {
  77. if (type == 'warning') div.style = 'background: yellow; padding: 10px;';
  78. setTimeout(function () {
  79. warningBanner.removeChild(div);
  80. updateBannerVisibility();
  81. }, 5000);
  82. }
  83. updateBannerVisibility();
  84. }
  85. var buildUrl = "Build";
  86. var loaderUrl = buildUrl + "/Build13.loader.js";
  87. var config = {
  88. dataUrl: buildUrl + "/Build13.data.unityweb",
  89. frameworkUrl: buildUrl + "/Build13.framework.js.unityweb",
  90. codeUrl: buildUrl + "/Build13.wasm.unityweb",
  91. streamingAssetsUrl: "StreamingAssets",
  92. companyName: "DefaultCompany",
  93. productName: "HeNanMuseum",
  94. productVersion: "0.1",
  95. showBanner: unityShowBanner,
  96. };
  97. // By default Unity keeps WebGL canvas render target size matched with
  98. // the DOM size of the canvas element (scaled by window.devicePixelRatio)
  99. // Set this to false if you want to decouple this synchronization from
  100. // happening inside the engine, and you would instead like to size up
  101. // the canvas DOM size and WebGL render target sizes yourself.
  102. // config.matchWebGLToCanvasSize = false;
  103. if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
  104. // Mobile device style: fill the whole browser client area with the game canvas:
  105. var meta = document.createElement('meta');
  106. meta.name = 'viewport';
  107. meta.content = 'width=device-width, height=device-height, initial-scale=1.0, user-scalable=no, shrink-to-fit=yes';
  108. document.getElementsByTagName('head')[0].appendChild(meta);
  109. }
  110. loadingBar.style.display = "block";
  111. var script = document.createElement("script");
  112. script.src = loaderUrl;
  113. script.onload = () => {
  114. createUnityInstance(canvas, config, (progress) => {
  115. progressBarFull.style.width = 100 * progress + "%";
  116. }).then((instance) => {
  117. loadingBar.style.display = "none";
  118. unityInstance = instance
  119. }).catch((message) => {
  120. alert(message);
  121. });
  122. };
  123. document.body.appendChild(script);
  124. // 新添加(以下全是)
  125. window.onShareImage = (img) => {
  126. console.log('result:', img);
  127. window.parent.postMessage({
  128. source: 'shareImg',
  129. data: img,
  130. },
  131. "*")
  132. }
  133. // 禁用UI交互
  134. window.disableUIInteract = () => {
  135. // console.log('禁用ui:111');
  136. window.parent.postMessage({
  137. source: 'disableUIInteract',
  138. data: true
  139. },
  140. "*")
  141. }
  142. // 启用UI交互
  143. window.enableUIInteract = () => {
  144. // console.log('禁用ui:111');
  145. window.parent.postMessage({
  146. source: 'enableUIInteract',
  147. data: true
  148. },
  149. "*")
  150. }
  151. // 拼接模型成功,接受 unity的消息 取消 模型的选中ui效果
  152. window.modelSuccItem = () => {
  153. window.parent.postMessage({
  154. source: 'modelSuccItem',
  155. data: true
  156. },
  157. "*")
  158. }
  159. window.Internal_ShowTouchErrorTips = (data) => {
  160. console.log('result:', data);
  161. }
  162. window.showTouchErrorTips = (data) => {
  163. console.log('result:', data);
  164. }
  165. window._Internal_ShowTouchErrorTips = (data) => {
  166. console.log('result:', data);
  167. }
  168. window.addEventListener('message', (res) => {
  169. console.log('result:', unityInstance);
  170. if (!unityInstance) return
  171. if (Object.prototype.toString.call(res.data) == "[object Object]") {
  172. let data = res.data.data;
  173. // 切换模块
  174. if (res.data.source === "changeBlock") {
  175. console.log('result:changeBlock', data);
  176. unityInstance.SendMessage('Main', 'OnClickModule', data);
  177. }
  178. // 切换类型
  179. else if (res.data.source === "clickTypeBtn") {
  180. unityInstance.SendMessage('Main', 'OnClickType', data === 'block' ? 0 : 1);
  181. console.log('result:OnClickType', data === 'block' ? 0 : 1);
  182. }
  183. // 点击子项
  184. else if (res.data.source === "clickItemBtn") {
  185. console.log('选中了子选项', data);
  186. unityInstance.SendMessage('Main', 'OnClickItem', data);
  187. }
  188. // 保存
  189. else if (res.data.source === "Save") {
  190. unityInstance.SendMessage('Main', 'Save');
  191. }
  192. // 取消
  193. else if (res.data.source === "Cancel") {
  194. unityInstance.SendMessage('Main', 'Cancel');
  195. }
  196. // 图片回调
  197. else if (res.data.source === "CallShareImage") {
  198. unityInstance.SendMessage('Main', 'CallShareImage');
  199. }
  200. // 到处逛逛
  201. else if (res.data.source === "ShowUserData") {
  202. console.log('到处逛逛,用户id:', data, '不知道为啥报错??');
  203. unityInstance.SendMessage('Main', 'ShowUserData', data);
  204. }
  205. // 点击编辑
  206. else if (res.data.source === "OnClickEdit") {
  207. // console.log('----------------');
  208. unityInstance.SendMessage('Main', 'OnClickEdit');
  209. }
  210. }
  211. })
  212. </script>
  213. </body>
  214. </html>