A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(editor): a UI prefab opens in a canvas, instead of collapsing onto itself
yhhbce42b060f91
diff --git a/desktop/src/commands/editorCommands.ts b/desktop/src/commands/editorCommands.tsindex 2a61effd0..629e0c3c5 100644--- a/desktop/src/commands/editorCommands.ts+++ b/desktop/src/commands/editorCommands.ts@@ -240,7 +240,8 @@ commands.register({keybinding: 'mod+a',isEnabled: () => SceneModel.entityOrder().length > 0,run: () => {- const ids = SceneModel.entityOrder();+ // Everything in the document — the editing environment isn't part of it.+ const ids = SceneModel.entityOrder().filter((id) => !SceneModel.isEnvironment(id));if (ids.length) sel().selectMany(ids, ids[ids.length - 1]);},});diff --git a/desktop/src/engine/SceneModel.ts b/desktop/src/engine/SceneModel.tsindex 50eca482d..a6e8e741c 100644--- a/desktop/src/engine/SceneModel.ts+++ b/desktop/src/engine/SceneModel.ts@@ -2,6 +2,7 @@// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Teamimport type { SceneData } from 'esengine';import type { EntityId } from '@/types';+import { isEnvironmentEntity } from './prefabEnvironment';type SceneEntity = SceneData['entities'][number];type SceneComponent = SceneEntity['components'][number];@@ -370,6 +371,23 @@ export class SceneModelImpl {this.emit({ kind: 'lockChanged', sourceId });}+ /** Whether an entity is part of the editing ENVIRONMENT — in the document so it can+ * host what's being edited, but not part of it (see engine/prefabEnvironment.ts).+ * Baked in when the document is adopted, so there is no setter. */+ isEnvironment(sourceId: number): boolean {+ const e = this.entityBySource(sourceId);+ return !!e && isEnvironmentEntity(e);+ }++ /** Whether the viewport may grab an entity: not locked, not editor-hidden, and not+ * environment. One predicate so click, marquee, and UI picking cannot drift apart.+ * An id the model doesn't know (an engine-owned helper entity) stays grabbable. */+ isPickable(sourceId: number): boolean {+ const e = this.entityBySource(sourceId) as (SceneEntity & { hidden?: boolean; locked?: boolean }) | undefined;+ if (!e) return true;+ return !e.locked && !e.hidden && !isEnvironmentEntity(e);+ }+// ── Sibling order (outliner drag-reorder; render order = `data.entities` order) ──// The outliner derives sibling order from each entity's position in// `data.entities` (buildSceneTree's parent index preserves it), so reordering isdiff --git a/desktop/src/engine/SceneQuery.ts b/desktop/src/engine/SceneQuery.tsindex 7e2953fd5..4a40968d3 100644--- a/desktop/src/engine/SceneQuery.ts+++ b/desktop/src/engine/SceneQuery.ts@@ -4,6 +4,7 @@ import type { SceneData } from 'esengine';import type { SceneNode, NodeKind, EntityId, InspectorComponent, InspectorFieldValue } from '@/types';import { SceneStore, SceneStoreImpl } from './SceneStore';import { SceneModel, SceneModelImpl } from './SceneModel';+import { isEnvironmentEntity } from './prefabEnvironment';import {inspectorFields,inferField,@@ -26,10 +27,14 @@ type SceneEntity = SceneData['entities'][number];/** Outliner tree from a SceneData; nesting derived from each entity's `parent`. */export function buildSceneTree(data: SceneData | null): SceneNode[] {if (!data) return [];- const ids = new Set(data.entities.map((e) => e.id));+ // The editing environment hosts the document without being part of it (Prefab Mode's+ // Canvas host), so it never gets a row and what it parents reads as a root — the tree+ // shows exactly what will be saved.+ const authored = data.entities.filter((e) => !isEnvironmentEntity(e));+ const ids = new Set(authored.map((e) => e.id));const childrenOf = new Map<number, SceneEntity[]>();const roots: SceneEntity[] = [];- for (const e of data.entities) {+ for (const e of authored) {if (e.parent != null && ids.has(e.parent)) {const arr = childrenOf.get(e.parent);if (arr) arr.push(e);diff --git a/desktop/src/engine/ViewportController.ts b/desktop/src/engine/ViewportController.tsindex 20542b5f4..3d9979ef1 100644--- a/desktop/src/engine/ViewportController.ts+++ b/desktop/src/engine/ViewportController.ts@@ -201,7 +201,7 @@ export const ViewportController = {};},- /** UI entities under the pointer, most specific first; locked/hidden dropped. */+ /** UI entities under the pointer, most specific first; unpickable ones dropped. */pickUIEntities(clientX: number, clientY: number): EntityId[] {const world = EngineHost.world;const module = EngineHost.module;@@ -214,7 +214,7 @@ export const ViewportController = {const wp = screenToUiWorld(cam, s.sx, s.sy);return uiPickAllWorld(module, reg, wp.x, wp.y).filter((hit) => {const src = SceneModel.sourceFor(hit);- return src == null || (!SceneModel.isLocked(src) && !SceneModel.isHidden(src));+ return src == null || SceneModel.isPickable(src);});},@@ -235,9 +235,9 @@ export const ViewportController = {const hits: { e: EntityId; layer: number; i: number }[] = [];for (const e of world.getAllEntities()) {if (!world.has(e, Transform)) continue;- // Locked / editor-hidden entities aren't click-selectable in the viewport.+ // Locked / editor-hidden / environment entities aren't click-selectable.const src = SceneModel.sourceFor(e);- if (src != null && (SceneModel.isLocked(src) || SceneModel.isHidden(src))) continue;+ if (src != null && !SceneModel.isPickable(src)) continue;const b = this.entityBounds(e);if (!b || !pointInOBB(wp.x, wp.y, b)) continue;const layer = world.has(e, Sprite) ? world.get(e, Sprite).layer : ICON_PICK_LAYER;@@ -262,7 +262,7 @@ export const ViewportController = {for (const e of world.getAllEntities()) {if (!world.has(e, Transform)) continue;const src = SceneModel.sourceFor(e);- if (src != null && (SceneModel.isLocked(src) || SceneModel.isHidden(src))) continue;+ if (src != null && !SceneModel.isPickable(src)) continue;const r = this.getEntityScreenRect(e);if (r && rectsIntersect(rect, r)) out.push(e);}diff --git a/desktop/src/engine/prefabEnvironment.ts b/desktop/src/engine/prefabEnvironment.tsnew file mode 100644index 000000000..32f4dfd7e--- /dev/null+++ b/desktop/src/engine/prefabEnvironment.ts@@ -0,0 +1,95 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file prefabEnvironment.ts+ * @brief The editing ENVIRONMENT: entities the editor puts around the thing being+ * edited so it reads the way it will in a scene, without ever becoming part+ * of it.+ *+ * Prefab Mode is the case that needs one. A UI node's box is authored RELATIVE to+ * its parent — fractional insets plus pixel margins — so a UI prefab opened on its+ * own has nothing above it for those fractions to resolve against: the tree+ * collapses into near-zero boxes at the origin, and the selection outlines and gizmo+ * pivots that read those boxes collapse with it. A scene hosts UI under a Canvas;+ * Prefab Mode has no scene, so it supplies the same Canvas as an environment.+ *+ * The environment lives in the DOCUMENT, so the one model→World projection builds it+ * like any other entity, and carries an editor-only `env` flag — the single mark+ * that keeps it out of the saved asset, the Outliner, and viewport picking.+ *+ * Pure data (no World, no store, no project), so the splicing rules are unit-tested+ * on their own.+ */++/**+ * The document-entity shape the environment reads and rewrites: structurally the+ * scene document's entity, plus the `env` flag. Loose on `components` so both a+ * flattened prefab's entities and a serialized model's satisfy it.+ */+export interface DocumentEntity {+ id: number;+ name: string;+ parent: number | null;+ children: number[];+ components: readonly { type: string }[];+ visible?: boolean;+ /** Marks an environment entity. Set by {@link hostPrefab}; never on authored data. */+ env?: boolean;+}++/** The component that gives UI nodes a box to resolve against. */+const UI_HOST = 'Canvas';+/** The component that needs one. */+const UI_NODE = 'UINode';++/** Whether an entity belongs to the editing environment rather than to the document+ * being authored. Reads the flag off any entity shape — a scene document's entity type+ * doesn't declare it, the same way it doesn't declare `hidden` / `locked` / `folder`. */+export function isEnvironmentEntity(e: object): boolean {+ return (e as { env?: boolean }).env === true;+}++/**+ * Whether a prefab needs the Canvas host: it carries UI boxes and brings no Canvas+ * of its own (a prefab that ships one already hosts itself, as a full-screen HUD+ * prefab does).+ */+export function needsUIHost(entities: readonly DocumentEntity[]): boolean {+ const carries = (type: string): boolean => entities.some((e) => e.components.some((c) => c.type === type));+ return carries(UI_NODE) && !carries(UI_HOST);+}++/**+ * Splice a host subtree in above a prefab: the host's root adopts the prefab's root+ * and every host entity is flagged `env`. The host leads the returned list because+ * document order is spawn order — a parent has to precede its children.+ */+export function hostPrefab<T extends DocumentEntity>(+ prefab: { entities: readonly T[]; rootId: number },+ host: { entities: readonly T[]; rootId: number },+): T[] {+ const environment = host.entities.map((e) =>+ e.id === host.rootId+ ? ({ ...e, env: true, children: [...e.children, prefab.rootId] } as T)+ : ({ ...e, env: true } as T),+ );+ const hosted = prefab.entities.map((e) => (e.id === prefab.rootId ? ({ ...e, parent: host.rootId } as T) : e));+ return [...environment, ...hosted];+}++/**+ * The authored half of a document: environment entities dropped, and whatever they+ * parented re-rooted. Extraction therefore sees exactly the prefab the user opened,+ * so the environment cannot reach the `.esprefab` — nor be minted an identity in it.+ */+export function authoredEntities<T extends DocumentEntity>(entities: readonly T[]): T[] {+ const environment = new Set(entities.filter(isEnvironmentEntity).map((e) => e.id));+ if (environment.size === 0) return [...entities];+ return entities+ .filter((e) => !environment.has(e.id))+ .map((e) => ({+ ...e,+ parent: e.parent != null && environment.has(e.parent) ? null : e.parent,+ children: e.children.filter((c) => !environment.has(c)),+ }) as T);+}diff --git a/desktop/src/project/ProjectStore.ts b/desktop/src/project/ProjectStore.tsindex 362f5412d..6e5932cd7 100644--- a/desktop/src/project/ProjectStore.ts+++ b/desktop/src/project/ProjectStore.ts@@ -16,7 +16,8 @@ import { EditorHistory } from '@/engine/EditorHistory';import { expandScenePrefabs, collapseScenePrefabs } from '@/engine/PrefabInstance';import { SceneCommands } from '@/engine/SceneCommands';import { Boxes } from 'lucide-react';-import { spritePrefab, setCanvasDesignSeed, setProjectCameraFit, setProjectPrefabSources, type EntitySource } from '@/engine/entitySources';+import { spritePrefab, setCanvasDesignSeed, setProjectCameraFit, setProjectPrefabSources, sourceById, type EntitySource } from '@/engine/entitySources';+import { needsUIHost, hostPrefab, authoredEntities, type DocumentEntity } from '@/engine/prefabEnvironment';import { setPrefabBaseResolver } from '@/engine/SceneQuery';import { setUserSchemas, userSchema, setBitmaskSource, setEnumSource, type UserComponentSchema } from '@/engine/schema';import { installDragonBonesEnumSources, clearDragonBonesNameCache } from '@/engine/dragonBonesNames';@@ -78,6 +79,11 @@ function assetMatchesSlot(type: AssetType, path: string, fieldType?: string): boreturn getEditorType(path) === fieldType;}+/** A flattened prefab entity as a document entity (the fields a scene document keeps). */+function toDocumentEntity(e: ProcessedEntity): DocumentEntity {+ return { id: e.id, name: e.name, parent: e.parent, children: e.children, components: e.components, visible: e.visible };+}+/** A pickable asset for the inspector's asset picker. */export interface AssetEntry {ref: string;@@ -2244,7 +2250,9 @@ class ProjectStoreImpl {* same outliner / inspector / viewport used for scenes. The asset is flattened* into ordinary entities (each remembered by its prefabEntityId so save-back* preserves identity), the current scene is swapped out, and a banner offers- * "Back to Scene". A FLAT prefab extracts back to a flat asset on save; a+ * "Back to Scene". A UI prefab additionally gets an editing environment — a Canvas+ * to lay out in, which save strips back out (see engine/prefabEnvironment.ts).+ * A FLAT prefab extracts back to a flat asset on save; a* VARIANT of a flat base is editable too (save collapses the edits against the* base into a variant delta, preserving basePrefab). Nested prefabs — and* variants of a nested / variant base — are still refused (re-nesting on save@@ -2291,16 +2299,17 @@ class ProjectStoreImpl {// A variant resolves its base through the warm-cache resolver (loadPrefabAsset// above warmed it), yielding base entities + the variant's own overrides/adds.let nid = 0;- const { entities, rootId } = flattenPrefab(prefab, [], { allocateId: () => nid++, loadPrefab: this.prefabResolverSync });+ const allocateId = (): number => nid++;+ const { entities, rootId } = flattenPrefab(prefab, [], { allocateId, loadPrefab: this.prefabResolverSync });const idBySource = new Map(entities.map((e) => [e.id, e.prefabEntityId]));- const sceneData = {- version: '1.0',- name: prefab.name,- entities: entities.map((e) => ({- id: e.id, name: e.name, parent: e.parent, children: e.children,- components: e.components, visible: e.visible,- })),- } as unknown as SceneData;+ let docEntities = entities.map(toDocumentEntity);+ // A UI prefab's boxes are fractions of a parent it no longer has, so open it inside+ // the editing environment's Canvas or the whole tree collapses (prefabEnvironment.ts).+ if (needsUIHost(docEntities)) {+ const host = await this.buildUIHost(allocateId);+ if (host) docEntities = hostPrefab({ entities: docEntities, rootId }, host);+ }+ const sceneData = { version: '1.0', name: prefab.name, entities: docEntities } as unknown as SceneData;await this.adoptDocument(sceneData);// A prefab carries no camera, so syncEditorViewToScene left the scene's view —@@ -2311,7 +2320,14 @@ class ProjectStoreImpl {// position override would otherwise frame at the origin and sit off-screen.const frameContent = (): void => {const world = EngineHost.world;- if (world) ViewportController.frameSelection([...world.getAllEntities()]);+ if (!world) return;+ // Frame the prefab, not the environment hosting it: a Canvas host spans the whole+ // design resolution, which would zoom a button-sized prefab down to a speck.+ const content = [...world.getAllEntities()].filter((e) => {+ const src = SceneModel.sourceFor(e);+ return src == null || !SceneModel.isEnvironment(src);+ });+ ViewportController.frameSelection(content);};requestAnimationFrame(() => requestAnimationFrame(frameContent));const returnLeaf = returnScene ? (returnScene.split('/').pop() ?? returnScene) : null;@@ -2321,6 +2337,25 @@ class ProjectStoreImpl {Toasts.push(t('proj.openedPrefab', { name: prefab.name }), 'info', 1600);}+ /**+ * The Canvas that hosts a UI prefab in Prefab Mode, as document entities. Built+ * through the Create-entity source, so the host IS the Canvas the user would get in+ * a scene — the project's design resolution and scale mode included — rather than a+ * second definition of "a Canvas" that can drift from it. Null if it can't be built+ * (then the prefab opens unhosted, as before).+ */+ private async buildUIHost(allocateId: () => number): Promise<{ entities: DocumentEntity[]; rootId: number } | null> {+ const source = sourceById('canvas');+ if (!source?.build) return null;+ try {+ const canvas = await source.build({ parent: null });+ const flat = flattenPrefab(canvas, [], { allocateId, loadPrefab: this.prefabResolverSync });+ return { entities: flat.entities.map(toDocumentEntity), rootId: flat.rootId };+ } catch {+ return null;+ }+ }+/*** Adopt an in-memory SceneData into the editor (preload assets → build the World* → adopt as the model), mirroring {@link loadCurrentScene}'s tail. No file read@@ -2363,13 +2398,16 @@ class ProjectStoreImpl {): { prefab: PrefabData; idBySource: Map<number, string>; removedCount: number } | null {const model = SceneModel.serialize();if (!model) return null;+ // The environment hosting the edit is not part of the asset: drop it (and re-root+ // what it parented) before anything mints identities or diffs against the base.+ const entities = authoredEntities(model.entities);const idBySource = new Map(pe.idBySource);- for (const e of model.entities) if (!idBySource.has(e.id)) idBySource.set(e.id, crypto.randomUUID());+ for (const e of entities) if (!idBySource.has(e.id)) idBySource.set(e.id, crypto.randomUUID());if (pe.base && pe.baseRef) {// VARIANT: diff the edited tree against the flat base → the variant's own// overrides + additions, then rebuild the variant (basePrefab preserved).- const processed: ProcessedEntity[] = model.entities.map((e) => ({+ const processed: ProcessedEntity[] = entities.map((e) => ({id: e.id,prefabEntityId: idBySource.get(e.id) ?? crypto.randomUUID(),name: e.name,@@ -2384,7 +2422,7 @@ class ProjectStoreImpl {return { prefab, idBySource, removedCount: delta.removed.length };}const prefab = extractPrefab(- model.entities as unknown as ExtractEntity[],+ entities as unknown as ExtractEntity[],pe.rootSource,pe.name,(srcId) => idBySource.get(srcId) ?? crypto.randomUUID(),diff --git a/desktop/tests/prefab-environment.test.ts b/desktop/tests/prefab-environment.test.tsnew file mode 100644index 000000000..8c84254f8--- /dev/null+++ b/desktop/tests/prefab-environment.test.ts@@ -0,0 +1,127 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file Prefab Mode's editing environment (engine/prefabEnvironment.ts).+ * A UI prefab is opened inside a Canvas host so its fractional boxes have+ * something to resolve against; these pin the two halves of that deal — the+ * host goes in above the prefab, and it is gone again by the time the asset is+ * extracted. The round-trip case is the one that matters: hosting must not+ * change a single byte of the saved `.esprefab`. Pure data (no World).+ */+import { describe, it, expect } from 'vitest';+import { extractPrefab } from 'esengine';+import type { ExtractEntity } from 'esengine';+import {+ needsUIHost,+ hostPrefab,+ authoredEntities,+ isEnvironmentEntity,+ type DocumentEntity,+} from '@/engine/prefabEnvironment';++/** A two-entity UI prefab: a panel with one label. */+function uiPrefab(): { entities: DocumentEntity[]; rootId: number } {+ return {+ rootId: 0,+ entities: [+ { id: 0, name: 'Panel', parent: null, children: [1], components: [{ type: 'Transform', data: {} }, { type: 'UINode', data: {} }] },+ { id: 1, name: 'Label', parent: 0, children: [], components: [{ type: 'Transform', data: {} }, { type: 'UINode', data: {} }, { type: 'Text', data: {} }] },+ ],+ };+}++/** The Canvas host the editor builds from the Create-entity source. */+function canvasHost(firstId = 10): { entities: DocumentEntity[]; rootId: number } {+ return {+ rootId: firstId,+ entities: [+ { id: firstId, name: 'Canvas', parent: null, children: [], components: [{ type: 'Transform', data: {} }, { type: 'Canvas', data: {} }, { type: 'UINode', data: {} }] },+ ],+ };+}++describe('needsUIHost', () => {+ it('hosts a UI prefab that brings no Canvas of its own', () => {+ expect(needsUIHost(uiPrefab().entities)).toBe(true);+ });++ it('leaves a prefab that ships its own Canvas alone', () => {+ const hud = uiPrefab();+ hud.entities[0].components = [{ type: 'Transform', data: {} }, { type: 'Canvas', data: {} }, { type: 'UINode', data: {} }];+ expect(needsUIHost(hud.entities)).toBe(false);+ });++ it('leaves a gameplay prefab alone', () => {+ const coin: DocumentEntity[] = [+ { id: 0, name: 'Coin', parent: null, children: [], components: [{ type: 'Transform', data: {} }, { type: 'Sprite', data: {} }] },+ ];+ expect(needsUIHost(coin)).toBe(false);+ });+});++describe('hostPrefab', () => {+ it('puts the host above the prefab root and flags only the host', () => {+ const doc = hostPrefab(uiPrefab(), canvasHost());++ // Document order is spawn order: the host has to precede what it parents.+ expect(doc.map((e) => e.id)).toEqual([10, 0, 1]);+ expect(doc.filter(isEnvironmentEntity).map((e) => e.id)).toEqual([10]);++ const host = doc.find((e) => e.id === 10)!;+ const root = doc.find((e) => e.id === 0)!;+ expect(host.children).toEqual([0]);+ expect(root.parent).toBe(10);+ // The prefab's own hierarchy is untouched.+ expect(doc.find((e) => e.id === 1)!.parent).toBe(0);+ });++ it('does not mutate the entities it was given', () => {+ const prefab = uiPrefab();+ hostPrefab(prefab, canvasHost());+ expect(prefab.entities[0].parent).toBeNull();+ });+});++describe('authoredEntities', () => {+ it('drops the environment and re-roots what it parented', () => {+ const authored = authoredEntities(hostPrefab(uiPrefab(), canvasHost()));++ expect(authored.map((e) => e.id)).toEqual([0, 1]);+ expect(authored[0].parent).toBeNull();+ expect(authored[1].parent).toBe(0);+ });++ it('strips the environment out of an authored entity’s children', () => {+ // A widget created with nothing selected lands under the Canvas host, so the+ // prefab root can end up listing it — the environment must not survive as a child.+ const doc = hostPrefab(uiPrefab(), canvasHost());+ doc.find((e) => e.id === 0)!.children = [1, 10];++ expect(authoredEntities(doc).find((e) => e.id === 0)!.children).toEqual([1]);+ });++ it('passes an unhosted document through unchanged', () => {+ const doc = uiPrefab().entities;+ expect(authoredEntities(doc)).toEqual(doc);+ });+});++describe('save-back round trip', () => {+ it('extracts the same asset whether or not the prefab was hosted', () => {+ const bare = uiPrefab();+ const hosted = hostPrefab(uiPrefab(), canvasHost());+ const stableId = (id: number): string => `id-${id}`;++ const fromBare = extractPrefab(bare.entities as unknown as ExtractEntity[], bare.rootId, 'Panel', stableId);+ const fromHosted = extractPrefab(authoredEntities(hosted) as unknown as ExtractEntity[], bare.rootId, 'Panel', stableId);++ expect(fromHosted).toEqual(fromBare);+ });++ it('never mints an identity for an environment entity', () => {+ const hosted = hostPrefab(uiPrefab(), canvasHost());+ const minted = authoredEntities(hosted).map((e) => e.id);++ expect(minted).not.toContain(10);+ });+});diff --git a/docs/astro/src/content/docs/guides/prefab.mdx b/docs/astro/src/content/docs/guides/prefab.mdxindex 1fa51e710..9d236d334 100644--- a/docs/astro/src/content/docs/guides/prefab.mdx+++ b/docs/astro/src/content/docs/guides/prefab.mdx@@ -37,6 +37,13 @@ framed in a warm accent under an **Editing Prefab** banner. Add, remove, rename,and tune components exactly as in a scene, then **Save Prefab** — every instance in everyscene picks up the change. **Back to Scene** returns you where you were.+A **UI prefab** opens inside a canvas. UI boxes are authored relative to their parent, so on+its own a UI prefab would have nothing for its percentages to resolve against and the whole+tree would collapse onto the origin. Prefab Mode therefore hosts it in a canvas at the+project's reference resolution — the layout, selection outlines, and gizmos read exactly as+they do in a scene. The host isn't part of the prefab: it never appears in the Outliner and+never reaches the saved asset.+Not yet supported in Prefab Mode: editing a **nested** prefab in place, or a variant whosebase isn't flat. Play and *Save As* are disabled while you're editing a prefab.diff --git a/docs/astro/src/content/docs/zh-cn/guides/prefab.mdx b/docs/astro/src/content/docs/zh-cn/guides/prefab.mdxindex 8717e1bd1..f58954a36 100644--- a/docs/astro/src/content/docs/zh-cn/guides/prefab.mdx+++ b/docs/astro/src/content/docs/zh-cn/guides/prefab.mdx@@ -31,6 +31,10 @@ import { Aside } from '@astrojs/starlight/components';像编辑场景一样增删、改名、重设父级、调组件,然后 **Save Prefab**——每个场景里的每个实例都会拿到这次改动。**Back to Scene** 把你带回原处。+**UI 预制体**会在一张画布里打开。UI 的盒子是相对父级书写的,单独打开时那些百分比没有东西可解析,+整棵树会塌到原点上。所以 Prefab Mode 会用项目参考分辨率的画布把它托住——布局、选择框、gizmo 都和在+场景里读起来完全一致。这个宿主不属于预制体:它不出现在 Outliner 里,也永远不会进到存下来的资产。+Prefab Mode 暂不支持:就地编辑**嵌套**预制体,或基不是扁平的变体。编辑预制体时 Play 与 *Save As* 被禁用。