feat(guide): 新增新手引导系统功能

1.  创建了通用引导预制体guide.prefab,包含手势提示节点
2.  实现GuideComp组件,支持引导状态跟踪、点击交互和自动销毁
3.  在角色控制和技能框预制体中接入引导组件,配置默认引导ID
4.  完成引导完成状态的本地记录与节点自动隐藏逻辑
This commit is contained in:
pan
2026-06-11 16:32:05 +08:00
parent 193beb0d24
commit 1c74138334
6 changed files with 2680 additions and 1034 deletions

View File

@@ -3,9 +3,7 @@ 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;
@@ -20,18 +18,64 @@ export class GuideComp extends CCComp {
/** 手势图标节点 */
@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 调用) */
@@ -39,9 +83,10 @@ export class GuideComp extends CCComp {
}
/** ECS 组件移除时的释放钩子:销毁节点 */
reset() {
this.node.destroy();
if (this.node && this.node.isValid) {
this.node.destroy();
}
}
}