717beff4-d69e-4a5f-b165-17e4f88a951e.js 4.58 KB
"use strict";
cc._RF.push(module, '717be/01p5KX7FlF+T4ipUe', 'AlterAnim');
// script/common/components/AlterAnim.ts

"use strict";
// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
const CCDummyObjects_1 = require("../CCDummyObjects");
const { ccclass, property, menu } = cc._decorator;
let AlterAnim = /** @class */ (() => {
    let AlterAnim = class AlterAnim extends cc.Component {
        constructor() {
            super(...arguments);
            this.animTime = 0.3;
            this.maskNode = CCDummyObjects_1.DummyNode;
            this.mainNode = CCDummyObjects_1.DummyNode;
        }
        onEnable() {
            this._showUIAnim(this.maskNode, this.mainNode);
        }
        /**
         *
         * @param maskNode 遮罩node
         * @param mainNode 所有内容node
         * @param params callback:执行完成后的回调,maskNodeOpacityValue遮罩node的opacity值
         */
        _showUIAnim(maskNode, mainNode, params = { callback: () => { }, maskNodeOpacityValue: 200 }) {
            maskNode.opacity = 0;
            maskNode.active = true;
            mainNode.scale = 0;
            mainNode.active = true;
            // 播放背景动画
            let opacityValue = params.maskNodeOpacityValue;
            cc.tween(maskNode)
                .to(this.animTime * 0.8, { opacity: opacityValue })
                .call(() => {
            })
                .start();
            // 播放主体动画
            cc.tween(mainNode)
                .to(this.animTime, { scale: 1 }, { easing: 'backOut' })
                .call(() => {
                // 弹窗已完全展示(动画完毕)
                if (params.callback)
                    params.callback();
            })
                .start();
        }
        hideUIAnim(params) {
            this._hideUIAnim(this.node, this.maskNode, this.mainNode, params);
        }
        /**
         *
         * @param parentNode 该组件挂载的node
         * @param maskNode 遮罩node
         * @param mainNode 所有内容node
         * @param params callback:执行完成后的回调,maskNodeOpacityValue遮罩node的opacity值
         */
        _hideUIAnim(parentNode, maskNode, mainNode, params = { callback: () => { } }) {
            // 拦截点击事件
            let blocker = parentNode.getChildByName("blocker");
            if (!blocker) {
                blocker = new cc.Node('blocker');
                blocker.addComponent(cc.BlockInputEvents);
                blocker.setParent(parentNode);
                blocker.setContentSize(parentNode.getContentSize());
            }
            blocker.active = true;
            // 播放背景动画
            cc.tween(maskNode)
                .delay(this.animTime * 0.2)
                .to(this.animTime * 0.8, { opacity: 0 })
                .call(() => {
            })
                .start();
            // 播放主体动画
            cc.tween(mainNode)
                .to(this.animTime, { scale: 0 }, { easing: 'backIn' })
                .call(() => {
                blocker.active = false;
                if (params.callback)
                    params.callback();
            })
                .start();
        }
    };
    __decorate([
        property({ type: Number, tooltip: "动画时长" })
    ], AlterAnim.prototype, "animTime", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "弹出框遮罩" })
    ], AlterAnim.prototype, "maskNode", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "内容node父节点" })
    ], AlterAnim.prototype, "mainNode", void 0);
    AlterAnim = __decorate([
        ccclass,
        menu("自定义UI组件/AlterAnim")
    ], AlterAnim);
    return AlterAnim;
})();
exports.default = AlterAnim;

cc._RF.pop();