将原ECS版本的GuideComp重构为原生Cocos Creator组件,移除冗余ECS依赖 优化引导点击与销毁逻辑,改用框架内置UI管理接口移除引导界面 更新guide1至guide4四个引导prefab,启用动画自动播放并调整动画配置 精简组件事件解绑逻辑,移除冗余的hand节点相关处理代码
75 lines
2.9 KiB
TypeScript
75 lines
2.9 KiB
TypeScript
|
||
import { mLogger } from "../common/Logger";
|
||
import { _decorator, Animation, AnimationClip, EventTouch, Label, Node, NodeEventType, Sprite, SpriteAtlas, Tween, tween, UIOpacity, Vec3, resources, Light, UITransform, Widget, CCInteger, CCString, Component } from "cc";
|
||
import { smc } from "../common/SingletonModuleComp";
|
||
import { UIID } from "../common/config/GameUIConfig";
|
||
import { oops } from "db://oops-framework/core/Oops";
|
||
|
||
const { ccclass, property } = _decorator;
|
||
|
||
@ccclass('GuideComp')
|
||
export class GuideComp extends Component {
|
||
/** 是否开启调试日志 */
|
||
private debugMode: boolean = true;
|
||
|
||
// ======================== 编辑器绑定节点 ========================
|
||
|
||
/** 引导编号 ID */
|
||
@property({ type: CCInteger })
|
||
guide_id: number = 0
|
||
|
||
onLoad() {
|
||
// 监听自身节点(即弹窗任意位置)的点击事件
|
||
this.node.on(NodeEventType.TOUCH_START, this.onTouchStart, this);
|
||
this.node.on(NodeEventType.TOUCH_END, this.onGuideClick, this);
|
||
}
|
||
|
||
private onTouchStart(event: EventTouch) {
|
||
// 允许事件穿透,确保底层的实际功能按钮能正常接收到 TOUCH_START 事件
|
||
event.preventSwallow = true;
|
||
}
|
||
|
||
private onGuideClick(event: EventTouch) {
|
||
// 记录该引导 ID 已完成
|
||
if (!smc.finish_guides.includes(this.guide_id)) {
|
||
smc.finish_guides.push(this.guide_id);
|
||
mLogger.log(this.debugMode, 'Guide', `完成引导 ID: ${this.guide_id}`);
|
||
|
||
// TODO: 若需要持久化保存,可在此处调用本地存储或同步到服务器的方法
|
||
// oops.storage.set("finish_guides", smc.finish_guides);
|
||
}
|
||
|
||
// 允许事件穿透,确保底层的实际功能按钮能正常接收到点击事件
|
||
event.preventSwallow = true;
|
||
|
||
// 因为通过 oops.gui.open(UIID) 弹出的界面,根节点可能会带有一个阻挡点击的遮罩组件(BlockInputEvents)
|
||
// 所以应当通过 oops.gui.remove 彻底从框架的层级管理中移除当前界面。
|
||
let targetUIID = -1;
|
||
if (this.guide_id === 1) targetUIID = UIID.Guide1;
|
||
if (this.guide_id === 2) targetUIID = UIID.Guide2;
|
||
if (this.guide_id === 3) targetUIID = UIID.Guide3;
|
||
if (this.guide_id === 4) targetUIID = UIID.Guide4;
|
||
|
||
if (targetUIID !== -1) {
|
||
oops.gui.remove(targetUIID);
|
||
} else {
|
||
// 兜底方案
|
||
this.node.active = false;
|
||
this.node.destroy();
|
||
}
|
||
}
|
||
|
||
/** 组件销毁时解绑所有事件,防止残留回调 */
|
||
onDestroy() {
|
||
if (this.node && this.node.isValid) {
|
||
this.node.off(NodeEventType.TOUCH_START, this.onTouchStart, this);
|
||
this.node.off(NodeEventType.TOUCH_END, this.onGuideClick, this);
|
||
}
|
||
}
|
||
|
||
/** 外部初始化入口(由 MissionGuideComp 调用) */
|
||
init() {
|
||
|
||
}
|
||
}
|