index.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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>中医药大观园</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. <!-- 引用自己的样式 -->
  11. <link rel="stylesheet" href="./myCode/style.css">
  12. </head>
  13. <body>
  14. <div id="unity-container">
  15. <canvas id="unity-canvas" tabindex="-1"></canvas>
  16. <div id="unity-loading-bar">
  17. <div id="unity-logo"></div>
  18. <div id="unity-progress-bar-empty">
  19. <div id="unity-progress-bar-full"></div>
  20. </div>
  21. </div>
  22. <div id="unity-warning"> </div>
  23. </div>
  24. <!-- 加载中文字 -->
  25. <div id="lodingTxt">加载中...</div>
  26. <!-- 开场视频 -->
  27. <div class="videoBox">
  28. <video src="./myCode/video.mp4" controls muted autoplay></video>
  29. <div class="skipTxt">跳 过</div>
  30. </div>
  31. <script>
  32. let unityExamples = null
  33. window.addEventListener("load", function () {
  34. if ("serviceWorker" in navigator) {
  35. navigator.serviceWorker.register("ServiceWorker.js");
  36. }
  37. });
  38. var container = document.querySelector("#unity-container");
  39. var canvas = document.querySelector("#unity-canvas");
  40. var loadingBar = document.querySelector("#unity-loading-bar");
  41. var progressBarFull = document.querySelector("#unity-progress-bar-full");
  42. var warningBanner = document.querySelector("#unity-warning");
  43. // Shows a temporary message banner/ribbon for a few seconds, or
  44. // a permanent error message on top of the canvas if type=='error'.
  45. // If type=='warning', a yellow highlight color is used.
  46. // Modify or remove this function to customize the visually presented
  47. // way that non-critical warnings and error messages are presented to the
  48. // user.
  49. function unityShowBanner(msg, type) {
  50. function updateBannerVisibility() {
  51. warningBanner.style.display = warningBanner.children.length ? 'block' : 'none';
  52. }
  53. var div = document.createElement('div');
  54. div.innerHTML = msg;
  55. warningBanner.appendChild(div);
  56. if (type == 'error') div.style = 'background: red; padding: 10px;';
  57. else {
  58. if (type == 'warning') div.style = 'background: yellow; padding: 10px;';
  59. setTimeout(function() {
  60. warningBanner.removeChild(div);
  61. updateBannerVisibility();
  62. }, 5000);
  63. }
  64. updateBannerVisibility();
  65. }
  66. var buildUrl = "Build";
  67. var loaderUrl = buildUrl + "/ChangZhouHospital_1.20.loader.js";
  68. var config = {
  69. dataUrl: buildUrl + "/ChangZhouHospital_1.20.data.unityweb",
  70. frameworkUrl: buildUrl + "/ChangZhouHospital_1.20.framework.js.unityweb",
  71. codeUrl: buildUrl + "/ChangZhouHospital_1.20.wasm.unityweb",
  72. streamingAssetsUrl: "StreamingAssets",
  73. companyName: "DefaultCompany",
  74. productName: "ChangZhouHospital",
  75. productVersion: "0.1",
  76. showBanner: unityShowBanner,
  77. };
  78. // By default Unity keeps WebGL canvas render target size matched with
  79. // the DOM size of the canvas element (scaled by window.devicePixelRatio)
  80. // Set this to false if you want to decouple this synchronization from
  81. // happening inside the engine, and you would instead like to size up
  82. // the canvas DOM size and WebGL render target sizes yourself.
  83. // config.matchWebGLToCanvasSize = false;
  84. if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
  85. // Mobile device style: fill the whole browser client area with the game canvas:
  86. var meta = document.createElement('meta');
  87. meta.name = 'viewport';
  88. meta.content = 'width=device-width, height=device-height, initial-scale=1.0, user-scalable=no, shrink-to-fit=yes';
  89. document.getElementsByTagName('head')[0].appendChild(meta);
  90. }
  91. loadingBar.style.display = "block";
  92. var script = document.createElement("script");
  93. script.src = loaderUrl;
  94. script.onload = () => {
  95. createUnityInstance(canvas, config, (progress) => {
  96. progressBarFull.style.width = 100 * progress + "%";
  97. }).then((unityInstance) => {
  98. loadingBar.style.display = "none";
  99. // 把unity的实例保存起来
  100. unityExamples = unityInstance
  101. // 隐藏加载中文字
  102. document.querySelector('#lodingTxt').style.display = 'none'
  103. }).catch((message) => {
  104. alert(message);
  105. });
  106. };
  107. document.body.appendChild(script);
  108. </script>
  109. <!-- 引入自己的js -->
  110. <script src="./myCode/index.js"></script>
  111. </body>
  112. </html>