Skip to content

Commit

Permalink
Removed GetHashCode override.
Browse files Browse the repository at this point in the history
This should improve performance, but has previously caused a slew of bugs.
Bugtest thoroughly before merging
  • Loading branch information
Siccity committed Feb 16, 2019
1 parent 3a8ae36 commit 57d3a03
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
10 changes: 3 additions & 7 deletions Scripts/Editor/NodeEditorGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,10 @@ private void DrawNodes() {
selectionCache = new List<UnityEngine.Object>(Selection.objects);
}

//Active node is hashed before and after node GUI to detect changes
int nodeHash = 0;
System.Reflection.MethodInfo onValidate = null;
if (Selection.activeObject != null && Selection.activeObject is XNode.Node) {
onValidate = Selection.activeObject.GetType().GetMethod("OnValidate");
if (onValidate != null) nodeHash = Selection.activeObject.GetHashCode();
if (onValidate != null) EditorGUI.BeginChangeCheck();
}

BeginZoomed(position, zoom, topPadding);
Expand Down Expand Up @@ -383,12 +381,10 @@ private void DrawNodes() {
if (e.type != EventType.Layout && currentActivity == NodeActivity.DragGrid) Selection.objects = preSelection.ToArray();
EndZoomed(position, zoom, topPadding);

//If a change in hash is detected in the selected node, call OnValidate method.
//If a change in 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 (nodeHash != 0) {
if (onValidate != null && nodeHash != Selection.activeObject.GetHashCode()) onValidate.Invoke(Selection.activeObject, null);
}
if (onValidate != null && EditorGUI.EndChangeCheck()) onValidate.Invoke(Selection.activeObject, null);
}

private bool ShouldBeCulled(XNode.Node node) {
Expand Down
4 changes: 0 additions & 4 deletions Scripts/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,6 @@ public void ClearConnections() {
foreach (NodePort port in Ports) port.ClearConnections();
}

public override int GetHashCode() {
return JsonUtility.ToJson(this).GetHashCode();
}

#region Attributes
/// <summary> Mark a serializable field as an input port. You can access this through <see cref="GetInputPort(string)"/> </summary>
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
Expand Down

0 comments on commit 57d3a03

Please sign in to comment.