import { _decorator, Component, Node, tween, Vec3 } from 'cc'; const { ccclass, property } = _decorator; /** * 升级面板动画控制器 * 负责管理升级面板的显示和隐藏动画 */ @ccclass('UpgradeAni') export class UpgradeAni extends Component { /** * 显示面板动画 * 面板从小到大的缩放动画,从屏幕中央弹出 */ public showPanel(): Promise { return new Promise((resolve) => { // 设置初始状态:缩小到0,位置居中 this.node.setScale(Vec3.ZERO); this.node.setPosition(0, 0, 0); // 确保面板在屏幕正中间 this.node.active = true; // 缩放动画:从0放大到1 tween(this.node) .to(0.3, { scale: new Vec3(1, 1, 1) }, { easing: 'backOut' // 使用回弹缓动效果 }) .call(() => { resolve(); }) .start(); }); } /** * 隐藏面板动画 * 面板从大到小的缩放动画 */ public hidePanel(): Promise { return new Promise((resolve) => { // 缩放动画:从1缩小到0 tween(this.node) .to(0.2, { scale: Vec3.ZERO }, { easing: 'backIn' // 使用回弹缓动效果 }) .call(() => { this.node.active = false; resolve(); }) .start(); }); } /** * 立即隐藏面板(无动画) */ public hidePanelImmediate(): void { this.node.setScale(Vec3.ZERO); this.node.active = false; } /** * 立即显示面板(无动画) */ public showPanelImmediate(): void { this.node.setScale(Vec3.ONE); this.node.setPosition(0, 0, 0); // 确保面板在屏幕正中间 this.node.active = true; } /** * 武器升级成功动画 * 播放武器图标的放大缩小动画 * @param weaponIconNode 武器图标节点 */ public playWeaponUpgradeAnimation(weaponIconNode: Node): Promise { return new Promise((resolve) => { // 保存原始缩放值 const originalScale = weaponIconNode.scale.clone(); // 创建缩放动画:放大到1.5倍再立即缩小回原始大小 const scaleAnimation = tween(weaponIconNode) .to(0.25, { scale: new Vec3(originalScale.x * 1.5, originalScale.y * 1.5, originalScale.z) }, { easing: 'sineOut' }) .to(0.25, { scale: originalScale }, { easing: 'sineIn' }); // 只播放缩放动画 scaleAnimation.call(() => resolve()).start(); }); } }