From 57d3a03a91d38f722d16c988e72d5cd5dffe489c Mon Sep 17 00:00:00 2001 From: Thor Brigsted Date: Sat, 16 Feb 2019 12:21:21 +0100 Subject: [PATCH] Removed GetHashCode override. This should improve performance, but has previously caused a slew of bugs. Bugtest thoroughly before merging --- Scripts/Editor/NodeEditorGUI.cs | 10 +++------- Scripts/Node.cs | 4 ---- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/Scripts/Editor/NodeEditorGUI.cs b/Scripts/Editor/NodeEditorGUI.cs index 9f48f0e..e22a0b4 100644 --- a/Scripts/Editor/NodeEditorGUI.cs +++ b/Scripts/Editor/NodeEditorGUI.cs @@ -241,12 +241,10 @@ namespace XNodeEditor { selectionCache = new List(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); @@ -383,12 +381,10 @@ namespace XNodeEditor { 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) { diff --git a/Scripts/Node.cs b/Scripts/Node.cs index 43d716e..da04d86 100644 --- a/Scripts/Node.cs +++ b/Scripts/Node.cs @@ -205,10 +205,6 @@ namespace XNode { foreach (NodePort port in Ports) port.ClearConnections(); } - public override int GetHashCode() { - return JsonUtility.ToJson(this).GetHashCode(); - } - #region Attributes /// Mark a serializable field as an input port. You can access this through [AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]