Files
cocos/web-template/main-site.html
刘宇飞 cba5105908 Initial Cocos Creator port of main-site Unity WebGL game.
Includes core gameplay, 600 exported levels, visual assets, web bridge, and bootstrap scene.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-22 14:57:46 +08:00

78 lines
3.4 KiB
HTML

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
<title>主站 · Cocos 关卡引擎</title>
<style>
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #1a1a2e; font-family: system-ui, sans-serif; }
#layout { display: flex; flex-direction: column; height: 100%; }
#toolbar { padding: 8px 12px; background: #16213e; color: #eee; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
#toolbar button { padding: 6px 12px; cursor: pointer; border: none; border-radius: 4px; background: #0f3460; color: #fff; }
#toolbar button:hover { background: #e94560; }
#game-wrap { flex: 1; position: relative; min-height: 0; }
#GameDiv, #Cocos3dGameContainer, #GameCanvas { width: 100% !important; height: 100% !important; }
#log { height: 120px; overflow: auto; background: #0d1117; color: #8b949e; font: 12px/1.4 monospace; padding: 8px; }
</style>
<!-- ① 先挂回调(与 Unity Template/index.html 一致) -->
<script src="cocos-bridge.js"></script>
</head>
<body>
<div id="layout">
<div id="toolbar">
<strong>主站 Cocos 联调</strong>
<button type="button" id="btn-l1">关卡 1</button>
<button type="button" id="btn-l21">关卡 21(载具)</button>
<button type="button" id="btn-move">前进 2 格</button>
<button type="button" id="btn-info">获取坐标</button>
<button type="button" id="btn-end">结束输入</button>
</div>
<div id="game-wrap">
<!-- ② Cocos 构建后替换为 build 目录中的容器,常见为 #GameDiv -->
<div id="GameDiv">
<div id="Cocos3dGameContainer">
<canvas id="GameCanvas" tabindex="0"></canvas>
</div>
</div>
</div>
<pre id="log"></pre>
</div>
<script>
const logEl = document.getElementById('log');
function log(msg) {
logEl.textContent += msg + '\n';
logEl.scrollTop = logEl.scrollHeight;
}
window.__tfrhOnExternalLevelInfo = (j) => log('关卡就绪: ' + j);
window.__tfrhOnProcessData = (j) => log('坐标: ' + j);
window.__tfrhOnExternalResult = (j) => log('结果: ' + j);
function send(obj, method, arg) {
const ins = window.unityInstance || window.cocosIns;
if (!ins) { log('实例未就绪'); return; }
if (arg === undefined) ins.SendMessage(obj, method);
else ins.SendMessage(obj, method, arg);
}
document.getElementById('btn-l1').onclick = () => send('GameController', 'SwitchLevel', 1);
document.getElementById('btn-l21').onclick = () => send('GameController', 'SwitchLevel', 21);
document.getElementById('btn-move').onclick = () => send('Player', 'CallMove', 2);
document.getElementById('btn-info').onclick = () => send('Player', 'CallPlayerInfo');
document.getElementById('btn-end').onclick = () => send('GameController', 'CallSetIsInputEnd', 1);
</script>
<!-- ③ 在 Cocos 构建输出的 index.html 中,将 systemjs / index.js 等脚本复制到本页 GameDiv 之后 -->
<!-- 示例(路径按实际构建目录修改):
<script src="src/polyfills.bundle.js"></script>
<script src="src/system.bundle.js"></script>
<script src="src/import-map.json" type="systemjs-importmap"></script>
<script>
System.import('./index.js').catch(function(e){ console.error(e); });
</script>
-->
</body>
</html>