feat: 提交资源
This commit is contained in:
77
assets/games/scripts/uis/CommonToast.ts
Normal file
77
assets/games/scripts/uis/CommonToast.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
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<void> {
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user