LayerManager增加前景层

增加组件单例
This commit is contained in:
李砚
2024-10-12 10:10:12 +08:00
parent 07bd34dad8
commit 29eb6c3b64
3 changed files with 39 additions and 2 deletions

View File

@@ -0,0 +1,21 @@
/*
* @Description: 单例组件基类
* @Author: ly
* @Date: 2024-10-12 09:22:51
* @LastEditors: ly
* @LastEditTime: 2024-10-12 09:42:33
*/
import { Component } from "cc";
export class SingletonComp extends Component {
private static _instance: SingletonComp = null!;
protected onLoad(): void {
if (SingletonComp._instance === null) {
SingletonComp._instance = this;
} else {
this.destroy();
return;
}
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "ed312310-5e95-44f4-923c-c1fd8b8db69b",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -3,7 +3,7 @@
* @Author: ly
* @Date: 2024-06-28 12:29:23
* @LastEditors: ly
* @LastEditTime: 2024-10-10 11:43:31
* @LastEditTime: 2024-10-12 09:50:59
*/
import { Layers, Node, Widget } from "cc";
@@ -12,9 +12,11 @@ import { Singleton } from "../base/Singleton";
/** 界面层类型 */
export enum LayerType {
/** 游戏背景层 */
GameBg = "LayerGameBg",
GameBg = "LayerBg",
/** 主游戏层 */
Game = "LayerGame",
/** 游戏前景层 */
GameFg = "LayerFg",
/** UI主界面 */
UIMain = "LayerUIMain",
/** 弹出层 */
@@ -38,6 +40,9 @@ export class LayerManager extends Singleton {
/** 主游戏层 */
public game: Node;
/** 游戏前景层 */
public gameFg: Node;
/** 主UI层 */
public uiMain: Node;
@@ -73,6 +78,7 @@ export class LayerManager extends Singleton {
this.world = gameRoot;
this.gameBg = this._createLayer(LayerType.GameBg);
this.game = this._createLayer(LayerType.Game);
this.gameFg = this._createLayer(LayerType.GameFg);
this.uiMain = this._createLayer(LayerType.UIMain);
this.popup = this._createLayer(LayerType.PopUp);
this.dialog = this._createLayer(LayerType.Dialog);
@@ -82,6 +88,7 @@ export class LayerManager extends Singleton {
this.uiRoot.addChild(this.gameBg);
this.uiRoot.addChild(this.game);
this.uiRoot.addChild(this.gameFg);
this.uiRoot.addChild(this.uiMain);
this.uiRoot.addChild(this.popup);
this.uiRoot.addChild(this.dialog);