Files
cocos/assets/scripts/bridge/JsBridge.ts
刘宇飞 d393302388 Complete Cocos Creator port with level bundles, themes, and tooling.
Adds level prefabs, theme assets, audio, extensions, and deployment scripts for the Unity WebGL migration.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-16 15:30:58 +08:00

44 lines
1.3 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 对应 Unity Application.ExternalCall
* Web 环境下调用 window 上的全局回调
*/
/** 对齐 Unity GameManager.ExternalLevelInfo关卡加载完成时回传 */
export interface ExternalLevelInfo {
LevelID: number;
PlayerName: string;
VehicleName: string;
}
declare global {
interface Window {
processData?: (json: string) => void;
processVehicleData?: (json: string) => void;
externalResult?: (json: string) => void;
externalLevelInfo?: (json: string) => void;
coinsData?: (json: string) => void;
/** 主站对接cocos-bridge.js 可选钩子 */
__tfrhOnExternalLevelInfo?: (json: string) => void;
[key: string]: unknown;
}
}
export class JsBridge {
static call(callbackName: string, jsonData: string) {
if (typeof window !== 'undefined') {
const fn = window[callbackName];
if (typeof fn === 'function') {
(fn as (json: string) => void)(jsonData);
return;
}
}
console.log(`[JsBridge] ${callbackName}`, jsonData);
}
/** Unity ExternalCallLevelInfo → Application.ExternalCall("externalLevelInfo", json) */
static notifyExternalLevelInfo(info: ExternalLevelInfo) {
const json = JSON.stringify(info);
this.call('externalLevelInfo', json);
}
}