| 12345678910111213141516171819202122232425262728293031323334353637 |
- import { _decorator, Component, Node, Vec3, tween } from 'cc';
- const { ccclass, property } = _decorator;
- /**
- * SkillButtonAnimator
- * 负责技能按钮的缩放 / 移动动画。
- * 提供 playShrink 接口供外部调用。
- */
- @ccclass('SkillButtonAnimator')
- export class SkillButtonAnimator extends Component {
- /**
- * 播放缩小并(可选)移动到指定目标位置的动画。
- * @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(() => {
- this.node.active = false; // 动画结束后隐藏节点
- if (onComplete) {
- onComplete();
- }
- })
- .start();
- }
- }
- export default SkillButtonAnimator;
|