From f00eb2147d65c8a307833400d10189ff3e1fdb84 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Tue, 11 Apr 2023 08:00:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8A=A8=E6=80=81=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E7=BB=84=E4=BB=B6=E6=97=B6`Inspector`=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E5=BC=82=E5=B8=B8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Documentation~/zh/changelog.md | 2 ++ Editor/MainComponents/MainComponentListEditor.cs | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Documentation~/zh/changelog.md b/Documentation~/zh/changelog.md index 7df3f802..bd3d7052 100644 --- a/Documentation~/zh/changelog.md +++ b/Documentation~/zh/changelog.md @@ -66,6 +66,8 @@ slug: /changelog ## master +* (2023.04.11) 修复动态添加组件时`Inspector`可能异常的问题 + ## v3.6.0 版本要点: diff --git a/Editor/MainComponents/MainComponentListEditor.cs b/Editor/MainComponents/MainComponentListEditor.cs index 97ca4c14..87ec7a62 100644 --- a/Editor/MainComponents/MainComponentListEditor.cs +++ b/Editor/MainComponents/MainComponentListEditor.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using UnityEditor; +using UnityEngine; using UnityEngine.Assertions; using XCharts.Runtime; @@ -102,7 +103,8 @@ namespace XCharts.Editor editor.OnDisable(); m_Editors.Clear(); - for (int i = 0; i < chart.components.Count; i++) + var count = Mathf.Min(chart.components.Count, m_ComponentsProperty.Count); + for (int i = 0; i < count; i++) { if (chart.components[i] != null) { @@ -119,7 +121,7 @@ namespace XCharts.Editor if (!m_EditorTypes.TryGetValue(settingsType, out editorType)) editorType = typeof(MainComponentBaseEditor); - var editor = (MainComponentBaseEditor) Activator.CreateInstance(editorType); + var editor = (MainComponentBaseEditor)Activator.CreateInstance(editorType); editor.Init(chart, component, property, m_BaseEditor); if (index < 0)