mirror of
https://gitee.com/dgflash/oops-plugin-framework.git
synced 2026-05-13 09:14:50 +08:00
2. 存储模块性能提升,添加LRU缓存、批量操作支持,优化内存使用 3. 多语言模块性能与内存管理优化,组件查询性能提升 4. 时间模块类型安全与性能优化,使用泛型替代any,对象池机制减少内存分配 5. 事件系统修复双重注册、重复注册等严重问题,实现EventData对象池减少GC压力 6. RandomManager修复4个逻辑BUG,包括边界问题和越界问题 7. 音频模块内存与性能优化,避免重复加载,优化数据结构,添加完整清理机制 8. CCView与CCViewVM合并,支持按需启用MVVM 9. Collection模块优化,AsyncQueue添加队列容量限制,Collection查询性能提升 10. ECS系统全面优化,对象池复用减少内存分配,循环性能提升 11. 优化MVVM组件性能
84 lines
2.3 KiB
TypeScript
84 lines
2.3 KiB
TypeScript
import type { EventTouch } from 'cc';
|
|
import { AudioClip, Component, Node, _decorator, game } from 'cc';
|
|
import { oops } from '../../../core/Oops';
|
|
|
|
const { ccclass, property, menu } = _decorator;
|
|
|
|
/** 节点按钮 */
|
|
@ccclass('ButtonSimple')
|
|
@menu('OopsFramework/Button/ButtonSimple (节点按钮)')
|
|
export default class ButtonSimple extends Component {
|
|
@property({
|
|
tooltip: '是否只触发一次'
|
|
})
|
|
private once = false;
|
|
|
|
@property({
|
|
tooltip: '每次触发间隔'
|
|
})
|
|
private interval = 500;
|
|
|
|
@property({
|
|
tooltip: '触摸音效',
|
|
type: AudioClip
|
|
})
|
|
private effect: AudioClip = null!;
|
|
|
|
/** 触摸次数计数 */
|
|
private touchCount = 0;
|
|
/** 上次触摸结束时间 */
|
|
private touchEndTime = 0;
|
|
|
|
private static effectPath: string = null!;
|
|
/** 批量设置触摸音效 */
|
|
static setBatchEffect(path: string) {
|
|
this.effectPath = path;
|
|
}
|
|
|
|
onLoad() {
|
|
this.node.on(Node.EventType.TOUCH_END, this.onTouchEnd, this);
|
|
this.node.on(Node.EventType.TOUCH_CANCEL, this.onTouchEnd, this);
|
|
}
|
|
|
|
/** 触摸结束 */
|
|
protected onTouchEnd(event: EventTouch) {
|
|
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;
|
|
|
|
// 短按触摸音效
|
|
this.playEffect();
|
|
}
|
|
}
|
|
|
|
/** 短按触摸音效 */
|
|
protected playEffect() {
|
|
if (ButtonSimple.effectPath) {
|
|
oops.audio.playEffect(ButtonSimple.effectPath);
|
|
}
|
|
else if (this.effect) {
|
|
oops.audio.playEffect(this.effect);
|
|
}
|
|
}
|
|
|
|
/** 组件销毁时的清理工作 */
|
|
onDestroy() {
|
|
this.node.off(Node.EventType.TOUCH_END, this.onTouchEnd, this);
|
|
this.node.off(Node.EventType.TOUCH_CANCEL, this.onTouchEnd, this);
|
|
|
|
// 清理音效引用
|
|
this.effect = null!;
|
|
}
|
|
}
|