From afe308dfc468edf386e730a44483c4aef175bb2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=A3=AE=E6=96=8C?= Date: Thu, 4 Aug 2022 16:14:29 +0800 Subject: [PATCH] [Bug] performance optimize in inspector (#12328) * interface optimize * performance optimize in editor inspector --- editor/inspector/assets/material.js | 7 ++++++- editor/inspector/components/particle-system.js | 16 ++++++++++++---- editor/inspector/contributions/node.css | 4 +++- editor/inspector/contributions/node.js | 18 ++++++++++++++---- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/editor/inspector/assets/material.js b/editor/inspector/assets/material.js index d371abe55c..d33c21cf88 100644 --- a/editor/inspector/assets/material.js +++ b/editor/inspector/assets/material.js @@ -466,6 +466,11 @@ exports.update = async function(assetList, metaList) { this.asset = assetList[0]; this.meta = metaList[0]; + // 增加容错 + if (!this.$this.isConnected) { + return; + } + if (assetList.length !== 1) { this.$.invalid.setAttribute('active', ''); return; @@ -492,7 +497,7 @@ exports.update = async function(assetList, metaList) { /** * Method of initializing the panel */ -exports.ready = async function() { +exports.ready = function() { this.canUpdatePreview = false; // Used to determine whether the material has been modified in isDirty() this.dirtyData = { diff --git a/editor/inspector/components/particle-system.js b/editor/inspector/components/particle-system.js index 5c64a73fd9..4aed84e75a 100644 --- a/editor/inspector/components/particle-system.js +++ b/editor/inspector/components/particle-system.js @@ -363,6 +363,13 @@ const uiElements = { if (autoflag) { const oldChildren = Array.from(element.children); const children = []; + + const oldCheckbox = element.querySelector('[slot="header"] > ui-checkbox'); + if (oldCheckbox) { + oldCheckbox.removeEventListener('change', oldCheckbox.changeEvent); + oldCheckbox.changeEvent = undefined; + } + const header = document.createElement('ui-prop'); header.setAttribute('slot', 'header'); header.setAttribute('type', 'dump'); @@ -370,10 +377,11 @@ const uiElements = { header.className = 'header'; header.dump = this.getObjectByKey(this.dump.value, key); const checkbox = document.createElement('ui-checkbox'); - checkbox.addEventListener('change', (event) => { + checkbox.changeEvent = (event) => { this.getObjectByKey(this.dump.value, key).value.enable.value = event.target.value; header.dispatch('change-dump'); - }); + }; + checkbox.addEventListener('change', checkbox.changeEvent); checkbox.setAttribute('value', this.getObjectByKey(this.dump.value, key).value.enable.value); const label = document.createElement('ui-label'); label.setAttribute('value', this.getName(this.getObjectByKey(this.dump.value, key))); @@ -669,7 +677,7 @@ exports.$ = { noisePreview: '#noisePreview', }; -exports.ready = function () { +exports.ready = function() { for (const key in uiElements) { const element = uiElements[key]; if (typeof element.ready === 'function') { @@ -677,7 +685,7 @@ exports.ready = function () { } } }; -exports.update = function (dump) { +exports.update = function(dump) { this.dump = dump; for (const key in uiElements) { const element = uiElements[key]; diff --git a/editor/inspector/contributions/node.css b/editor/inspector/contributions/node.css index e8b0f563d4..a308940dcd 100644 --- a/editor/inspector/contributions/node.css +++ b/editor/inspector/contributions/node.css @@ -8,8 +8,10 @@ flex: 1; display: flex; flex-direction: column; - overflow: scroll; + overflow-y: scroll; + overflow-x: auto; padding-left: 6px; + padding-right: 2px; } .container[hoving] { diff --git a/editor/inspector/contributions/node.js b/editor/inspector/contributions/node.js index 250d238026..0e64b45132 100644 --- a/editor/inspector/contributions/node.js +++ b/editor/inspector/contributions/node.js @@ -1248,7 +1248,7 @@ const Elements = { panel.$.sectionAsset.prepend(materialPanel); } - materialPanel.addEventListener('focus', () => { + materialPanel.focusEventInNode = () => { const children = Array.from(materialPanel.parentElement.children); children.forEach((child) => { if (child === materialPanel) { @@ -1257,14 +1257,16 @@ const Elements = { child.removeAttribute('focused'); } }); - }); - materialPanel.addEventListener('blur', () => { + }; + materialPanel.blurEventInNode = () => { if (panel.blurSleep) { return; } materialPanel.removeAttribute('focused'); - }); + }; + materialPanel.addEventListener('focus', materialPanel.focusEventInNode); + materialPanel.addEventListener('blur', materialPanel.blurEventInNode); } materialPanels.push(materialPanel); materialPrevPanel = materialPanel; @@ -1274,6 +1276,10 @@ const Elements = { for (const oldChild of oldChildren) { if (oldChild && materialPanels.indexOf(oldChild) === -1) { await oldChild.panel.beforeClose.call(oldChild.panelObject); + oldChild.removeEventListener('focus', oldChild.focusEventInNode); + oldChild.removeEventListener('blur', oldChild.blurEventInNode); + oldChild.focusEventInNode = undefined; + oldChild.blurEventInNode = undefined; oldChild.remove(); } } @@ -1289,6 +1295,10 @@ const Elements = { if (next === false) { return false; } else { + materialPanel.removeEventListener('focus', materialPanel.focusEventInNode); + materialPanel.removeEventListener('blur', materialPanel.blurEventInNode); + materialPanel.focusEventInNode = undefined; + materialPanel.blurEventInNode = undefined; materialPanel.remove(); } }