717beff4-d69e-4a5f-b165-17e4f88a951e.js
4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
"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();