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,25 +175,40 @@ 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 baseHeight = _devMode ? elemHeight * 2 : elemHeight; float[] cache = new float[_selectedIndices.Count];
var param = GetParamByIndex(_selectedIndices[index]); for (int i = 0; i < _selectedIndices.Count; i++)
var syncMode = param.FindPropertyRelative(nameof(ParameterConfig.syncType));
if (syncMode.enumValueIndex != (int) ParameterSyncType.NotSynced)
{ {
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 cache;
{ }
return elemHeight + baseHeight;
} private float ElementHeight(int reqIndex)
else {
{ return ElementHeightCache[reqIndex];
return baseHeight;
}
} }
private void DrawAutodetectHeader(ref Rect rect) private void DrawAutodetectHeader(ref Rect 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();