import { _decorator, Component, Node, Vec3, tween } from 'cc'; const { ccclass, property } = _decorator; /** * SkillButtonAnimator * 负责技能按钮的缩放 / 移动动画。 * 提供 playShrink 接口供外部调用。 */ @ccclass('SkillButtonAnimator') export class SkillButtonAnimator extends Component { private _origScale: Vec3 = new Vec3(); private _origPos: Vec3 = new Vec3(); onLoad () { // 记录初始位置、缩放,用于恢复 this._origScale.set(this.node.scale); this._origPos.set(this.node.position); } /** * 播放缩小并(可选)移动到指定目标位置的动画。 * @param duration 动画时长(秒) * @param targetPos 目标位置(节点本地坐标系),不传则保持原位置 * @param onComplete 完成回调 */ public playShrink(duration: number = 0.3, targetPos?: Vec3, onComplete?: () => void) { // 若目标位置存在,则先 tween 到该位置;否则只缩放 const props: any = { scale: new Vec3(0, 0, 0) }; if (targetPos) { props.position = targetPos; } tween(this.node) .to(duration, props, { easing: 'quadIn' }) .call(() => { // 动画结束后隐藏节点,但允许后续 resetState 恢复 this.node.active = false; if (onComplete) onComplete(); }) .start(); this.node.setPosition(this._origPos); } public resetState() { // Reset scale, position, opacity, etc. as needed this.node.setScale(Vec3.ONE); this.node.active = true; // this.node.setPosition(this._initPos); // this.node.opacity = 255; } } export default SkillButtonAnimator;