mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 17:26:02 +08:00
Minor OnValidate optimization
Code now only runs on selected node
This commit is contained in:
parent
c66ac47ea9
commit
97bbc236be
@ -138,7 +138,14 @@ public partial class NodeEditorWindow {
|
|||||||
Event e = Event.current;
|
Event e = Event.current;
|
||||||
if (e.type == EventType.Repaint) portConnectionPoints.Clear();
|
if (e.type == EventType.Repaint) portConnectionPoints.Clear();
|
||||||
|
|
||||||
BeginWindows();
|
//Selected node is hashed before and after node GUI to detect changes
|
||||||
|
int nodeHash = 0;
|
||||||
|
System.Reflection.MethodInfo onValidate = null;
|
||||||
|
if (selectedNode != null) {
|
||||||
|
onValidate = selectedNode.GetType().GetMethod("OnValidate");
|
||||||
|
if (onValidate != null) nodeHash = selectedNode.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
BeginZoomed(position, zoom);
|
BeginZoomed(position, zoom);
|
||||||
//if (e.type == EventType.Repaint) portRects.Clear();
|
//if (e.type == EventType.Repaint) portRects.Clear();
|
||||||
foreach (Node node in graph.nodes) {
|
foreach (Node node in graph.nodes) {
|
||||||
@ -157,11 +164,6 @@ public partial class NodeEditorWindow {
|
|||||||
|
|
||||||
nodeEditor.target = node;
|
nodeEditor.target = node;
|
||||||
|
|
||||||
//Node is hashed before and after node GUI to detect changes
|
|
||||||
int nodeHash = 0;
|
|
||||||
var onValidate = node.GetType().GetMethod("OnValidate");
|
|
||||||
if (onValidate != null) nodeHash = node.GetHashCode();
|
|
||||||
|
|
||||||
nodeEditor.OnNodeGUI();
|
nodeEditor.OnNodeGUI();
|
||||||
if (e.type == EventType.Repaint) {
|
if (e.type == EventType.Repaint) {
|
||||||
foreach (var kvp in nodeEditor.portRects) {
|
foreach (var kvp in nodeEditor.portRects) {
|
||||||
@ -169,9 +171,6 @@ public partial class NodeEditorWindow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//If a change in hash is detected, call OnValidate method. This is done through reflection because OnValidate is only relevant in editor, and thus, the code should not be included in build.
|
|
||||||
if (onValidate != null && nodeHash != node.GetHashCode()) onValidate.Invoke(node, null);
|
|
||||||
|
|
||||||
GUILayout.EndVertical();
|
GUILayout.EndVertical();
|
||||||
|
|
||||||
GUILayout.FlexibleSpace();
|
GUILayout.FlexibleSpace();
|
||||||
@ -181,6 +180,12 @@ public partial class NodeEditorWindow {
|
|||||||
GUILayout.EndArea();
|
GUILayout.EndArea();
|
||||||
}
|
}
|
||||||
EndZoomed(position, zoom);
|
EndZoomed(position, zoom);
|
||||||
EndWindows();
|
|
||||||
|
//If a change in hash is detected in the selected node, call OnValidate method.
|
||||||
|
//This is done through reflection because OnValidate is only relevant in editor,
|
||||||
|
//and thus, the code should not be included in build.
|
||||||
|
if (selectedNode != null) {
|
||||||
|
if (onValidate != null && nodeHash != selectedNode.GetHashCode()) onValidate.Invoke(selectedNode, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user