1. 创建了通用引导预制体guide.prefab,包含手势提示节点 2. 实现GuideComp组件,支持引导状态跟踪、点击交互和自动销毁 3. 在角色控制和技能框预制体中接入引导组件,配置默认引导ID 4. 完成引导完成状态的本地记录与节点自动隐藏逻辑
93 lines
3.3 KiB
TypeScript
93 lines
3.3 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 } from "cc";
|
|
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
|
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
|
import { smc } from "../common/SingletonModuleComp";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass('GuideComp')
|
|
@ecs.register('GuideComp', false)
|
|
export class GuideComp extends CCComp {
|
|
/** 是否开启调试日志 */
|
|
private debugMode: boolean = true;
|
|
|
|
// ======================== 编辑器绑定节点 ========================
|
|
|
|
/** 手势图标节点 */
|
|
@property(Node)
|
|
hand: Node = null!
|
|
|
|
/** 引导编号 ID */
|
|
@property({ type: CCInteger })
|
|
guide_id: number = 0
|
|
|
|
|
|
onLoad() {
|
|
// 如果该引导已经完成,则隐藏并销毁本节点
|
|
if (smc.finish_guides.includes(this.guide_id)) {
|
|
this.node.active = false;
|
|
this.node.destroy();
|
|
return;
|
|
}
|
|
|
|
// 监听手势节点点击事件
|
|
if (this.hand) {
|
|
this.hand.on(NodeEventType.TOUCH_START, this.onTouchStart, this);
|
|
this.hand.on(NodeEventType.TOUCH_END, this.onGuideClick, this);
|
|
} else {
|
|
// 兜底:如果没有绑定手势节点,则监听自身节点
|
|
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;
|
|
|
|
// 完成后隐藏并销毁引导节点
|
|
this.node.active = false;
|
|
this.node.destroy();
|
|
}
|
|
|
|
/** 组件销毁时解绑所有事件,防止残留回调 */
|
|
onDestroy() {
|
|
if (this.hand && this.hand.isValid) {
|
|
this.hand.off(NodeEventType.TOUCH_START, this.onTouchStart, this);
|
|
this.hand.off(NodeEventType.TOUCH_END, this.onGuideClick, this);
|
|
}
|
|
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() {
|
|
|
|
}
|
|
|
|
/** ECS 组件移除时的释放钩子:销毁节点 */
|
|
reset() {
|
|
if (this.node && this.node.isValid) {
|
|
this.node.destroy();
|
|
}
|
|
}
|
|
}
|