mirror of
https://gitee.com/dgflash/oops-plugin-framework.git
synced 2026-09-27 04:57:36 +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 类型定义与导出规范 优化接口注释与类型约束,提升开发体验
104 lines
2.9 KiB
TypeScript
104 lines
2.9 KiB
TypeScript
import type { EventTouch } from 'cc';
|
|
import { Button, Component, EventHandler, _decorator, game } from 'cc';
|
|
|
|
const { ccclass, property, menu, requireComponent } = _decorator;
|
|
|
|
/**
|
|
* 通用按钮
|
|
* 1、防连点
|
|
* 2、支持只触发一次
|
|
*
|
|
* 注意:此组件需要配合 Button 组件使用,会自动添加 Button 组件
|
|
*/
|
|
@ccclass('UIButton')
|
|
@menu('OopsFramework/Button/UIButton (通用按钮)')
|
|
@requireComponent(Button)
|
|
export default class UIButton extends Component {
|
|
@property({
|
|
tooltip: '每次触发间隔(毫秒)'
|
|
})
|
|
private interval = 500;
|
|
|
|
@property({
|
|
tooltip: '是否只触发一次'
|
|
})
|
|
private once = false;
|
|
|
|
/** 触摸次数 */
|
|
private _touchCount = 0;
|
|
/** 触摸结束时间 */
|
|
private _touchEndTime = 0;
|
|
/** 按钮组件引用 */
|
|
private _button: Button | null = null;
|
|
/** 原始触摸结束回调 */
|
|
private _originalTouchEnded: Function | null = null;
|
|
|
|
onLoad() {
|
|
this._button = this.getComponent(Button);
|
|
if (!this._button) {
|
|
console.warn('[UIButton] 未找到 Button 组件,请确保节点上有 Button 组件');
|
|
return;
|
|
}
|
|
|
|
// 保存原始回调并劫持
|
|
// @ts-ignore
|
|
this._originalTouchEnded = this._button._onTouchEnded;
|
|
// @ts-ignore
|
|
this._button._onTouchEnded = this._onTouchEnded.bind(this);
|
|
}
|
|
|
|
/**
|
|
* 触摸结束事件处理
|
|
* @param event 触摸事件
|
|
*/
|
|
private _onTouchEnded(event: EventTouch) {
|
|
if (!this._button) return;
|
|
|
|
// @ts-ignore
|
|
if (!this._button._interactable || !this._button.enabledInHierarchy) {
|
|
return;
|
|
}
|
|
|
|
// @ts-ignore
|
|
if (this._button._pressed) {
|
|
// 是否只触发一次
|
|
if (this.once) {
|
|
if (this._touchCount > 0) {
|
|
event.propagationStopped = true;
|
|
return;
|
|
}
|
|
this._touchCount++;
|
|
}
|
|
|
|
// 防连点,根据设置的间隔触发一次事件
|
|
if (this._touchEndTime && game.totalTime - this._touchEndTime < this.interval) {
|
|
event.propagationStopped = true;
|
|
}
|
|
else {
|
|
this._touchEndTime = game.totalTime;
|
|
EventHandler.emitEvents(this._button.clickEvents, event);
|
|
this.node.emit(Button.EventType.CLICK, this._button);
|
|
}
|
|
}
|
|
|
|
// @ts-ignore
|
|
this._button._pressed = false;
|
|
// @ts-ignore
|
|
this._button._updateState();
|
|
|
|
if (event) {
|
|
event.propagationStopped = true;
|
|
}
|
|
}
|
|
|
|
onDestroy() {
|
|
// 恢复原始回调
|
|
if (this._button && this._originalTouchEnded) {
|
|
// @ts-ignore
|
|
this._button._onTouchEnded = this._originalTouchEnded;
|
|
}
|
|
this._button = null;
|
|
this._originalTouchEnded = null;
|
|
}
|
|
}
|