Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.8.0-4 round: fix unlink prefab bug in inspector #15518

Merged
merged 4 commits into from
Jun 29, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions editor/inspector/contributions/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ exports.listeners = {
const undoID = await beginRecording(panel.uuidList);
const dump = event.target.dump;
try {
// Editor.Message.send('scene', 'snapshot');
for (let i = 0; i < panel.uuidList.length; i++) {
const uuid = panel.uuidList[i];
if (i > 0) {
Expand Down Expand Up @@ -637,10 +636,19 @@ const Elements = {
return;
}

// Editor.Message.send('scene', 'snapshot');

const role = button.getAttribute('role');

const recordings = [];
for (const dump of panel.dumps) {
const prefab = dump.__prefab__;
switch (role) {
case 'reset': {
recordings.push(prefab.rootUuid);
}
}
}
const undoID = await beginRecording(recordings);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unlink-prefab不需要在业务层记录undo,场景中unlink时已经记录好了https://github.com/cocos/editor-extensions/pull/595

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里如果recordings没有uuid最好不要beginRecording

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done modified


for (const dump of panel.dumps) {
const prefab = dump.__prefab__;

Expand All @@ -654,19 +662,15 @@ const Elements = {
break;
}
case 'unlink': {
const undoID = await beginRecording(prefab.rootUuid);
await Editor.Message.request('scene', 'unlink-prefab', prefab.rootUuid, false);
await endRecording(undoID);
break;
}
case 'local': {
Editor.Message.send('assets', 'twinkle', prefab.uuid);
break;
}
case 'reset': {
const undoID = await beginRecording(prefab.rootUuid);
await Editor.Message.request('scene', 'restore-prefab', prefab.rootUuid, prefab.uuid);
await endRecording(undoID);
break;
}
case 'save': {
Expand All @@ -676,6 +680,10 @@ const Elements = {
}
}
}

if (recordings.length && undoID) {
await endRecording(undoID);
}
});
},
async update() {
Expand All @@ -691,7 +699,16 @@ const Elements = {
const prefab = panel.dump.__prefab__;
const prefabStateInfo = prefab.prefabStateInfo;

if (prefabStateInfo.assetUuid) {
const canUnlink = panel.dumps.some(dump => {
if (dump.__prefab__ && dump.__prefab__.prefabStateInfo) {
const state = dump.__prefab__.prefabStateInfo.state;
if (state === 2 || state === 3) {
return true;
}
}
return false;
});
if (canUnlink) {
panel.$.prefabUnlink.removeAttribute('disabled');
} else {
panel.$.prefabUnlink.setAttribute('disabled', '');
Expand Down
Loading