Skip to content

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.

feat(editor): Edit Prefab from an instance — enter Prefab Mode from the scene (P2 UX)

yhh574f6a66c4c4
diff --git a/desktop/src/i18n/messages/details.ts b/desktop/src/i18n/messages/details.ts
index ac282a4dc..5dce02563 100644
--- a/desktop/src/i18n/messages/details.ts
+++ b/desktop/src/i18n/messages/details.ts
@@ -200,6 +200,8 @@ export const detailsMessages = defineMessages({
'det.editing': { en: 'Editing', zh: '编辑中' },
'det.editingShared': { en: '{count} entities · shared components', zh: '{count} 个实体 · 共同组件' },
'det.id': { en: 'ID', zh: 'ID' },
+ 'det.prefabEdit': { en: 'Edit', zh: '编辑' },
+ 'det.prefabEditTip': { en: 'Open this prefab in Prefab Mode', zh: '在预制体模式中打开此预制体' },
'det.prefabSelect': { en: 'Select', zh: '选择' },
'det.prefabSelectTip': { en: 'Select the prefab asset in the Content Browser', zh: '在内容浏览器中选中该预制体资产' },
'det.prefabApply': { en: 'Apply', zh: '应用' },
diff --git a/desktop/src/i18n/messages/outliner.ts b/desktop/src/i18n/messages/outliner.ts
index 27a50645b..786816003 100644
--- a/desktop/src/i18n/messages/outliner.ts
+++ b/desktop/src/i18n/messages/outliner.ts
@@ -47,6 +47,7 @@ export const outlinerMessages = defineMessages({
'out.deleteFolder': { en: 'Delete Folder', zh: '删除文件夹' },
'out.duplicate': { en: 'Duplicate', zh: '创建副本' },
'out.createPrefab': { en: 'Create Prefab', zh: '创建预制体' },
+ 'out.prefabEdit': { en: 'Edit Prefab', zh: '编辑预制体' },
'out.prefabSelectSource': { en: 'Select Prefab Source', zh: '选中预制体源' },
'out.prefabApply': { en: 'Apply to Prefab', zh: '应用到预制体' },
'out.prefabRevert': { en: 'Revert to Prefab', zh: '还原为预制体' },
diff --git a/desktop/src/panels/Details.tsx b/desktop/src/panels/Details.tsx
index 0ba73c555..56362c143 100644
--- a/desktop/src/panels/Details.tsx
+++ b/desktop/src/panels/Details.tsx
@@ -26,6 +26,7 @@ import {
Save,
Search,
Square,
+ SquarePen,
Trash2,
Upload,
Volume2,
@@ -2933,6 +2934,13 @@ function EditorDetails() {
</span>
<span className="pn">{prefabName}</span>
<span className="pacts">
+ <button
+ type="button"
+ title={t('det.prefabEditTip')}
+ onClick={() => void ProjectStore.editPrefabOfInstance(selectedId)}
+ >
+ <SquarePen size={12} strokeWidth={1.9} /> {t('det.prefabEdit')}
+ </button>
<button
type="button"
title={t('det.prefabSelectTip')}
diff --git a/desktop/src/panels/Outliner.tsx b/desktop/src/panels/Outliner.tsx
index f1d137a6c..8b8abcfc8 100644
--- a/desktop/src/panels/Outliner.tsx
+++ b/desktop/src/panels/Outliner.tsx
@@ -94,6 +94,7 @@ function prefabInstanceItems(id: number): MenuItem[] {
if (!ref) return [];
return [
{ sep: true },
+ { label: t('out.prefabEdit'), onClick: () => void ProjectStore.editPrefabOfInstance(id) },
{
label: t('out.prefabSelectSource'),
onClick: () => {
diff --git a/desktop/src/project/ProjectStore.ts b/desktop/src/project/ProjectStore.ts
index 648c8a5d3..b7200b2ba 100644
--- a/desktop/src/project/ProjectStore.ts
+++ b/desktop/src/project/ProjectStore.ts
@@ -980,6 +980,23 @@ class ProjectStoreImpl {
return out;
}
+ /**
+ * Enter Prefab Mode on the SOURCE of a prefab instance (Outliner / Inspector
+ * "Edit Prefab" — Unity's open-from-instance, the common workflow of editing a
+ * prefab you spotted in the scene). Resolves any entity of the instance to its
+ * prefab asset and routes to {@link openPrefab}, which owns the unsaved-changes
+ * guard + flat-only refusal. No-op if the entity isn't a prefab instance or its
+ * asset can't be resolved.
+ */
+ async editPrefabOfInstance(id: number): Promise<void> {
+ const tag = SceneModel.prefabTag(id);
+ const ref = tag?.prefab ?? (tag ? SceneModel.prefabTag(tag.instanceRoot)?.prefab : undefined);
+ if (!ref) return;
+ const info = this.assetInfo(ref);
+ if (!info) return;
+ await this.openPrefab(info.path);
+ }
+
/**
* Revert a prefab instance to the prefab (Details "Revert"): re-sync the whole
* instance to the asset, discarding all overrides, keeping its placement. Works on