mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
add message protocol manager for node editing (#15963)
* add message protocol manager * optimize switch message protocol when editing node * add optimize * again
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
const { template, $, update, close } = require('./base');
|
||||
|
||||
const { getMessageProtocolScene } = require('../utils/prop');
|
||||
|
||||
exports.template = template;
|
||||
exports.$ = $;
|
||||
exports.update = update;
|
||||
@@ -22,9 +24,9 @@ exports.ready = function() {
|
||||
|
||||
$button.addEventListener('confirm', async () => {
|
||||
const uuids = this.dump.value.uuid.values || [this.dump.value.uuid.value];
|
||||
const undoID = await Editor.Message.request('scene', 'begin-recording', uuids);
|
||||
const undoID = await Editor.Message.request(getMessageProtocolScene(this.$this), 'begin-recording', uuids);
|
||||
for (const uuid of uuids) {
|
||||
await Editor.Message.request('scene', 'execute-component-method', {
|
||||
await Editor.Message.request(getMessageProtocolScene(this.$this), 'execute-component-method', {
|
||||
uuid: uuid,
|
||||
name: 'cook',
|
||||
args: [],
|
||||
@@ -32,12 +34,12 @@ exports.ready = function() {
|
||||
}
|
||||
|
||||
for (const uuid of uuids) {
|
||||
await Editor.Message.request('scene', 'execute-component-method', {
|
||||
await Editor.Message.request(getMessageProtocolScene(this.$this), 'execute-component-method', {
|
||||
uuid: uuid,
|
||||
name: 'combine',
|
||||
args: [],
|
||||
});
|
||||
}
|
||||
await Editor.Message.request('scene', 'end-recording', undoID);
|
||||
await Editor.Message.request(getMessageProtocolScene(this.$this), 'end-recording', undoID);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const { trackEventWithTimer } = require('../utils/metrics');
|
||||
const { getMessageProtocolScene } = require('../utils/prop');
|
||||
|
||||
exports.template = `
|
||||
<div class="light-probe-group">
|
||||
@@ -41,10 +42,10 @@ exports.update = async function(dump) {
|
||||
panel.dump = dump;
|
||||
}
|
||||
|
||||
const mode = await Editor.Message.request('scene', 'query-light-probe-edit-mode');
|
||||
const mode = await Editor.Message.request(getMessageProtocolScene(this.$this), 'query-light-probe-edit-mode');
|
||||
panel.changeProbeMode(mode);
|
||||
|
||||
const boxMode = await Editor.Message.request('scene', 'query-light-probe-bounding-box-edit-mode');
|
||||
const boxMode = await Editor.Message.request(getMessageProtocolScene(this.$this), 'query-light-probe-bounding-box-edit-mode');
|
||||
panel.changeProbeBoxMode(boxMode);
|
||||
};
|
||||
|
||||
@@ -61,14 +62,14 @@ exports.ready = function() {
|
||||
if (result.response === 0) {
|
||||
// 先关闭盒子模式
|
||||
if (panel.sceneProbeBoxMode) {
|
||||
await Editor.Message.request('scene', 'toggle-light-probe-bounding-box-edit-mode', !panel.sceneProbeBoxMode);
|
||||
await Editor.Message.request(getMessageProtocolScene(this.$this), 'toggle-light-probe-bounding-box-edit-mode', !panel.sceneProbeBoxMode);
|
||||
}
|
||||
|
||||
const uuidObject = panel.dump.value.uuid;
|
||||
const uuids = uuidObject.values ? uuidObject.values : [uuidObject.value];
|
||||
const undoID = await Editor.Message.request('scene', 'begin-recording', uuids);
|
||||
const undoID = await Editor.Message.request(getMessageProtocolScene(this.$this), 'begin-recording', uuids);
|
||||
for (const uuid of uuids) {
|
||||
Editor.Message.send('scene', 'execute-component-method', {
|
||||
Editor.Message.send(getMessageProtocolScene(this.$this), 'execute-component-method', {
|
||||
uuid: uuid,
|
||||
name: 'generateLightProbes',
|
||||
args: [],
|
||||
@@ -77,12 +78,12 @@ exports.ready = function() {
|
||||
|
||||
trackEventWithTimer('bakingSystem', 'A100006');
|
||||
|
||||
await Editor.Message.request('scene', 'end-recording', undoID);
|
||||
await Editor.Message.request(getMessageProtocolScene(this.$this), 'end-recording', undoID);
|
||||
}
|
||||
});
|
||||
|
||||
panel.$.edit.addEventListener('confirm', async () => {
|
||||
await Editor.Message.request('scene', 'toggle-light-probe-edit-mode', !panel.sceneProbeMode);
|
||||
await Editor.Message.request(getMessageProtocolScene(this.$this), 'toggle-light-probe-edit-mode', !panel.sceneProbeMode);
|
||||
trackEventWithTimer('bakingSystem', 'A100008');
|
||||
});
|
||||
|
||||
@@ -90,7 +91,7 @@ exports.ready = function() {
|
||||
Editor.Message.addBroadcastListener('scene:light-probe-edit-mode-changed', panel.changeProbeModeBind);
|
||||
|
||||
panel.$.box.addEventListener('confirm', async () => {
|
||||
await Editor.Message.request('scene', 'toggle-light-probe-bounding-box-edit-mode', !panel.sceneProbeBoxMode);
|
||||
await Editor.Message.request(getMessageProtocolScene(this.$this), 'toggle-light-probe-bounding-box-edit-mode', !panel.sceneProbeBoxMode);
|
||||
trackEventWithTimer('bakingSystem', 'A100007');
|
||||
});
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ const { join } = require('path');
|
||||
const lodItem = require('./lod-item');
|
||||
const multiLodGroup = require('./multi-lod-group');
|
||||
const { trackEventWithTimer } = require('../../utils/metrics');
|
||||
const { getMessageProtocolScene } = require('../../utils/prop');
|
||||
|
||||
module.paths.push(join(Editor.App.path, 'node_modules'));
|
||||
const Vue = require('vue/dist/vue.min.js');
|
||||
@@ -236,7 +237,7 @@ exports.ready = function() {
|
||||
},
|
||||
recalculateBounds() {
|
||||
const that = this;
|
||||
Editor.Message.send('scene', 'execute-component-method', {
|
||||
Editor.Message.send(getMessageProtocolScene(that.$el), 'execute-component-method', {
|
||||
uuid: that.dump.value.uuid.value,
|
||||
name: 'recalculateBounds',
|
||||
args: [],
|
||||
@@ -245,7 +246,7 @@ exports.ready = function() {
|
||||
},
|
||||
resetObjectSize() {
|
||||
const that = this;
|
||||
Editor.Message.send('scene', 'execute-component-method', {
|
||||
Editor.Message.send(getMessageProtocolScene(that.$el), 'execute-component-method', {
|
||||
uuid: that.dump.value.uuid.value,
|
||||
name: 'resetObjectSize',
|
||||
args: [],
|
||||
@@ -264,21 +265,20 @@ exports.ready = function() {
|
||||
}
|
||||
const preValue = LODs[index].value.screenUsagePercentage.value;
|
||||
const nextValue = LODs[index + 1] ? LODs[index + 1].value.screenUsagePercentage.value : 0;
|
||||
const undoID = await Editor.Message.request('scene', 'begin-recording', uuid);
|
||||
await Editor.Message.request('scene', 'lod-insert', uuid, index + 1, (preValue + nextValue) / 2, null);
|
||||
await Editor.Message.request('scene', 'end-recording', undoID);
|
||||
const undoID = await Editor.Message.request(getMessageProtocolScene(that.$el), 'begin-recording', uuid);
|
||||
await Editor.Message.request(getMessageProtocolScene(that.$el), 'lod-insert', uuid, index + 1, (preValue + nextValue) / 2, null);
|
||||
await Editor.Message.request(getMessageProtocolScene(that.$el), 'end-recording', undoID);
|
||||
trackEventWithTimer('LOD', 'A100005');
|
||||
} else if (operator === 'delete') {
|
||||
if (LODs.length === 1) {
|
||||
console.warn('At least one LOD, Can\'t delete any more');
|
||||
return;
|
||||
}
|
||||
const undoID = await Editor.Message.request('scene', 'begin-recording', uuid);
|
||||
await Editor.Message.request('scene', 'lod-erase', uuid, index);
|
||||
await Editor.Message.request('scene', 'end-recording', undoID);
|
||||
const undoID = await Editor.Message.request(getMessageProtocolScene(that.$el), 'begin-recording', uuid);
|
||||
await Editor.Message.request(getMessageProtocolScene(that.$el), 'lod-erase', uuid, index);
|
||||
await Editor.Message.request(getMessageProtocolScene(that.$el), 'end-recording', undoID);
|
||||
trackEventWithTimer('LOD', 'A100006');
|
||||
}
|
||||
// Editor.Message.send('scene', 'snapshot');
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const { trackEventWithTimer } = require('../../utils/metrics');
|
||||
const { getMessageProtocolScene } = require('../../utils/prop');
|
||||
|
||||
exports.template = `
|
||||
<ui-section :cache-expand="cacheExpandId">
|
||||
@@ -162,7 +163,7 @@ exports.methods = {
|
||||
},
|
||||
async applyCameraSize() {
|
||||
const that = this;
|
||||
let size = await Editor.Message.request('scene', 'lod-apply-current-camera-size', that.dump.value.uuid.value);
|
||||
let size = await Editor.Message.request(getMessageProtocolScene(that.$el), 'lod-apply-current-camera-size', that.dump.value.uuid.value);
|
||||
if (that.$refs[that.screenUsagePercentageRef]) {
|
||||
const min = Editor.Utils.Math.divide(that.$refs[that.screenUsagePercentageRef].min, 100) || 0;
|
||||
let max = null;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const { trackEventWithTimer } = require('../../utils/metrics');
|
||||
const { getMessageProtocolScene } = require('../../utils/prop');
|
||||
|
||||
exports.template = `
|
||||
<div>
|
||||
@@ -114,7 +115,7 @@ exports.methods = {
|
||||
resetMultiObjectSize() {
|
||||
const that = this;
|
||||
that.dump.value.uuid.values.forEach((uuid) => {
|
||||
Editor.Message.send('scene', 'execute-component-method', {
|
||||
Editor.Message.send(getMessageProtocolScene(that.$el), 'execute-component-method', {
|
||||
uuid: uuid,
|
||||
name: 'resetObjectSize',
|
||||
args: [],
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
const { template, $, update, close } = require('./base');
|
||||
const { getMessageProtocolScene } = require('../utils/prop');
|
||||
|
||||
// 排列时,相邻元素的间隔间距
|
||||
const MARGIN = '4px';
|
||||
|
||||
@@ -110,7 +112,7 @@ exports.ready = function() {
|
||||
$export.addEventListener('confirm', async (event) => {
|
||||
event.stopPropagation();
|
||||
|
||||
let assetInfo = await Editor.Message.request('scene', 'export-particle-plist', this.dump.value.uuid.value);
|
||||
let assetInfo = await Editor.Message.request(getMessageProtocolScene(this.$this), 'export-particle-plist', this.dump.value.uuid.value);
|
||||
if (assetInfo) {
|
||||
let values = [this.$this.dump.value];
|
||||
if (this.$this.dump.values) {
|
||||
|
||||
@@ -249,12 +249,12 @@ const uiElements = {
|
||||
const componentUUIDs = this.dump.value.uuid.values || [this.dump.value.uuid.value];
|
||||
await Promise.all(componentUUIDs.map(uuid => {
|
||||
return new Promise((res) => {
|
||||
Editor.Message.request('scene', 'execute-component-method', {
|
||||
Editor.Message.request(propUtils.getMessageProtocolScene(this.$this), 'execute-component-method', {
|
||||
uuid,
|
||||
name: '_calculateBounding',
|
||||
args: [true],
|
||||
}).then(() => {
|
||||
Editor.Message.request('scene', 'execute-component-method', {
|
||||
Editor.Message.request(propUtils.getMessageProtocolScene(this.$this), 'execute-component-method', {
|
||||
uuid,
|
||||
name: 'gizmo.onNodeChanged',
|
||||
args: [],
|
||||
@@ -390,7 +390,7 @@ const uiElements = {
|
||||
this.$.showBounds.addEventListener('change', (event) => {
|
||||
const componentUUIDs = this.dump.value.uuid.values || [this.dump.value.uuid.value];
|
||||
componentUUIDs.forEach(uuid => {
|
||||
Editor.Message.send('scene', 'execute-component-method', {
|
||||
Editor.Message.send(propUtils.getMessageProtocolScene(this.$this), 'execute-component-method', {
|
||||
uuid,
|
||||
name: 'gizmo.showBoundingBox',
|
||||
args: [event.target.value],
|
||||
@@ -407,7 +407,7 @@ const uiElements = {
|
||||
const componentUUIDs = this.dump.value.uuid.values || [this.dump.value.uuid.value];
|
||||
const values = await Promise.all(
|
||||
componentUUIDs.map(
|
||||
uuid => Editor.Message.request('scene', 'execute-component-method', {
|
||||
uuid => Editor.Message.request(propUtils.getMessageProtocolScene(this.$this), 'execute-component-method', {
|
||||
uuid,
|
||||
name: 'gizmo.isShowBoundingBox',
|
||||
args: [],
|
||||
@@ -609,7 +609,7 @@ const uiElements = {
|
||||
if (!this.dump?.value?.uuid?.values && !this.dump?.value?.uuid?.value) { return; }
|
||||
let uuid = this.dump.value.uuid.values ? this.dump.value.uuid.values[0] : this.dump.value.uuid.value;
|
||||
if (!uuid) { return; }
|
||||
let data = await Editor.Message.request('scene', 'execute-component-method', {
|
||||
let data = await Editor.Message.request(propUtils.getMessageProtocolScene(this.$this), 'execute-component-method', {
|
||||
uuid,
|
||||
name: 'getNoisePreview',
|
||||
args: [100, 100],
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const { template, $, update, close } = require('./base');
|
||||
const { getMessageProtocolScene } = require('../utils/prop');
|
||||
|
||||
exports.template = template;
|
||||
exports.$ = $;
|
||||
@@ -21,20 +22,17 @@ exports.ready = function() {
|
||||
|
||||
$button.addEventListener('change', (event) => {
|
||||
event.stopPropagation();
|
||||
// Editor.Message.send('scene', 'snapshot');
|
||||
});
|
||||
|
||||
$button.addEventListener('confirm', async (event) => {
|
||||
event.stopPropagation();
|
||||
|
||||
const uuids = this.dump.value.uuid.values || [this.dump.value.uuid.value];
|
||||
const undoID = await Editor.Message.request('scene', 'begin-recording', uuids);
|
||||
const undoID = await Editor.Message.request(getMessageProtocolScene(this.$this), 'begin-recording', uuids);
|
||||
for (const uuid of uuids) {
|
||||
await Editor.Message.request('scene', 'regenerate-polygon-2d-points', uuid);
|
||||
await Editor.Message.request(getMessageProtocolScene(this.$this), 'regenerate-polygon-2d-points', uuid);
|
||||
}
|
||||
await Editor.Message.request('scene', 'end-recording', undoID);
|
||||
|
||||
// Editor.Message.send('scene', 'snapshot');
|
||||
await Editor.Message.request(getMessageProtocolScene(this.$this), 'end-recording', undoID);
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
@@ -5,23 +5,22 @@ exports.$ = $;
|
||||
exports.update = update;
|
||||
exports.close = close;
|
||||
|
||||
const { setHidden } = require('../utils/prop');
|
||||
const { setHidden, getMessageProtocolScene } = require('../utils/prop');
|
||||
|
||||
exports.ready = function() {
|
||||
this.elements = {
|
||||
_asset: {
|
||||
ready(element) {
|
||||
element.addEventListener('change-dump', async (event) => {
|
||||
// Editor.Message.send('scene', 'snapshot');
|
||||
const uuid = this.dump.value.uuid.value;
|
||||
const dump = event.target.dump;
|
||||
const undoID = await Editor.Message.request('scene', 'begin-recording', uuid);
|
||||
Editor.Message.request('scene', 'execute-component-method', {
|
||||
const undoID = await Editor.Message.request(getMessageProtocolScene(this.$this), 'begin-recording', uuid);
|
||||
Editor.Message.request(getMessageProtocolScene(this.$this), 'execute-component-method', {
|
||||
uuid: this.dump.value.uuid.value,
|
||||
name: 'manager.addAssetToComp',
|
||||
args: [dump.value],
|
||||
});
|
||||
await Editor.Message.request('scene', 'end-recording', undoID);
|
||||
await Editor.Message.request(getMessageProtocolScene(this.$this), 'end-recording', undoID);
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
@@ -2,11 +2,17 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
module.paths.push(path.join(Editor.App.path, 'node_modules'));
|
||||
const Profile = require('@base/electron-profile');
|
||||
const { throttle } = require('lodash');
|
||||
const utils = require('./utils');
|
||||
const { trackEventWithTimer } = require('../utils/metrics');
|
||||
const { injectionStyle } = require('../utils/prop');
|
||||
|
||||
// ipc messages protocol
|
||||
const messageProtocol = {
|
||||
scene: 'scene',
|
||||
};
|
||||
|
||||
const lockList = [];
|
||||
let lockPerform = false;
|
||||
let lastSnapShot = null;
|
||||
@@ -53,16 +59,16 @@ function snapshotLock(panel, lock, uuids, cancel = false) {
|
||||
// 不传options时,会自动记录到undo队列,不需要调用endRecording
|
||||
async function beginRecording(uuids, options) {
|
||||
if (!uuids) { return; }
|
||||
const undoID = await Editor.Message.request('scene', 'begin-recording', uuids, options);
|
||||
const undoID = await Editor.Message.request(messageProtocol.scene, 'begin-recording', uuids, options);
|
||||
return undoID;
|
||||
}
|
||||
|
||||
async function endRecording(undoID, cancel) {
|
||||
if (!undoID) { return; }
|
||||
if (cancel) {
|
||||
await Editor.Message.request('scene', 'cancel-recording', undoID);
|
||||
await Editor.Message.request(messageProtocol.scene, 'cancel-recording', undoID);
|
||||
} else {
|
||||
await Editor.Message.request('scene', 'end-recording', undoID);
|
||||
await Editor.Message.request(messageProtocol.scene, 'end-recording', undoID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +139,7 @@ exports.listeners = {
|
||||
}
|
||||
|
||||
if (setChildrenLayer) {
|
||||
await Editor.Message.request('scene', 'set-node-and-children-layer', {
|
||||
await Editor.Message.request(messageProtocol.scene, 'set-node-and-children-layer', {
|
||||
uuid,
|
||||
dump: {
|
||||
value,
|
||||
@@ -143,7 +149,7 @@ exports.listeners = {
|
||||
continue;
|
||||
}
|
||||
|
||||
await Editor.Message.request('scene', 'set-property', {
|
||||
await Editor.Message.request(messageProtocol.scene, 'set-property', {
|
||||
uuid,
|
||||
path,
|
||||
dump: {
|
||||
@@ -167,7 +173,6 @@ exports.listeners = {
|
||||
clearTimeout(panel.previewTimeId);
|
||||
snapshotLock(panel, false);
|
||||
// In combination with change-dump, snapshot only generated once after ui-elements continuously changed.
|
||||
// Editor.Message.send('scene', 'snapshot');
|
||||
},
|
||||
async 'create-dump'(event) {
|
||||
const panel = this;
|
||||
@@ -179,7 +184,6 @@ exports.listeners = {
|
||||
|
||||
clearTimeout(panel.previewTimeId);
|
||||
|
||||
// Editor.Message.send('scene', 'snapshot');
|
||||
const undoID = await beginRecording(panel.uuidList);
|
||||
const dump = target.dump;
|
||||
let cancel = false;
|
||||
@@ -190,13 +194,12 @@ exports.listeners = {
|
||||
dump.values[i] = dump.value;
|
||||
}
|
||||
|
||||
await Editor.Message.request('scene', 'update-property-from-null', {
|
||||
await Editor.Message.request(messageProtocol.scene, 'update-property-from-null', {
|
||||
uuid,
|
||||
path: dump.path,
|
||||
});
|
||||
}
|
||||
|
||||
// Editor.Message.send('scene', 'snapshot');
|
||||
} catch (error) {
|
||||
cancel = true;
|
||||
console.error(error);
|
||||
@@ -222,7 +225,7 @@ exports.listeners = {
|
||||
dump.values[i] = dump.value;
|
||||
}
|
||||
|
||||
await Editor.Message.request('scene', 'reset-property', {
|
||||
await Editor.Message.request(messageProtocol.scene, 'reset-property', {
|
||||
uuid,
|
||||
path: dump.path,
|
||||
});
|
||||
@@ -277,7 +280,7 @@ exports.listeners = {
|
||||
// 预览新的值
|
||||
value.uuid = assetUuid;
|
||||
|
||||
Editor.Message.send('scene', 'preview-set-property', {
|
||||
Editor.Message.send(messageProtocol.scene, 'preview-set-property', {
|
||||
uuid,
|
||||
path,
|
||||
dump: {
|
||||
@@ -297,7 +300,7 @@ exports.listeners = {
|
||||
const uuid = panel.uuidList[i];
|
||||
const { path } = dump;
|
||||
|
||||
Editor.Message.send('scene', 'cancel-preview-set-property', {
|
||||
Editor.Message.send(messageProtocol.scene, 'cancel-preview-set-property', {
|
||||
uuid,
|
||||
path,
|
||||
});
|
||||
@@ -527,6 +530,21 @@ const Elements = {
|
||||
|
||||
Editor.Message.addBroadcastListener('project:setting-change', panel.__projectSettingChanged__);
|
||||
|
||||
panel.__throttleProfileChanged__ = throttle(async (protocol, file, key) => {
|
||||
if (protocol === 'defaultPreferences' && file === 'packages/inspector.json' && key === 'message-protocol') {
|
||||
await panel.__queryMessageProtocolScene__();
|
||||
|
||||
for (const prop in Elements) {
|
||||
const element = Elements[prop];
|
||||
if (element.update) {
|
||||
await element.update.call(panel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 100, { leading: false, trailing: true });
|
||||
|
||||
Profile.on('change', panel.__throttleProfileChanged__);
|
||||
|
||||
// 识别拖入脚本资源
|
||||
panel.$.container.addEventListener('dragover', (event) => {
|
||||
event.preventDefault();
|
||||
@@ -587,7 +605,7 @@ const Elements = {
|
||||
try {
|
||||
dumps = await Promise.all(
|
||||
panel.uuidList.map((uuid) => {
|
||||
return Editor.Message.request('scene', 'query-node', uuid);
|
||||
return Editor.Message.request(messageProtocol.scene, 'query-node', uuid);
|
||||
}),
|
||||
);
|
||||
} catch (err) {
|
||||
@@ -628,6 +646,10 @@ const Elements = {
|
||||
Editor.Message.removeBroadcastListener('scene:change-node', panel.__nodeChanged__);
|
||||
Editor.Message.removeBroadcastListener('scene:animation-time-change', panel.__animationTimeChange__);
|
||||
Editor.Message.removeBroadcastListener('project:setting-change', panel.__projectSettingChanged__);
|
||||
|
||||
Profile.removeListener('change', panel.__throttleProfileChanged__);
|
||||
panel.__throttleProfileChanged__.cancel();
|
||||
panel.__throttleProfileChanged__ = undefined;
|
||||
},
|
||||
},
|
||||
prefab: {
|
||||
@@ -656,7 +678,7 @@ const Elements = {
|
||||
break;
|
||||
}
|
||||
case 'unlink': {
|
||||
await Editor.Message.request('scene', 'unlink-prefab', prefab.rootUuid, false);
|
||||
await Editor.Message.request(messageProtocol.scene, 'unlink-prefab', prefab.rootUuid, false);
|
||||
break;
|
||||
}
|
||||
case 'local': {
|
||||
@@ -664,12 +686,12 @@ const Elements = {
|
||||
break;
|
||||
}
|
||||
case 'reset': {
|
||||
await Editor.Message.request('scene', 'restore-prefab', prefab.rootUuid, prefab.uuid);
|
||||
await Editor.Message.request(messageProtocol.scene, 'restore-prefab', prefab.rootUuid, prefab.uuid);
|
||||
break;
|
||||
}
|
||||
case 'save': {
|
||||
// apply-prefab是自定义的undo,在场景中实现了undo
|
||||
await Editor.Message.request('scene', 'apply-prefab', prefab.rootUuid);
|
||||
await Editor.Message.request(messageProtocol.scene, 'apply-prefab', prefab.rootUuid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -967,13 +989,13 @@ const Elements = {
|
||||
|
||||
// DIFFUSEMAP_WITH_REFLECTION 的枚举值为 2
|
||||
if (envLightingType === 2) {
|
||||
await Editor.Message.request('scene', 'execute-scene-script', {
|
||||
await Editor.Message.request(messageProtocol.scene, 'execute-scene-script', {
|
||||
name: 'inspector',
|
||||
method: 'generateDiffuseMap',
|
||||
args: [envMapUuid],
|
||||
});
|
||||
} else {
|
||||
await Editor.Message.request('scene', 'execute-scene-script', {
|
||||
await Editor.Message.request(messageProtocol.scene, 'execute-scene-script', {
|
||||
name: 'inspector',
|
||||
method: 'generateVector',
|
||||
args: [envMapUuid],
|
||||
@@ -981,13 +1003,13 @@ const Elements = {
|
||||
}
|
||||
},
|
||||
async setEnvMapAndConvolutionMap(uuid) {
|
||||
await Editor.Message.request('scene', 'execute-scene-script', {
|
||||
await Editor.Message.request(messageProtocol.scene, 'execute-scene-script', {
|
||||
name: 'inspector',
|
||||
method: 'setSkyboxEnvMap',
|
||||
args: [uuid],
|
||||
});
|
||||
if (uuid) {
|
||||
await Editor.Message.request('scene', 'execute-scene-script', {
|
||||
await Editor.Message.request(messageProtocol.scene, 'execute-scene-script', {
|
||||
name: 'inspector',
|
||||
method: 'setReflectionConvolutionMap',
|
||||
args: [uuid],
|
||||
@@ -1026,7 +1048,7 @@ const Elements = {
|
||||
panel.$.sceneSkyboxReflectionLoading.style.display = 'inline-flex';
|
||||
panel.$.sceneSkyboxReflectionBake.style.display = 'none';
|
||||
|
||||
await Editor.Message.request('scene', 'execute-scene-script', {
|
||||
await Editor.Message.request(messageProtocol.scene, 'execute-scene-script', {
|
||||
name: 'inspector',
|
||||
method: 'bakeReflectionConvolution',
|
||||
args: [envMapData.value.uuid],
|
||||
@@ -1314,6 +1336,7 @@ const Elements = {
|
||||
$section.appendChild($panel);
|
||||
$section.__panels__.push($panel);
|
||||
$panel.dump = component;
|
||||
$panel.messageProtocol = messageProtocol;
|
||||
$panel.update(component);
|
||||
});
|
||||
|
||||
@@ -1341,6 +1364,8 @@ const Elements = {
|
||||
panel.$.nodeSection.appendChild(array[index]);
|
||||
}
|
||||
array[index].setAttribute('src', file);
|
||||
array[index].dump = panel.dump;
|
||||
array[index].messageProtocol = messageProtocol;
|
||||
array[index].update(panel.dump);
|
||||
});
|
||||
|
||||
@@ -1408,11 +1433,11 @@ const Elements = {
|
||||
const uuidList = panel.uuidList;
|
||||
switch (type) {
|
||||
case 'save-o': {
|
||||
Editor.Message.request('scene', 'apply-removed-component', uuidList[0], info.fileID);
|
||||
Editor.Message.request(messageProtocol.scene, 'apply-removed-component', uuidList[0], info.fileID);
|
||||
break;
|
||||
}
|
||||
case 'reset': {
|
||||
Editor.Message.request('scene', 'revert-removed-component', uuidList[0], info.fileID);
|
||||
Editor.Message.request(messageProtocol.scene, 'revert-removed-component', uuidList[0], info.fileID);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1498,7 +1523,7 @@ const Elements = {
|
||||
// 批量调用request意味着编辑操作在很多帧后才会完成,所以不能自动记录undo
|
||||
const undoID = await beginRecording(panel.uuidList);
|
||||
for (const uuid of panel.uuidList) {
|
||||
await Editor.Message.request('scene', 'create-component', {
|
||||
await Editor.Message.request(messageProtocol.scene, 'create-component', {
|
||||
uuid,
|
||||
component: detail.info.cid,
|
||||
});
|
||||
@@ -1643,7 +1668,7 @@ exports.methods = {
|
||||
}
|
||||
}
|
||||
|
||||
Editor.Message.send('scene', cmd);
|
||||
Editor.Message.send(messageProtocol.scene, cmd);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -1697,7 +1722,7 @@ exports.methods = {
|
||||
const values = dump.value.uuid.values || [dump.value.uuid.value];
|
||||
const undoID = await beginRecording(values);
|
||||
for (const compUuid of values) {
|
||||
await Editor.Message.request('scene', 'reset-component', {
|
||||
await Editor.Message.request(messageProtocol.scene, 'reset-component', {
|
||||
uuid: compUuid,
|
||||
});
|
||||
}
|
||||
@@ -1728,7 +1753,7 @@ exports.methods = {
|
||||
if (!uuids.length > 0) { return; }
|
||||
const undoID = await beginRecording(uuids);
|
||||
for (let i = 0; i < uuids.length; i++) {
|
||||
await Editor.Message.request('scene', 'remove-array-element', {
|
||||
await Editor.Message.request(messageProtocol.scene, 'remove-array-element', {
|
||||
uuid: uuids[i],
|
||||
path: '__comps__',
|
||||
index: indexes[i],
|
||||
@@ -1742,7 +1767,7 @@ exports.methods = {
|
||||
enabled: !isMultiple && index !== 0,
|
||||
async click() {
|
||||
const undoID = await beginRecording(uuid);
|
||||
await Editor.Message.request('scene', 'move-array-element', {
|
||||
await Editor.Message.request(messageProtocol.scene, 'move-array-element', {
|
||||
uuid,
|
||||
path: '__comps__',
|
||||
target: index,
|
||||
@@ -1756,7 +1781,7 @@ exports.methods = {
|
||||
enabled: !isMultiple && index !== total - 1,
|
||||
async click() {
|
||||
const undoID = await beginRecording(uuid);
|
||||
await Editor.Message.request('scene', 'move-array-element', {
|
||||
await Editor.Message.request(messageProtocol.scene, 'move-array-element', {
|
||||
uuid,
|
||||
path: '__comps__',
|
||||
target: index,
|
||||
@@ -1802,7 +1827,7 @@ exports.methods = {
|
||||
const index = indexes[i];
|
||||
|
||||
const nodeDump = nodeDumps.find(nodeDump => uuid === nodeDump.uuid.value);
|
||||
await Editor.Message.request('scene', 'set-property', {
|
||||
await Editor.Message.request(messageProtocol.scene, 'set-property', {
|
||||
uuid,
|
||||
path: nodeDump.__comps__[index].path,
|
||||
dump: clipboardComponentInfo.dump,
|
||||
@@ -1822,20 +1847,20 @@ exports.methods = {
|
||||
let index = 0;
|
||||
for (const dump of values) {
|
||||
const uuid = uuidList[index];
|
||||
await Editor.Message.request('scene', 'create-component', {
|
||||
await Editor.Message.request(messageProtocol.scene, 'create-component', {
|
||||
uuid,
|
||||
component: clipboardComponentInfo.cid,
|
||||
});
|
||||
|
||||
// 检查是否创建成功,是的话,给赋值
|
||||
const nodeDump = await Editor.Message.request('scene', 'query-node', uuid);
|
||||
const nodeDump = await Editor.Message.request(messageProtocol.scene, 'query-node', uuid);
|
||||
const length = nodeDump.__comps__ && nodeDump.__comps__.length;
|
||||
if (length) {
|
||||
const lastIndex = length - 1;
|
||||
const lastComp = nodeDump.__comps__[lastIndex];
|
||||
|
||||
if (lastComp?.cid === clipboardComponentInfo.cid) {
|
||||
await Editor.Message.request('scene', 'set-property', {
|
||||
await Editor.Message.request(messageProtocol.scene, 'set-property', {
|
||||
uuid,
|
||||
path: `__comps__.${lastIndex}`,
|
||||
dump: clipboardComponentInfo.dump,
|
||||
@@ -1876,7 +1901,7 @@ exports.methods = {
|
||||
async click() {
|
||||
const undoID = await beginRecording(uuidList);
|
||||
for (const uuid of uuidList) {
|
||||
await Editor.Message.request('scene', 'reset-node', {
|
||||
await Editor.Message.request(messageProtocol.scene, 'reset-node', {
|
||||
uuid,
|
||||
});
|
||||
}
|
||||
@@ -1902,7 +1927,7 @@ exports.methods = {
|
||||
const undoID = await beginRecording(uuidList);
|
||||
for (const uuid of uuidList) {
|
||||
for (const attr of clipboardNodeInfo.attrs) {
|
||||
await Editor.Message.request('scene', 'set-property', {
|
||||
await Editor.Message.request(messageProtocol.scene, 'set-property', {
|
||||
uuid,
|
||||
path: attr,
|
||||
dump: clipboardNodeInfo.dump[attr],
|
||||
@@ -1917,7 +1942,7 @@ exports.methods = {
|
||||
label: Editor.I18n.t('ENGINE.menu.copy_node_world_transform'),
|
||||
enabled: !isMultiple,
|
||||
async click() {
|
||||
const data = await Editor.Message.request('scene', 'execute-scene-script', {
|
||||
const data = await Editor.Message.request(messageProtocol.scene, 'execute-scene-script', {
|
||||
name: 'inspector',
|
||||
method: 'queryNodeWorldTransform',
|
||||
args: [dump.uuid.value],
|
||||
@@ -1937,7 +1962,7 @@ exports.methods = {
|
||||
if (clipboardNodeWorldTransform.data) {
|
||||
const undoID = await beginRecording(uuidList);
|
||||
for (const uuid of uuidList) {
|
||||
await Editor.Message.request('scene', 'execute-scene-script', {
|
||||
await Editor.Message.request(messageProtocol.scene, 'execute-scene-script', {
|
||||
name: 'inspector',
|
||||
method: 'setNodeWorldTransform',
|
||||
args: [uuid, clipboardNodeWorldTransform.data],
|
||||
@@ -1954,20 +1979,20 @@ exports.methods = {
|
||||
async click() {
|
||||
const undoID = await beginRecording(uuidList);
|
||||
for (const uuid of uuidList) {
|
||||
await Editor.Message.request('scene', 'create-component', {
|
||||
await Editor.Message.request(messageProtocol.scene, 'create-component', {
|
||||
uuid,
|
||||
component: clipboardComponentInfo.cid,
|
||||
});
|
||||
|
||||
// 检查是否创建成功,是的话,给赋值
|
||||
const nodeDump = await Editor.Message.request('scene', 'query-node', uuid);
|
||||
const nodeDump = await Editor.Message.request(messageProtocol.scene, 'query-node', uuid);
|
||||
const length = nodeDump.__comps__ && nodeDump.__comps__.length;
|
||||
if (length) {
|
||||
const lastIndex = length - 1;
|
||||
const lastComp = nodeDump.__comps__[lastIndex];
|
||||
|
||||
if (lastComp?.cid === clipboardComponentInfo.cid) {
|
||||
await Editor.Message.request('scene', 'set-property', {
|
||||
await Editor.Message.request(messageProtocol.scene, 'set-property', {
|
||||
uuid,
|
||||
path: `__comps__.${lastIndex}`,
|
||||
dump: clipboardComponentInfo.dump,
|
||||
@@ -1985,7 +2010,7 @@ exports.methods = {
|
||||
async click() {
|
||||
const undoID = await beginRecording(uuidList);
|
||||
for (const uuid of uuidList) {
|
||||
await Editor.Message.request('scene', 'reset-property', {
|
||||
await Editor.Message.request(messageProtocol.scene, 'reset-property', {
|
||||
uuid,
|
||||
path: 'position',
|
||||
});
|
||||
@@ -1999,7 +2024,7 @@ exports.methods = {
|
||||
async click() {
|
||||
const undoID = await beginRecording(uuidList);
|
||||
for (const uuid of uuidList) {
|
||||
await Editor.Message.request('scene', 'reset-property', {
|
||||
await Editor.Message.request(messageProtocol.scene, 'reset-property', {
|
||||
uuid,
|
||||
path: 'rotation',
|
||||
});
|
||||
@@ -2013,7 +2038,7 @@ exports.methods = {
|
||||
async click() {
|
||||
const undoID = await beginRecording(uuidList);
|
||||
for (const uuid of uuidList) {
|
||||
await Editor.Message.request('scene', 'reset-property', {
|
||||
await Editor.Message.request(messageProtocol.scene, 'reset-property', {
|
||||
uuid,
|
||||
path: 'scale',
|
||||
});
|
||||
@@ -2027,7 +2052,7 @@ exports.methods = {
|
||||
async click() {
|
||||
const undoID = await beginRecording(uuidList);
|
||||
for (const uuid of uuidList) {
|
||||
await Editor.Message.request('scene', 'reset-property', {
|
||||
await Editor.Message.request(messageProtocol.scene, 'reset-property', {
|
||||
uuid,
|
||||
path: 'mobility',
|
||||
});
|
||||
@@ -2052,7 +2077,7 @@ exports.methods = {
|
||||
const dumpData = materialUuids[assetUuid][dumpPath];
|
||||
for (let i = 0; i < panel.uuidList.length; i++) {
|
||||
const nodeUuid = panel.uuidList[i];
|
||||
await Editor.Message.request('scene', 'set-property', {
|
||||
await Editor.Message.request(messageProtocol.scene, 'set-property', {
|
||||
uuid: nodeUuid,
|
||||
path: dumpPath,
|
||||
dump: {
|
||||
@@ -2110,6 +2135,23 @@ exports.ready = async function ready() {
|
||||
// 为了避免把 ui-num-input, ui-color 的连续 change 进行 snapshot
|
||||
panel.snapshotLock = false;
|
||||
|
||||
// 节点的 ipc 协议,指向 scene 或 xr-scene 等进程
|
||||
panel.__queryMessageProtocolScene__ = async function() {
|
||||
try {
|
||||
if (!panel.messageProtocol) {
|
||||
panel.messageProtocol = messageProtocol;
|
||||
}
|
||||
const config = await await Editor.Profile.getConfig('inspector', 'message-protocol');
|
||||
if (config) {
|
||||
Object.assign(messageProtocol, config);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
messageProtocol.scene = 'scene';
|
||||
}
|
||||
};
|
||||
await panel.__queryMessageProtocolScene__();
|
||||
|
||||
for (const prop in Elements) {
|
||||
const element = Elements[prop];
|
||||
if (element.ready) {
|
||||
|
||||
@@ -184,6 +184,32 @@ exports.setHidden = function(data, element) {
|
||||
}
|
||||
};
|
||||
|
||||
// In order to avoid a large number of operations in a short time, the function of returning the same operation result in a time period is added
|
||||
let getMessageProtocolSceneResult = '';
|
||||
let getMessageProtocolSceneStartTime = Date.now();
|
||||
exports.getMessageProtocolScene = function(element) {
|
||||
if (getMessageProtocolSceneResult && Date.now() - getMessageProtocolSceneStartTime < 1000) {
|
||||
return getMessageProtocolSceneResult;
|
||||
}
|
||||
|
||||
getMessageProtocolSceneResult = '';
|
||||
getMessageProtocolSceneStartTime = Date.now();
|
||||
|
||||
while (element) {
|
||||
element = element.parentElement || element.getRootNode().host;
|
||||
if (element && element.messageProtocol) {
|
||||
getMessageProtocolSceneResult = element.messageProtocol.scene;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!getMessageProtocolSceneResult) {
|
||||
getMessageProtocolSceneResult = 'scene';
|
||||
}
|
||||
|
||||
return getMessageProtocolSceneResult;
|
||||
};
|
||||
|
||||
exports.updatePropByDump = function(panel, dump) {
|
||||
panel.dump = dump;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user