diff --git a/assets/core/base/SingletonComp.ts b/assets/core/base/SingletonComp.ts new file mode 100644 index 0000000..888aa67 --- /dev/null +++ b/assets/core/base/SingletonComp.ts @@ -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; + } + } +} \ No newline at end of file diff --git a/assets/core/base/SingletonComp.ts.meta b/assets/core/base/SingletonComp.ts.meta new file mode 100644 index 0000000..9266881 --- /dev/null +++ b/assets/core/base/SingletonComp.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "ed312310-5e95-44f4-923c-c1fd8b8db69b", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/core/layer/LayerManager.ts b/assets/core/layer/LayerManager.ts index a2c20b0..9205388 100644 --- a/assets/core/layer/LayerManager.ts +++ b/assets/core/layer/LayerManager.ts @@ -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);