mirror of
https://gitee.com/dgflash/oops-plugin-framework.git
synced 2026-06-23 19:22:47 +08:00
新增与优化核心模块 🎯 GUI 交互增强 ButtonInterceptor:按钮点击事件劫持器 劫持 EventHandler.emitEvents / ButtonSimple.onClick 核心方法 支持多类型按钮音效配置注册,按按钮类型自动匹配音效 单例模式管理,支持全局动态激活 / 停用拦截功能 🧩 对象池管理系统 GameNodePool:通用游戏节点对象池管理器 基于预制体(Prefab)UUID 实现池化隔离管理 支持特效、UI 元素等高频对象预加载、复用与回收 全局单例访问,统一管控对象创建 / 销毁逻辑 🔊 音频管理系统 AudioManager:音频核心管理器 独立背景音乐(AudioMusic)+ 音效池(AudioEffectPool)双模块 支持全局音量控制、播放状态恢复与场景切换管理 AudioEffect:基础音效播放器 AudioEnum:音频类型、音效分类枚举定义 📦 资源加载系统 ResLoader:资源加载核心控制器 资源包(Bundle)统一管理 + 并发加载限流控制 远程资源本地缓存、自动释放与内存优化 完整加载进度回调 + 错误异常处理机制 ResTypes:资源类型规范定义 ResErrors:资源加载错误码与异常处理 ResUtils:资源路径、格式转换等工具方法 🧱 模块化组件系统 GameComponent:游戏显示对象组件基类 集成资源自动引用计数(RC)管理 模块化部件(GamePartRegistry)插拔式架构 内置音频、按钮、事件、键盘、节点、对象池、资源七大部件 部件封装: GamePartAudio:音频功能部件 GamePartButton:按钮交互部件 GamePartEvent:全局事件部件 GamePartKeyboard:键盘输入部件 GamePartNode:节点操作部件 GamePartNodePool:对象池调用部件 GamePartRes:资源加载部件 📝 类型定义完善 新增 IAudio 音频数据与播放参数接口 统一全模块 TS 类型定义与导出规范 优化接口注释与类型约束,提升开发体验
101 lines
3.1 KiB
TypeScript
101 lines
3.1 KiB
TypeScript
import { GamePartAudio } from './part/GamePartAudio';
|
|
import { GamePartButton } from './part/GamePartButton';
|
|
import { GamePartNodePool } from './part/GamePartNodePool';
|
|
import { GamePartEvent } from './part/GamePartEvent';
|
|
import { GamePartKeyboard } from './part/GamePartKeyboard';
|
|
import { GamePartNode } from './part/GamePartNode';
|
|
import { GamePartRes } from './part/GamePartRes';
|
|
import { GamePartBase } from './GamePartBase';
|
|
|
|
/**
|
|
* 子模块注册键
|
|
* @remarks 枚举顺序即销毁顺序(先输入/音频/资源/特效,最后事件)
|
|
*/
|
|
export enum GamePartKey {
|
|
/** 按钮 */
|
|
Button = 'button',
|
|
/** 键盘 */
|
|
Keyboard = 'keyboard',
|
|
/** 音频 */
|
|
Audio = 'audio',
|
|
/** 资源 */
|
|
Res = 'res',
|
|
/** 节点池 */
|
|
Pool = 'pool',
|
|
/** 节点树 */
|
|
Nodes = 'nodes',
|
|
/** 全局事件 */
|
|
Event = 'event',
|
|
}
|
|
|
|
/** 模块创建器类型 */
|
|
type ModuleCreator = (comp: object) => GamePartBase;
|
|
|
|
/** 子模块懒加载注册表(统一登记、按序批量销毁) */
|
|
export class GamePartRegistry {
|
|
private instances: Map<GamePartKey, GamePartBase> | null = null;
|
|
private creators: Map<GamePartKey, ModuleCreator>;
|
|
|
|
/** 构造函数
|
|
* @param comp 宿主对象
|
|
* @param creators 模块创建器映射表
|
|
*/
|
|
constructor(
|
|
private readonly comp: object,
|
|
creators: Map<GamePartKey, ModuleCreator>
|
|
) {
|
|
this.creators = creators;
|
|
}
|
|
|
|
/** 获取实例映射表(延迟创建) */
|
|
private getInstances(): Map<GamePartKey, GamePartBase> {
|
|
if (!this.instances) {
|
|
this.instances = new Map<GamePartKey, GamePartBase>();
|
|
}
|
|
return this.instances;
|
|
}
|
|
|
|
/** 获取模块实例
|
|
* @param key 模块键
|
|
* @returns 模块实例
|
|
*/
|
|
get<M extends GamePartBase = GamePartBase>(key: GamePartKey): M {
|
|
const instances = this.getInstances();
|
|
let module = instances.get(key) as M | undefined;
|
|
if (!module) {
|
|
const creator = this.creators.get(key);
|
|
if (!creator) {
|
|
throw new Error(`未找到模块创建器: ${key}`);
|
|
}
|
|
module = creator(this.comp) as M;
|
|
instances.set(key, module);
|
|
}
|
|
return module;
|
|
}
|
|
|
|
/** 销毁所有模块 */
|
|
destroy(): void {
|
|
if (this.instances) {
|
|
for (const key of Object.values(GamePartKey)) {
|
|
this.instances.get(key)?.destroy();
|
|
}
|
|
this.instances.clear();
|
|
this.instances = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
const GAME_PART = new Map<GamePartKey, ModuleCreator>([
|
|
[GamePartKey.Button, (comp) => new GamePartButton(comp)],
|
|
[GamePartKey.Keyboard, (comp) => new GamePartKeyboard(comp)],
|
|
[GamePartKey.Audio, (comp) => new GamePartAudio(comp)],
|
|
[GamePartKey.Res, (comp) => new GamePartRes(comp)],
|
|
[GamePartKey.Pool, (comp) => new GamePartNodePool(comp)],
|
|
[GamePartKey.Nodes, (comp) => new GamePartNode(comp)],
|
|
[GamePartKey.Event, (comp) => new GamePartEvent(comp)],
|
|
]);
|
|
|
|
export function createPart(comp: object): GamePartRegistry {
|
|
return new GamePartRegistry(comp, GAME_PART);
|
|
}
|