UIBase.ts
1.71 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
export class UIBase extends cc.Component {
enableParam: any = null;
private _tweenobj = { progress: 0 };
protected _usePopUpEffect: boolean = true;
protected _useCloseEffect: boolean = true;
protected _closing: boolean = false;
/**正在关闭特效中 */
get closing(): boolean { return this._closing; }
/**弹出特效,子类可复写 */
onPopUpEffect() {
if (this._usePopUpEffect) {
this.node.setScale(0.1, 0.1, 1);
this._tweenobj.progress = 0;
cc.tween(this._tweenobj).to(0.2, { progress: 1 }, { onUpdate: this.onEffectUpdate.bind(this), easing: 'backOut' }).call(this.onPopUpEffectFinish.bind(this)).start();
}
}
private onEffectUpdate(target: { progress: number }, ratio: number) {
this.node.setScale(target.progress, target.progress);
}
protected onPopUpEffectFinish() {
}
onBeforeClose() {
cc.Tween.stopAllByTarget(this._tweenobj);
}
onCloseEffect(callBack: Function, callBackThisObj: any) {
if (this._useCloseEffect) {
this._closing = true;
this._tweenobj.progress = 1;
cc.tween(this._tweenobj).to(0.2, { progress: 0 }, { onUpdate: this.onEffectUpdate.bind(this), easing: 'backIn' }).call(() => {
this._closing = false;
callBack.call(callBackThisObj);
}).start();
}
else {
callBack.call(callBackThisObj)
}
}
// private onCloseEffectUpdate(target: { progress: number }, ratio: number) {
// // target.setScale(ratio, ratio, 1);
// this.node.setScale(target.progress, target.progress);
// // log(target.progress, ratio);
// }
}