47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
/**
|
|
* 全局 Proto 初始化
|
|
*/
|
|
|
|
import { EDITOR } from "cc/env";
|
|
import ProtoDefinitionsModule from "../protos/ProtoDefinitions.js";
|
|
|
|
/**
|
|
* 初始化全局 ProtoDefinitions
|
|
*/
|
|
export class GlobalProtoInit {
|
|
private static _initialized = false;
|
|
|
|
/**
|
|
* 初始化全局 Proto 定义
|
|
*/
|
|
public static init(): void {
|
|
if (this._initialized) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
// 将 ProtoDefinitions 挂载到全局对象
|
|
// 同时挂载到 window 对象(浏览器环境)
|
|
if (typeof window !== "undefined") {
|
|
window.ProtoDefinitions = ProtoDefinitionsModule;
|
|
}
|
|
|
|
this._initialized = true;
|
|
console.log("GlobalProtoInit", "ProtoDefinitions 已成功挂载到全局对象");
|
|
} catch (err) {
|
|
console.error("GlobalProtoInit", "初始化 ProtoDefinitions 失败:", err);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 检查是否已初始化
|
|
*/
|
|
public static isInitialized(): boolean {
|
|
return this._initialized;
|
|
}
|
|
}
|
|
|
|
if (!EDITOR) {
|
|
GlobalProtoInit.init();
|
|
}
|