From 37900d82191746cde9d29433d12b50407c014a2f Mon Sep 17 00:00:00 2001 From: dgflash Date: Mon, 15 Sep 2025 14:40:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A1=86=E6=9E=B6=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=A0=BC=E5=BC=8F=EF=BC=8C=E6=94=AF=E6=8C=81=E5=88=86?= =?UTF-8?q?=E7=BB=84=E8=AE=BE=E7=BD=AE=E6=B8=B8=E6=88=8F=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=EF=BC=8C=E6=96=B9=E4=BE=BF=E5=BC=80=E5=8F=91=E3=80=81=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E3=80=81=E7=94=9F=E4=BA=A7=E7=8E=AF=E5=A2=83=E5=88=87?= =?UTF-8?q?=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/core/Root.ts | 4 +- assets/module/config/BuildTimeConstants.ts | 2 +- assets/module/config/Config.ts | 3 +- assets/module/config/GameConfig.ts | 76 +++++++++++++--------- 4 files changed, 51 insertions(+), 34 deletions(-) diff --git a/assets/core/Root.ts b/assets/core/Root.ts index a0ae880..98e18cb 100644 --- a/assets/core/Root.ts +++ b/assets/core/Root.ts @@ -4,7 +4,7 @@ * @LastEditors: dgflash * @LastEditTime: 2023-08-28 10:02:57 */ -import { _decorator, Component, director, Game, game, JsonAsset, Node, resources, screen, sys } from "cc"; +import { _decorator, Component, director, Game, game, JsonAsset, Node, profiler, resources, screen, sys } from "cc"; import { GameConfig } from "../module/config/GameConfig"; import { GameQueryConfig } from "../module/config/GameQueryConfig"; import { oops, version } from "./Oops"; @@ -94,6 +94,8 @@ export class Root extends Component { //@ts-ignore oops.gui.initLayer(this.gui, config.json.gui); + // 初始化统计信息 + oops.config.game.stats ? profiler.showStats() : profiler.hideStats(); // 初始化每秒传输帧数 game.frameRate = oops.config.game.frameRate; diff --git a/assets/module/config/BuildTimeConstants.ts b/assets/module/config/BuildTimeConstants.ts index 89cfa74..81fc32a 100644 --- a/assets/module/config/BuildTimeConstants.ts +++ b/assets/module/config/BuildTimeConstants.ts @@ -10,7 +10,7 @@ const keys = (Object.keys(buildTimeConstants) as (keyof typeof buildTimeConstant /* 游戏运行环境 */ export class BuildTimeConstants { - constructor() { + toString() { const keyNameMaxLen = keys.reduce((len, key) => Math.max(len, key.length), 0); const enviroment = `${keys.map((key) => { const value = buildTimeConstants[key]; diff --git a/assets/module/config/Config.ts b/assets/module/config/Config.ts index e3fece8..1a1b830 100644 --- a/assets/module/config/Config.ts +++ b/assets/module/config/Config.ts @@ -5,13 +5,14 @@ * @LastEditTime: 2022-11-01 15:47:16 */ +import { BuildTimeConstants } from "./BuildTimeConstants"; import { GameConfig } from "./GameConfig"; import { GameQueryConfig } from "./GameQueryConfig"; /** 游戏配置静态访问类 */ export class Config { /** 环境常量 */ - // btc!: BuildTimeConstants; + btc: BuildTimeConstants = new BuildTimeConstants(); /** 游戏配置数据,版本号、支持语种等数据 */ game!: GameConfig; diff --git a/assets/module/config/GameConfig.ts b/assets/module/config/GameConfig.ts index 06e7eca..2f0ac6c 100644 --- a/assets/module/config/GameConfig.ts +++ b/assets/module/config/GameConfig.ts @@ -20,27 +20,55 @@ export enum GameConfigCustomType { export class GameConfig { /** 客户端版本号配置 */ get version(): string { - return this._data.config.version; - } - /** 游戏每秒传输帧数 */ - get frameRate(): number { - return this._data.config.frameRate; + return this.data.version; } /** 本地存储内容加密 key */ get localDataKey(): string { - return this._data.config.localDataKey; + return this.data.localDataKey; } /** 本地存储内容加密 iv */ get localDataIv(): string { - return this._data.config.localDataIv; + return this.data.localDataIv; + } + /** 游戏每秒传输帧数 */ + get frameRate(): number { + return this.data.frameRate; + } + /** 是否开启移动设备安全区域适配 */ + get mobileSafeArea(): boolean { + return this.data.mobileSafeArea || false; + } + /** 加载界面资源超时提示 */ + get loadingTimeoutGui(): number { + return this.data.loadingTimeoutGui || 1000; + } + /** 是否显示统计信息 */ + get stats(): number { + return this.data.stats; } /** Http 服务器地址 */ get httpServer(): string { - return this._data.config.httpServer; + return this.data.httpServer; } /** Http 请求超时时间 */ get httpTimeout(): number { - return this._data.config.httpTimeout; + return this.data.httpTimeout; + } + /** WebSocket 服务器地址 */ + get webSocketServer(): string { + return this.data.webSocketServer; + } + /** WebSocket 心跳间隔时间(毫秒) */ + get webSocketHeartTime(): number { + return this.data.webSocketHeartTime; + } + /** WebSocket 指定时间没收到消息就断开连接(毫秒) */ + get webSocketReceiveTime(): number { + return this.data.webSocketReceiveTime; + } + /** WebSocket 重连间隔时间(毫秒) */ + get webSocketReconnetTimeOut(): number { + return this.data.webSocketReconnetTimeOut; } /** 获取当前客户端支持的语言类型 */ @@ -65,40 +93,26 @@ export class GameConfig { return this._data.bundle.default; } - /** 加载界面资源超时提示 */ - get loadingTimeoutGui(): number { - return this._data.config.loadingTimeoutGui || 1000; - } - - /** 是否开启移动设备安全区域适配 */ - get mobileSafeArea(): boolean { - return this._data.config.mobileSafeArea || false; - } - private _data: any = null; /** 游戏配置数据 */ get data(): any { - return this._data; + return this._data.config[this._configType]; } + /** 当前游戏配置分组类型 */ + private _configType: GameConfigCustomType = GameConfigCustomType.Prod; + constructor(config: any) { this._data = Object.freeze(config.json); - + this.setConfigType(this._data.type); oops.log.logConfig(this._data, "游戏配置"); } - private _customType: GameConfigCustomType = GameConfigCustomType.Dev; - /** - * 设置自定义游戏参数配置类型 + * 设置游戏参数类型 * @param type */ - setCustomType(type: GameConfigCustomType) { - this._customType = type; - } - - /** 获取游戏自定义配置 */ - get custom(): any { - return this.data.custom[this._customType]; + setConfigType(type: GameConfigCustomType) { + this._configType = type; } } \ No newline at end of file