ConfigManager改全局单例

This commit is contained in:
2025-08-15 15:24:31 +08:00
parent 30e8effe86
commit 599c98f135
9 changed files with 361 additions and 376 deletions
@@ -1,22 +1,28 @@
import {
_decorator,
resources,
BufferAsset,
Component,
assetManager,
AssetManager,
} from "cc";
import * as cfg from "../../schema/schema";
import ByteBuf from "db://assets/Scripts/luban/ByteBuf";
const { ccclass, property } = _decorator;
@ccclass("ConfigManager")
export default class ConfigManager extends Component {
export default class ConfigManager {
private static _instance: ConfigManager = null;
public static get I(): ConfigManager {
if (!this._instance) {
this._instance = new ConfigManager();
}
return this._instance;
}
public static tables: cfg.Tables = null;
private static dataMap = new Map<string, Uint8Array>();
public static jsonFileNames: string[] = [];
onLoad() {
private constructor() {}
public init() {
this.loadAllConfig();
}
@@ -65,7 +71,7 @@ export default class ConfigManager extends Component {
}
Promise.all(promises).then((values) => {
console.log("静态配置加载完成");
ConfigManager.tables = new cfg.Tables(this.getFileData);
ConfigManager.tables = new cfg.Tables(ConfigManager.I.getFileData);
for (let item of ConfigManager.tables.TbGirls.getDataList()) {
console.log(item);
}
@@ -71,14 +71,14 @@ export class ThemePanel extends li_BaseView {
this.cache.push(item);
this.content.addChild(newNode);
}
const rectInfo = cfgs[0];
const rectInfo = ConfigManager.tables.TbGirls.get(10001);
this.recId = rectInfo.id;
this.rectNameKey = rectInfo.key;
this.rectNameKey = rectInfo.nameKey;
//this.recName.string = LanguageUtils.getText(this.rectNameKey);
ResManager.I.changeBundleSpriteFrame(
this.recSprite,
rectInfo.path,
rectInfo.avatarPath,
"Chat18x",
() => {
let sizeTran = this.recSprite.node.parent.getComponent(UITransform);