From c0bfcf4992879abb93d33d55639374cc7fe300af Mon Sep 17 00:00:00 2001 From: dgflash Date: Mon, 28 Apr 2025 10:24:52 +0800 Subject: [PATCH 1/6] =?UTF-8?q?LabelTime=E7=BB=84=E4=BB=B6=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=B8=B8=E6=88=8F=E8=BF=9B=E5=85=A5=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E6=9A=82=E5=81=9C=E6=97=B6=E9=97=B4=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/libs/gui/label/LabelTime.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/assets/libs/gui/label/LabelTime.ts b/assets/libs/gui/label/LabelTime.ts index deceeee..7831f6d 100644 --- a/assets/libs/gui/label/LabelTime.ts +++ b/assets/libs/gui/label/LabelTime.ts @@ -30,6 +30,11 @@ export default class LabelTime extends Label { }) zeroize: boolean = true; + @property({ + tooltip: "游戏进入后台时间暂时", + }) + paused: boolean = false; + private backStartTime: number = 0; // 进入后台开始时间 private dateDisable!: boolean; // 时间能否由天数显示 private result!: string; // 时间结果字符串 @@ -152,6 +157,11 @@ export default class LabelTime extends Label { } private onGameShow() { + // 时间到了 + if (this.countDown <= 0) return; + // 时间暂停 + if (this.paused) return; + const interval = Math.floor((oops.timer.getTime() - (this.backStartTime || oops.timer.getTime())) / 1000); this.countDown -= interval; if (this.countDown < 0) { -- Gitee From d81c8019ebf79261aed719d8d66c6b72fd9a69c9 Mon Sep 17 00:00:00 2001 From: dgflash Date: Wed, 7 May 2025 20:23:41 +0800 Subject: [PATCH 2/6] =?UTF-8?q?ModuleUtil.addView=20=E6=B7=BB=E5=8A=A0=20b?= =?UTF-8?q?undleName=20=E8=B5=84=E6=BA=90=E5=8C=85=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/module/common/ModuleUtil.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/assets/module/common/ModuleUtil.ts b/assets/module/common/ModuleUtil.ts index 089588a..43b4d38 100644 --- a/assets/module/common/ModuleUtil.ts +++ b/assets/module/common/ModuleUtil.ts @@ -1,5 +1,6 @@ import { Node, __private } from "cc"; import { oops } from "../../core/Oops"; +import { resLoader } from "../../core/common/loader/ResLoader"; import { UICallbacks } from "../../core/gui/layer/Defines"; import { ViewUtil } from "../../core/utils/ViewUtil"; import { ecs } from "../../libs/ecs/ECS"; @@ -60,17 +61,19 @@ export class ModuleUtil { /** * 通过资源内存中获取预制上的组件添加到ECS实体中 - * @param ent 模块实体 - * @param ctor 界面逻辑组件 - * @param parent 显示对象父级 - * @param url 显示资源地址 + * @param ent 模块实体 + * @param ctor 界面逻辑组件 + * @param parent 显示对象父级 + * @param url 显示资源地址 + * @param bundleName 资源包名称 */ static addView( ent: ecs.Entity, ctor: __private.__types_globals__Constructor | __private.__types_globals__AbstractedConstructor, parent: Node, - url: string) { - const node = ViewUtil.createPrefabNode(url); + url: string, + bundleName: string = resLoader.defaultBundleName) { + const node = ViewUtil.createPrefabNode(url, bundleName); const comp = node.getComponent(ctor)!; ent.add(comp); node.parent = parent; -- Gitee From ab6bc88fa1041fe74885c9e25200bf0fce7a4885 Mon Sep 17 00:00:00 2001 From: dgflash Date: Sat, 10 May 2025 20:32:59 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/core/gui/layer/LayerNotify.ts | 13 ++++++++----- assets/core/gui/layer/LayerPopup.ts | 5 +---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/assets/core/gui/layer/LayerNotify.ts b/assets/core/gui/layer/LayerNotify.ts index b5aa1d7..6794aa4 100644 --- a/assets/core/gui/layer/LayerNotify.ts +++ b/assets/core/gui/layer/LayerNotify.ts @@ -8,6 +8,8 @@ import { BlockInputEvents, Layers, Node, Widget, instantiate } from "cc"; import { ViewUtil } from "../../utils/ViewUtil"; import { PromptResType } from "../GuiEnum"; import { Notify } from "../prompt/Notify"; +import { sys } from "cc"; +import { EDITOR, EDITOR_NOT_IN_PREVIEW } from "cc/env"; /* * 滚动消息提示层 @@ -29,10 +31,7 @@ export class LayerNotify extends Node { widget.left = widget.right = widget.top = widget.bottom = 0; widget.alignMode = 2; widget.enabled = true; - this.init(); - } - private init() { this.layer = Layers.Enum.UI_2D; this.black = this.addComponent(BlockInputEvents); this.black.enabled = false; @@ -67,9 +66,13 @@ export class LayerNotify extends Node { */ async toast(content: string, useI18n: boolean) { if (this.notify == null) { - this.notify = ViewUtil.createPrefabNode(PromptResType.Toast); // 兼容编辑器预览模式 - if (this.notify == null) this.notify = await ViewUtil.createPrefabNodeAsync(PromptResType.Toast); + if (EDITOR) { + this.notify = await ViewUtil.createPrefabNodeAsync(PromptResType.Toast); + } + else { + this.notify = ViewUtil.createPrefabNode(PromptResType.Toast); + } this.notifyItem = this.notify.children[0]; this.notifyItem.parent = null; } diff --git a/assets/core/gui/layer/LayerPopup.ts b/assets/core/gui/layer/LayerPopup.ts index b12888d..c3a397b 100644 --- a/assets/core/gui/layer/LayerPopup.ts +++ b/assets/core/gui/layer/LayerPopup.ts @@ -20,10 +20,7 @@ export class LayerPopUp extends LayerUI { constructor(name: string) { super(name); - this.init(); - } - - private init() { + this.layer = Layers.Enum.UI_2D; this.on(Node.EventType.CHILD_ADDED, this.onChildAdded, this); this.on(Node.EventType.CHILD_REMOVED, this.onChildRemoved, this); -- Gitee From 1a867759ec4d4c1136e543c1d90b13a476c823a2 Mon Sep 17 00:00:00 2001 From: dgflash Date: Sat, 10 May 2025 20:46:01 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/core/gui/layer/LayerNotify.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/assets/core/gui/layer/LayerNotify.ts b/assets/core/gui/layer/LayerNotify.ts index 6794aa4..e57c7e2 100644 --- a/assets/core/gui/layer/LayerNotify.ts +++ b/assets/core/gui/layer/LayerNotify.ts @@ -5,11 +5,10 @@ * @LastEditTime: 2022-09-02 13:44:12 */ import { BlockInputEvents, Layers, Node, Widget, instantiate } from "cc"; +import { EDITOR } from "cc/env"; import { ViewUtil } from "../../utils/ViewUtil"; import { PromptResType } from "../GuiEnum"; import { Notify } from "../prompt/Notify"; -import { sys } from "cc"; -import { EDITOR, EDITOR_NOT_IN_PREVIEW } from "cc/env"; /* * 滚动消息提示层 @@ -40,9 +39,13 @@ export class LayerNotify extends Node { /** 打开等待提示 */ async waitOpen() { if (this.wait == null) { - this.wait = ViewUtil.createPrefabNode(PromptResType.Wait); // 兼容编辑器预览模式 - if (this.wait == null) this.wait = await ViewUtil.createPrefabNodeAsync(PromptResType.Wait); + if (EDITOR) { + this.wait = await ViewUtil.createPrefabNodeAsync(PromptResType.Wait); + } + else { + this.wait = ViewUtil.createPrefabNode(PromptResType.Wait); + } } if (this.wait.parent == null) { -- Gitee From 04d5c9ae357e1d763248f4a75ef668c8fbcd32a5 Mon Sep 17 00:00:00 2001 From: dgflash Date: Sun, 11 May 2025 16:47:44 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E7=A7=BB=E9=99=A4=E8=BF=9C=E7=A8=8B=E5=8C=85?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=95=B0=E6=8D=AE=EF=BC=8C=E7=8E=B0=E4=BD=BF?= =?UTF-8?q?=E7=94=A8cc=E5=BC=95=E6=93=8E=E4=B8=AD=E8=BF=9C=E7=A8=8B?= =?UTF-8?q?=E5=8C=85=E9=85=8D=E7=BD=AE=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/core/Root.ts | 1 - assets/core/common/loader/ResLoader.ts | 31 ++++++-------------------- 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/assets/core/Root.ts b/assets/core/Root.ts index bcc5fad..693b9f6 100644 --- a/assets/core/Root.ts +++ b/assets/core/Root.ts @@ -90,7 +90,6 @@ export class Root extends Component { // 设置默认资源包 oops.res.defaultBundleName = oops.config.game.bundleDefault; - oops.res.init(oops.config.game.data.bundle); // 游戏界面管理 oops.gui.mobileSafeArea = oops.config.game.mobileSafeArea; diff --git a/assets/core/common/loader/ResLoader.ts b/assets/core/common/loader/ResLoader.ts index 3ea8049..8489f6e 100644 --- a/assets/core/common/loader/ResLoader.ts +++ b/assets/core/common/loader/ResLoader.ts @@ -1,4 +1,4 @@ -import { Asset, AssetManager, __private, assetManager, error, js, resources, warn } from "cc"; +import { __private, Asset, AssetManager, assetManager, error, js, resources, warn } from "cc"; export type AssetType = __private.__types_globals__Constructor | null; export type Paths = string | string[]; @@ -35,8 +35,6 @@ export class ResLoader { //#region 资源配置数据 /** 全局默认加载的资源包名 */ defaultBundleName: string = "resources"; - /** 是否使用远程 CDN 资源 */ - cdn: boolean = false; /** 下载时的最大并发数 - 项目设置 -> 项目数据 -> 资源下载并发数,设置默认值;初始值为15 */ get maxConcurrency() { @@ -70,17 +68,6 @@ export class ResLoader { assetManager.downloader.retryInterval = value; } - /** 资源包配置 */ - private bundles: Map = new Map(); - //#endregion - - init(config: any) { - this.cdn = config.enable; - for (let bundleName in config.packages) { - this.bundles.set(bundleName, config.packages[bundleName]); - } - } - //#region 加载远程资源 /** * 加载远程资源 @@ -120,16 +107,13 @@ oops.res.loadRemote(this.url, opt, onComplete); //#region 资源包管理 /** * 加载资源包 - * @param url 资源地址 - * @param v 资源MD5版本号 + * @param name 资源地址 * @example -var serverUrl = "http://192.168.1.8:8080/"; // 服务器地址 -var md5 = "8e5c0"; // Cocos Creator 构建后的MD5字符 -await oops.res.loadBundle(serverUrl,md5); + await oops.res.loadBundle(name); */ - loadBundle(url: string, v?: string) { + loadBundle(name: string) { return new Promise((resolve, reject) => { - assetManager.loadBundle(url, { version: v }, (err, bundle: AssetManager.Bundle) => { + assetManager.loadBundle(name, (err, bundle: AssetManager.Bundle) => { if (err) { return error(err); } @@ -366,7 +350,7 @@ oops.res.loadDir("game", onProgressCallback, onCompleteCallback); */ release(path: string, bundleName?: string) { if (bundleName == undefined) bundleName = this.defaultBundleName; - + const bundle = assetManager.getBundle(bundleName); if (bundle) { const asset = bundle.get(path); @@ -483,8 +467,7 @@ oops.res.loadDir("game", onProgressCallback, onCompleteCallback); } // 自动加载资源包 else { - const v = this.cdn ? this.bundles.get(args.bundle) : ""; - bundle = await this.loadBundle(args.bundle, v); + bundle = await this.loadBundle(args.bundle); if (bundle) this.loadByBundleAndArgs(bundle, args); } } -- Gitee From e865c808a9f4e0a867a45934e764996185152e68 Mon Sep 17 00:00:00 2001 From: dgflash Date: Wed, 14 May 2025 10:38:04 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=9F=B3=E4=B9=90?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=AF=B9=E8=B1=A1=E6=B1=A0=E5=90=8C=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E8=B5=84=E6=BA=90=E5=8C=85=E4=B8=AD=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E7=9B=B8=E4=BA=92=E8=A6=86=E7=9B=96=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=EF=BC=8C=E9=87=8A=E6=94=BE=E9=9F=B3=E6=95=88=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E6=97=B6=E5=86=85=E5=AD=98=E6=B3=84=E6=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/core/Root.ts | 33 +++++++++------------ assets/core/common/audio/AudioEffectPool.ts | 18 +++++++---- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/assets/core/Root.ts b/assets/core/Root.ts index 693b9f6..a0ae880 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, screen, sys } from "cc"; +import { _decorator, Component, director, Game, game, JsonAsset, Node, resources, screen, sys } from "cc"; import { GameConfig } from "../module/config/GameConfig"; import { GameQueryConfig } from "../module/config/GameQueryConfig"; import { oops, version } from "./Oops"; @@ -20,8 +20,6 @@ import { LayerManager } from "./gui/layer/LayerManager"; const { property } = _decorator; -let isInited = false; - /** 框架显示层根节点 */ export class Root extends Component { /** 游戏层节点 */ @@ -42,16 +40,12 @@ export class Root extends Component { private persist: Node = null! onLoad() { - if (!isInited) { - isInited = true; // 注:这里是规避cc3.8在编辑器模式下运行时,关闭游戏会两次初始化报错 - - console.log(`Oops Framework ${version}`); - this.enabled = false; + console.log(`Oops Framework ${version}`); + this.enabled = false; - this.initModule(); - this.iniStart(); - this.loadConfig().then(); - } + this.initModule(); + this.iniStart(); + this.loadConfig().then(); } private initModule() { @@ -75,8 +69,12 @@ export class Root extends Component { private async loadConfig() { const config_name = "config"; - const config = await oops.res.loadAsync(config_name, JsonAsset); - if (config) { + resources.load(config_name, JsonAsset, (err, config) => { + if (err) { + this.loadConfig().then(); + return; + } + oops.config.game = new GameConfig(config); // 本地存储模块 @@ -103,11 +101,8 @@ export class Root extends Component { this.init(); this.run(); - oops.res.release(config_name); - } - else { - this.loadConfig().then(); - } + resources.release(config_name); + }); } update(dt: number) { diff --git a/assets/core/common/audio/AudioEffectPool.ts b/assets/core/common/audio/AudioEffectPool.ts index f24d950..e4f3a71 100644 --- a/assets/core/common/audio/AudioEffectPool.ts +++ b/assets/core/common/audio/AudioEffectPool.ts @@ -35,7 +35,7 @@ export class AudioEffectPool { /** 对象池集合 */ private effects: Map = new Map(); /** 用过的音效资源记录 */ - private res: Map = new Map(); + private res: Map = new Map(); private _aeId: number = 0; /** 获取请求唯一编号 */ @@ -63,8 +63,16 @@ export class AudioEffectPool { } else { clip = resLoader.get(url, AudioClip, bundleName)!; - if (!clip) { - this.res.set(bundleName, url); + if (clip == null) { + let urls = this.res.get(bundleName); + if (urls == null) { + urls = []; + this.res.set(bundleName, urls); + urls.push(url); + } + else if (urls.indexOf(url) == -1) { + urls.push(url); + } clip = await resLoader.loadAsync(bundleName, url, AudioClip); } } @@ -148,8 +156,8 @@ export class AudioEffectPool { this.effects.clear(); // 释放音效资源 - this.res.forEach((url: string, bundleName: string) => { - resLoader.release(bundleName, url); + this.res.forEach((urls: string[], bundleName: string) => { + urls.forEach(url => resLoader.release(bundleName, url)); }); // 释放池中播放器 -- Gitee