fix: slow behavior with lots of parameters

Closes: #217
This commit is contained in:
bd_ 2023-02-22 23:26:53 +09:00
parent d385eb8800
commit d940e5de8a

View File

@ -175,27 +175,42 @@ namespace nadena.dev.modular_avatar.core.editor
_needsRebuild = true; _needsRebuild = true;
} }
private float ElementHeight(int index) // https://github.com/bdunderscore/modular-avatar/issues/217
private float[] ElementHeightCache = null;
private float[] BuildHeightCache()
{
float[] cache = new float[_selectedIndices.Count];
for (int i = 0; i < _selectedIndices.Count; i++)
{ {
float baseHeight = _devMode ? elemHeight * 2 : elemHeight; float baseHeight = _devMode ? elemHeight * 2 : elemHeight;
var param = GetParamByIndex(_selectedIndices[index]); var param = GetParamByIndex(_selectedIndices[i]);
var syncMode = param.FindPropertyRelative(nameof(ParameterConfig.syncType)); var syncMode = param.FindPropertyRelative(nameof(ParameterConfig.syncType));
if (syncMode.enumValueIndex != (int) ParameterSyncType.NotSynced) if (syncMode.enumValueIndex != (int) ParameterSyncType.NotSynced)
{ {
baseHeight += elemHeight; baseHeight += elemHeight;
} }
if (_selectedIndices[index] == -1) if (_selectedIndices[i] == -1)
{ {
return elemHeight + baseHeight; cache[i] = elemHeight + baseHeight;
} }
else else
{ {
return baseHeight; cache[i] = baseHeight;
} }
} }
return cache;
}
private float ElementHeight(int reqIndex)
{
return ElementHeightCache[reqIndex];
}
private void DrawAutodetectHeader(ref Rect rect) private void DrawAutodetectHeader(ref Rect rect)
{ {
Rect top = rect; Rect top = rect;
@ -412,6 +427,8 @@ namespace nadena.dev.modular_avatar.core.editor
protected override void OnInnerInspectorGUI() protected override void OnInnerInspectorGUI()
{ {
ElementHeightCache = BuildHeightCache();
EditorGUI.BeginChangeCheck(); EditorGUI.BeginChangeCheck();
_devMode = EditorGUILayout.Toggle(G("params.devmode"), _devMode); _devMode = EditorGUILayout.Toggle(G("params.devmode"), _devMode);
if (EditorGUI.EndChangeCheck() || _reorderableList == null || _needsRebuild) SetupList(); if (EditorGUI.EndChangeCheck() || _reorderableList == null || _needsRebuild) SetupList();