import BaseToast from "@max-studio/core/ui/BaseToast"; import { uiConfig, UIType } from "@max-studio/core/ui/UIDecorator"; import UIManager from "@max-studio/core/ui/UIManager"; import { SpriteAtlas, tween, Vec3, UITransform } from "cc"; import { RichText } from "cc"; import { _decorator, Component, Node } from "cc"; const { ccclass, property } = _decorator; @uiConfig({ prefab: "prefabs/uis/CommonToast", bundle: "games", type: UIType.TOAST, isMulti: true, isCache: true, }) @ccclass("CommonToast") export class CommonToast extends BaseToast { @property(RichText) private contentLabel: RichText; @property(Node) private containerNode: Node; async onShow(tip: string, atlas: SpriteAtlas): Promise { if (atlas) { this.contentLabel.imageAtlas = atlas; } this.contentLabel.string = tip; // 播放滑入动画 this.playSlideInAnimation(); // 显示3秒后自动滑出 this.scheduleOnce(() => { this.playSlideOutAnimation(); }, 2); } /** * 播放滑入动画 */ private playSlideInAnimation() { this.containerNode.setPosition(0, 930, 0); // 播放滑入动画 tween(this.containerNode) .to( 0.5, { position: new Vec3(0, 720, 0) }, { easing: "backOut", }, ) .start(); } /** * 播放滑出动画 */ private playSlideOutAnimation() { // 滑出到屏幕顶部外面 const endY = 930; tween(this.containerNode) .to( 0.3, { position: new Vec3(0, endY, 0) }, { easing: "backIn", }, ) .call(() => { UIManager.getInstance().closeUI(this); }) .start(); } }