fix: modular avatar parameters is super slow (#834)

This commit is contained in:
bd_ 2024-04-22 10:26:11 +09:00 committed by GitHub
parent 3ebc4fb2cf
commit c111b29fbb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -36,23 +36,19 @@ namespace nadena.dev.modular_avatar.core.editor
} }
} }
private void OnEnable() #if UNITY_2022_1_OR_NEWER
private bool _delayPending = false;
private void DelayRecalculate()
{ {
#if UNITY_2022_1_OR_NEWER _delayPending = false;
ObjectChangeEvents.changesPublished += OnChangesPublished;
#endif
Recalculate(); Recalculate();
} }
#if UNITY_2022_1_OR_NEWER
private void OnChangesPublished(ref ObjectChangeEventStream stream) private void OnChangesPublished(ref ObjectChangeEventStream stream)
{ {
Recalculate(); if (!_delayPending) EditorApplication.delayCall += DelayRecalculate;
} _delayPending = true;
private void OnDisable()
{
ObjectChangeEvents.changesPublished -= OnChangesPublished;
} }
#endif #endif
@ -65,7 +61,18 @@ namespace nadena.dev.modular_avatar.core.editor
_legendContainer = _root.Q<VisualElement>("Legend"); _legendContainer = _root.Q<VisualElement>("Legend");
_usageBoxContainer = _root.Q<VisualElement>("UsageBox"); _usageBoxContainer = _root.Q<VisualElement>("UsageBox");
Recalculate(); #if UNITY_2022_1_OR_NEWER
_root.RegisterCallback<AttachToPanelEvent>(_evt =>
{
ObjectChangeEvents.changesPublished += OnChangesPublished;
Recalculate();
});
_root.RegisterCallback<DetachFromPanelEvent>(_evt =>
{
ObjectChangeEvents.changesPublished -= OnChangesPublished;
});
#endif
return _root; return _root;
} }