LayerManager增加前景层
增加组件单例
This commit is contained in:
21
assets/core/base/SingletonComp.ts
Normal file
21
assets/core/base/SingletonComp.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
9
assets/core/base/SingletonComp.ts.meta
Normal file
9
assets/core/base/SingletonComp.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ed312310-5e95-44f4-923c-c1fd8b8db69b",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user