AlertManager.ts 678 Bytes
import { ResUtils } from "../../utils/ResUtils";

class AlertComponent extends cc.Component {
    animate = true;
    start() {
        if (this.animate) {
            this.node.scale = 0.1;
            this.node.runAction(cc.sequence(cc.scaleTo(0.3, 1.1), cc.scaleTo(0.2, 0.9), cc.scaleTo(0.2, 1)));
        }
    }
}

export namespace AlertManager {
    export async function showAlert(parent: cc.Node, node: cc.Node | string, animate = true) {
        if (typeof node === "string") {
            node = await ResUtils.createWithPrefab(node);
        }
        let comp = node.addComponent(AlertComponent);
        comp.animate = animate;
        node.parent = parent;
    }
}