From 887f7d0dffef48d1c608153ef0c67b113b23a3c8 Mon Sep 17 00:00:00 2001 From: bd_ Date: Wed, 22 Feb 2023 23:29:45 +0900 Subject: [PATCH] fix: improve parameter inspector perf when using lots of parameters This doesn't fully close #217, but it's an improvement. Fully fixing it will require reworking the UI fully (or getting unity to fix their terrible code :/) --- .../Inspector/AvatarParametersEditor.cs | 45 +++++++++++++------ 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/Packages/nadena.dev.modular-avatar/Editor/Inspector/AvatarParametersEditor.cs b/Packages/nadena.dev.modular-avatar/Editor/Inspector/AvatarParametersEditor.cs index a2990562..cf26c54e 100644 --- a/Packages/nadena.dev.modular-avatar/Editor/Inspector/AvatarParametersEditor.cs +++ b/Packages/nadena.dev.modular-avatar/Editor/Inspector/AvatarParametersEditor.cs @@ -175,25 +175,40 @@ namespace nadena.dev.modular_avatar.core.editor _needsRebuild = true; } - private float ElementHeight(int index) + // https://github.com/bdunderscore/modular-avatar/issues/217 + private float[] ElementHeightCache = null; + + private float[] BuildHeightCache() { - float baseHeight = _devMode ? elemHeight * 2 : elemHeight; + float[] cache = new float[_selectedIndices.Count]; - var param = GetParamByIndex(_selectedIndices[index]); - var syncMode = param.FindPropertyRelative(nameof(ParameterConfig.syncType)); - if (syncMode.enumValueIndex != (int) ParameterSyncType.NotSynced) + for (int i = 0; i < _selectedIndices.Count; i++) { - baseHeight += elemHeight; + float baseHeight = _devMode ? elemHeight * 2 : elemHeight; + + var param = GetParamByIndex(_selectedIndices[i]); + var syncMode = param.FindPropertyRelative(nameof(ParameterConfig.syncType)); + if (syncMode.enumValueIndex != (int) ParameterSyncType.NotSynced) + { + baseHeight += elemHeight; + } + + if (_selectedIndices[i] == -1) + { + cache[i] = elemHeight + baseHeight; + } + else + { + cache[i] = baseHeight; + } } - if (_selectedIndices[index] == -1) - { - return elemHeight + baseHeight; - } - else - { - return baseHeight; - } + return cache; + } + + private float ElementHeight(int reqIndex) + { + return ElementHeightCache[reqIndex]; } private void DrawAutodetectHeader(ref Rect rect) @@ -412,6 +427,8 @@ namespace nadena.dev.modular_avatar.core.editor protected override void OnInnerInspectorGUI() { + ElementHeightCache = BuildHeightCache(); + EditorGUI.BeginChangeCheck(); _devMode = EditorGUILayout.Toggle(G("params.devmode"), _devMode); if (EditorGUI.EndChangeCheck() || _reorderableList == null || _needsRebuild) SetupList();