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)