Skip to content

Commit

Permalink
fix: modular avatar parameters is super slow (#834)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdunderscore committed Apr 22, 2024
1 parent 3ebc4fb commit c111b29
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions Editor/ParamsUsage/ParamsUsageEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,19 @@ public bool Visible
}
}

private void OnEnable()
{
#if UNITY_2022_1_OR_NEWER
ObjectChangeEvents.changesPublished += OnChangesPublished;
#endif
Recalculate();
}

#if UNITY_2022_1_OR_NEWER
private void OnChangesPublished(ref ObjectChangeEventStream stream)
private bool _delayPending = false;

private void DelayRecalculate()
{
_delayPending = false;
Recalculate();
}

private void OnDisable()
private void OnChangesPublished(ref ObjectChangeEventStream stream)
{
ObjectChangeEvents.changesPublished -= OnChangesPublished;
if (!_delayPending) EditorApplication.delayCall += DelayRecalculate;
_delayPending = true;
}
#endif

Expand All @@ -65,7 +61,18 @@ protected override VisualElement CreateInnerInspectorGUI()
_legendContainer = _root.Q<VisualElement>("Legend");
_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;
}
Expand Down Expand Up @@ -101,7 +108,7 @@ private static IEnumerable<Color> Colors()
private void Recalculate()
{
if (_root == null || !_visible) return;

var ctx = serializedObject.context as GameObject;

if (ctx == null) return;
Expand Down

0 comments on commit c111b29

Please sign in to comment.