From ab6bc88fa1041fe74885c9e25200bf0fce7a4885 Mon Sep 17 00:00:00 2001 From: dgflash Date: Sat, 10 May 2025 20:32:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/core/gui/layer/LayerNotify.ts | 13 ++++++++----- assets/core/gui/layer/LayerPopup.ts | 5 +---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/assets/core/gui/layer/LayerNotify.ts b/assets/core/gui/layer/LayerNotify.ts index b5aa1d7..6794aa4 100644 --- a/assets/core/gui/layer/LayerNotify.ts +++ b/assets/core/gui/layer/LayerNotify.ts @@ -8,6 +8,8 @@ import { BlockInputEvents, Layers, Node, Widget, instantiate } from "cc"; import { ViewUtil } from "../../utils/ViewUtil"; import { PromptResType } from "../GuiEnum"; import { Notify } from "../prompt/Notify"; +import { sys } from "cc"; +import { EDITOR, EDITOR_NOT_IN_PREVIEW } from "cc/env"; /* * 滚动消息提示层 @@ -29,10 +31,7 @@ export class LayerNotify extends Node { widget.left = widget.right = widget.top = widget.bottom = 0; widget.alignMode = 2; widget.enabled = true; - this.init(); - } - private init() { this.layer = Layers.Enum.UI_2D; this.black = this.addComponent(BlockInputEvents); this.black.enabled = false; @@ -67,9 +66,13 @@ export class LayerNotify extends Node { */ async toast(content: string, useI18n: boolean) { if (this.notify == null) { - this.notify = ViewUtil.createPrefabNode(PromptResType.Toast); // 兼容编辑器预览模式 - if (this.notify == null) this.notify = await ViewUtil.createPrefabNodeAsync(PromptResType.Toast); + if (EDITOR) { + this.notify = await ViewUtil.createPrefabNodeAsync(PromptResType.Toast); + } + else { + this.notify = ViewUtil.createPrefabNode(PromptResType.Toast); + } this.notifyItem = this.notify.children[0]; this.notifyItem.parent = null; } diff --git a/assets/core/gui/layer/LayerPopup.ts b/assets/core/gui/layer/LayerPopup.ts index b12888d..c3a397b 100644 --- a/assets/core/gui/layer/LayerPopup.ts +++ b/assets/core/gui/layer/LayerPopup.ts @@ -20,10 +20,7 @@ export class LayerPopUp extends LayerUI { constructor(name: string) { super(name); - this.init(); - } - - private init() { + this.layer = Layers.Enum.UI_2D; this.on(Node.EventType.CHILD_ADDED, this.onChildAdded, this); this.on(Node.EventType.CHILD_REMOVED, this.onChildRemoved, this);