From 62ec9a54cf816cb384e3833c34865b66dd900bc3 Mon Sep 17 00:00:00 2001 From: Emre Dogan <48212096+EmreDogann@users.noreply.github.com> Date: Fri, 6 Oct 2023 00:54:56 +0100 Subject: [PATCH] Repaint current graph window on undo/redo to feel more responsive. --- Scripts/Editor/NodeEditorWindow.cs | 39 ++++++++++++++++++------------ 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/Scripts/Editor/NodeEditorWindow.cs b/Scripts/Editor/NodeEditorWindow.cs index f434e73..90928d5 100644 --- a/Scripts/Editor/NodeEditorWindow.cs +++ b/Scripts/Editor/NodeEditorWindow.cs @@ -54,23 +54,10 @@ namespace XNodeEditor } } - private void OnDisable() - { - // Cache portConnectionPoints before serialization starts - int count = portConnectionPoints.Count; - _references = new NodePortReference[count]; - _rects = new Rect[count]; - int index = 0; - foreach (var portConnectionPoint in portConnectionPoints) - { - _references[index] = new NodePortReference(portConnectionPoint.Key); - _rects[index] = portConnectionPoint.Value; - index++; - } - } - private void OnEnable() { + Undo.undoRedoPerformed += OnUndoRedoPerformed; + // Reload portConnectionPoints if there are any int length = _references.Length; if (length == _rects.Length) @@ -86,6 +73,23 @@ namespace XNodeEditor } } + private void OnDisable() + { + Undo.undoRedoPerformed -= OnUndoRedoPerformed; + + // Cache portConnectionPoints before serialization starts + int count = portConnectionPoints.Count; + _references = new NodePortReference[count]; + _rects = new Rect[count]; + int index = 0; + foreach (var portConnectionPoint in portConnectionPoints) + { + _references[index] = new NodePortReference(portConnectionPoint.Key); + _rects[index] = portConnectionPoint.Value; + index++; + } + } + public Dictionary nodeSizes { get; } = new Dictionary(); public NodeGraph graph; public Vector2 panOffset @@ -154,6 +158,11 @@ namespace XNodeEditor } } + private void OnUndoRedoPerformed() + { + Repaint(); + } + /// Make sure the graph editor is assigned and to the right object private void ValidateGraphEditor() {