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 } 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! /** 手势图标节点 */ @property(Node) clickNode: Node = null! /** 引导编号 ID */ @property({ type: CCInteger }) guide_id: number = 0 /** 动画名称 ID */ @property({ type: CCString }) animation_name: string = 'dianji'; onLoad() { // 如果该引导已经完成,则隐藏并销毁本节点 if (smc.finish_guides.includes(this.guide_id)) { this.node.active = false; this.node.destroy(); return; } // 播放手势动画 if (this.hand && this.animation_name) { // 延迟一帧播放,防止组件还未完全激活 this.scheduleOnce(() => { if (!this.isValid) return; // 防止节点已被销毁 // 1. 先尝试在绑定的 this.hand 本身上查找 Animation 组件 let anim = this.hand.getComponent(Animation); // 2. 如果没找到,再尝试去它的子节点上找 if (!anim) { anim = this.hand.getComponentInChildren(Animation); } if (anim) { // 确保目标动画状态存在 const animState = anim.getState(this.animation_name); if (animState) { anim.play(this.animation_name); mLogger.log(this.debugMode, 'Guide', `成功播放引导动画: ${this.animation_name}`); } else { mLogger.warn(this.debugMode, 'Guide', `找到了 Animation 组件,但组件内未挂载名为 '${this.animation_name}' 的动画剪辑(Clip)。请检查编辑器 Animation 组件的 Clips 列表!`); } } else { mLogger.warn(this.debugMode, 'Guide', `在 hand 节点及其子节点下均未找到 Animation 组件,无法播放动画: ${this.animation_name}`); } }); } } /** * 完成当前引导操作 * (现在通过编辑器绑定 Button 组件或代码显式调用触发) */ public onGuideClick() { // 记录该引导 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); } // 完成后隐藏并销毁引导节点 this.node.active = false; this.node.destroy(); } /** 组件销毁时解绑所有事件,防止残留回调 */ onDestroy() { } /** 外部初始化入口(由 MissionGuideComp 调用) */ init() { } /** ECS 组件移除时的释放钩子:销毁节点 */ reset() { if (this.node && this.node.isValid) { this.node.destroy(); } } }