feat: 提交资源
This commit is contained in:
57
assets/scripts/core/GlobalProtoInit.ts
Normal file
57
assets/scripts/core/GlobalProtoInit.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
/* eslint-disable no-console */
|
||||
/**
|
||||
* 全局 Proto 初始化
|
||||
*/
|
||||
|
||||
// import ProtoDefinitionsModule from "../protos/ProtoDefinitions.js";
|
||||
|
||||
import ProtoDefinitionsModule from "../protos/ProtoDefinitions.js";
|
||||
|
||||
// @ts-ignore
|
||||
|
||||
/**
|
||||
* 初始化全局 ProtoDefinitions
|
||||
*/
|
||||
export class GlobalProtoInit {
|
||||
// ProtoDefinitionsModule.
|
||||
private static _initialized = false;
|
||||
|
||||
/**
|
||||
* 初始化全局 Proto 定义
|
||||
*/
|
||||
public static init(): void {
|
||||
if (this._initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 将 ProtoDefinitions 挂载到全局对象
|
||||
|
||||
(globalThis as any).ProtoDefinitions = ProtoDefinitionsModule;
|
||||
|
||||
// 同时挂载到 window 对象(浏览器环境)
|
||||
if (typeof window !== "undefined") {
|
||||
(window as any).ProtoDefinitions = ProtoDefinitionsModule;
|
||||
}
|
||||
|
||||
this._initialized = true;
|
||||
console.log(
|
||||
"GlobalProtoInit",
|
||||
"ProtoDefinitions 已成功挂载到全局对象",
|
||||
);
|
||||
} catch (err) {
|
||||
console.error(
|
||||
"GlobalProtoInit",
|
||||
"初始化 ProtoDefinitions 失败:",
|
||||
err,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否已初始化
|
||||
*/
|
||||
public static isInitialized(): boolean {
|
||||
return this._initialized;
|
||||
}
|
||||
}
|
||||
9
assets/scripts/core/GlobalProtoInit.ts.meta
Normal file
9
assets/scripts/core/GlobalProtoInit.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "4145ae89-a1b6-4f79-88d1-c99b83e3c02d",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user