Files
Deroc_Virtual_3D/Assets/WebGLTemplates/MonTemplatePerso/index.html
T
Alex38Lyon d4b7efa424 update
2025-06-03 09:56:26 +02:00

165 lines
4.4 KiB
HTML

<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>{{{ PRODUCT_NAME }}}</title>
<style>
html, body {
background: {{{ BACKGROUND || '#000' }}};
width: 100%;
height: 100%;
overflow: visible;
padding: 0;
margin: 0;
font-family: Arial, sans-serif;
color: white;
}
#container {
background: transparent !important;
position: absolute;
}
#container canvas {
position: absolute;
}
#container canvas[data-pixel-art="true"] {
image-rendering: pixelated;
-ms-interpolation-mode: nearest-neighbor;
}
#loading-box {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
z-index: 1000;
}
#logo {
max-width: 600px;
margin-bottom: 20px;
}
#progress-container {
width: 300px;
height: 20px;
background-color: rgba(255, 255, 255, 0.2);
border-radius: 10px;
overflow: hidden;
margin: 0 auto;
}
#progress-bar {
height: 100%;
width: 0%;
background-color: #4caf50;
transition: width 0.1s ease;
}
#progress-info {
margin-top: 10px;
font-size: 14px;
}
</style>
</head>
<body>
<div id="container">
<canvas id="game-canvas" data-pixel-art="{{{ OPTIMIZE_FOR_PIXEL_ART }}}"></canvas>
<!-- Logo et barre de chargement -->
<div id="loading-box">
<img id="logo" src="Logo.png" alt="Logo">
<div id="progress-container">
<div id="progress-bar"></div>
</div>
<div id="progress-info">Chargement... 0%</div>
</div>
<script src="Build/{{{ LOADER_FILENAME }}}"></script>
<script>
const canvas = document.querySelector("#game-canvas");
const progressBar = document.getElementById("progress-bar");
const progressInfo = document.getElementById("progress-info");
const loadingBox = document.getElementById("loading-box");
let lastTime = performance.now();
let lastProgress = 0;
const config = {
dataUrl: "Build/{{{ DATA_FILENAME }}}",
frameworkUrl: "Build/{{{ FRAMEWORK_FILENAME }}}",
codeUrl: "Build/{{{ CODE_FILENAME }}}",
#if MEMORY_FILENAME
memoryUrl: "Build/{{{ MEMORY_FILENAME }}}",
#endif
#if SYMBOLS_FILENAME
symbolsUrl: "Build/{{{ SYMBOLS_FILENAME }}}",
#endif
streamingAssetsUrl: "StreamingAssets",
companyName: "{{{ COMPANY_NAME }}}",
productName: "{{{ PRODUCT_NAME }}}",
productVersion: "{{{ PRODUCT_VERSION }}}"
};
let scaleToFit;
try {
scaleToFit = !!JSON.parse("{{{ SCALE_TO_FIT }}}");
} catch (e) {
scaleToFit = true;
}
function progressHandler(progress) {
const percent = Math.floor(progress * 100);
const now = performance.now();
const deltaTime = (now - lastTime) / 1000; // en secondes
const deltaProgress = progress - lastProgress;
const speed = deltaProgress > 0 ? (deltaProgress * 100 / deltaTime).toFixed(2) : "0";
progressBar.style.width = percent + "%";
// <!-- progressInfo.textContent = `Chargement... ${percent}% (${speed}%/s)`; -->
progressInfo.textContent = `Chargement... ${percent}%`;
lastTime = now;
lastProgress = progress;
if (percent >= 100) {
// Masquer le logo et la barre après chargement
setTimeout(() => loadingBox.style.display = "none", 500);
}
}
function onResize() {
const container = canvas.parentElement;
let w, h;
if (scaleToFit) {
w = window.innerWidth;
h = window.innerHeight;
const r = {{{ HEIGHT }}} / {{{ WIDTH }}};
if (w * r > h) w = Math.min(w, Math.ceil(h / r));
h = Math.floor(w * r);
} else {
w = {{{ WIDTH }}};
h = {{{ HEIGHT }}};
}
container.style.width = canvas.style.width = w + "px";
container.style.height = canvas.style.height = h + "px";
container.style.top = Math.floor((window.innerHeight - h) / 2) + "px";
container.style.left = Math.floor((window.innerWidth - w) / 2) + "px";
}
createUnityInstance(canvas, config, progressHandler).then(function (instance) {
canvas = instance.Module.canvas;
onResize();
});
window.addEventListener('resize', onResize);
onResize();
if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
const meta = document.createElement('meta');
meta.name = 'viewport';
meta.content = 'width=device-width, height=device-height, initial-scale=1.0, user-scalable=no, shrink-to-fit=yes';
document.getElementsByTagName('head')[0].appendChild(meta);
}
</script>
</div>
</body>
</html>