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>
This commit is contained in:
28
assets/scripts/bridge/JsBridge.ts
Normal file
28
assets/scripts/bridge/JsBridge.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* 对应 Unity Application.ExternalCall
|
||||
* Web 环境下调用 window 上的全局回调
|
||||
*/
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
processData?: (json: string) => void;
|
||||
processVehicleData?: (json: string) => void;
|
||||
externalResult?: (json: string) => void;
|
||||
externalLevelInfo?: (json: string) => void;
|
||||
coinsData?: (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);
|
||||
}
|
||||
}
|
||||
9
assets/scripts/bridge/JsBridge.ts.meta
Normal file
9
assets/scripts/bridge/JsBridge.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "d34fa121-5277-49b2-9938-ed0886a31fc4",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user