marineparkclient/assets/common/ui/UIMaskMgr.ts
2023-08-15 11:09:12 +08:00

51 lines
1.8 KiB
TypeScript

import { SysDefine } from "./config/SysDefine";
import UIBase from "./base/UIBase";
import UIManager from "./UIManager";
import { MaskOpacity } from "./config/SysDefine";
import uiHelper from "./base/UIHelper";
import { MaskType } from "./MaskType";
import { UIMaskScript } from "./UIMaskScript";
/**
* 遮罩管理
*/
const {ccclass, property} = cc._decorator;
@ccclass
export default class UIMaskMgr extends cc.Component {
public static popUpRoot: cc.Node = null;
public static _inst: UIMaskMgr = null;
public static get inst() {
if(this._inst == null) {
let tempObject = cc.find(SysDefine.SYS_UIMASK_NAME);
this._inst = cc.find(SysDefine.SYS_UIMASK_NAME).addComponent<UIMaskMgr>(this);
UIMaskMgr.inst.uiMask = new cc.Node("UIMaskNode").addComponent(UIMaskScript);
UIMaskMgr.inst.uiMask.init();
this.popUpRoot = cc.find(SysDefine.SYS_UIROOT_NAME + '/' + SysDefine.SYS_POPUP_NODE);
}
return this._inst;
}
private uiMask:UIMaskScript = null;
/** 为mask添加颜色 */
private async showMask(maskType: MaskType) {
await this.uiMask.showMask(maskType.opacity, maskType.easingTime, maskType.isEasing);
}
public checkMaskWindow(uiBases: UIBase[]) {
if(this.uiMask.node.parent) {
this.uiMask.node.removeFromParent();
}
for(let i=uiBases.length-1; i>=0; i--) {
if(uiBases[i].maskType.opacity > 0) {
UIMaskMgr.popUpRoot.addChild(this.uiMask.node, Math.max(uiBases[i].node.zIndex-1, 0));
this.uiMask.uid = uiBases[i].uid;
this.showMask(uiBases[i].maskType);
break;
}
}
if(!this.uiMask.node.parent) {
this.uiMask.node.opacity = 0;
}
}
}