index.html 8.0 KB

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