1
0
mirror of https://github.com/Siccity/xNode.git synced 2026-02-04 22:34:54 +08:00

Fixed #107 - OnValidate

OnValidate is now called on rename as well.
Removed outdated OnValidate fix. It probably never worked anyway.
This commit is contained in:
Thor Brigsted 2019-07-01 09:54:51 +02:00
parent d0e1cd5d66
commit 8e0bd964ad
3 changed files with 11 additions and 11 deletions

View File

@ -282,12 +282,6 @@ namespace XNodeEditor {
selectionCache = new List<UnityEngine.Object>(Selection.objects); selectionCache = new List<UnityEngine.Object>(Selection.objects);
} }
System.Reflection.MethodInfo onValidate = null;
if (Selection.activeObject != null && Selection.activeObject is XNode.Node) {
onValidate = Selection.activeObject.GetType().GetMethod("OnValidate");
if (onValidate != null) EditorGUI.BeginChangeCheck();
}
BeginZoomed(); BeginZoomed();
Vector2 mousePos = Event.current.mousePosition; Vector2 mousePos = Event.current.mousePosition;
@ -420,11 +414,6 @@ namespace XNodeEditor {
if (e.type != EventType.Layout && currentActivity == NodeActivity.DragGrid) Selection.objects = preSelection.ToArray(); if (e.type != EventType.Layout && currentActivity == NodeActivity.DragGrid) Selection.objects = preSelection.ToArray();
EndZoomed(); EndZoomed();
//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 (onValidate != null && EditorGUI.EndChangeCheck()) onValidate.Invoke(Selection.activeObject, null);
} }
private bool ShouldBeCulled(XNode.Node node) { private bool ShouldBeCulled(XNode.Node node) {

View File

@ -103,6 +103,15 @@ namespace XNodeEditor {
} }
} }
/// <summary> Call OnValidate on target </summary>
public static void TriggerOnValidate(UnityEngine.Object target) {
System.Reflection.MethodInfo onValidate = null;
if (target != null) {
onValidate = target.GetType().GetMethod("OnValidate", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
if (onValidate != null) onValidate.Invoke(target, null);
}
}
public static KeyValuePair<ContextMenu, MethodInfo>[] GetContextMenuMethods(object obj) { public static KeyValuePair<ContextMenu, MethodInfo>[] GetContextMenuMethods(object obj) {
Type type = obj.GetType(); Type type = obj.GetType();
MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

View File

@ -51,6 +51,7 @@ namespace XNodeEditor {
target.name = NodeEditorUtilities.NodeDefaultName(target.GetType()); target.name = NodeEditorUtilities.NodeDefaultName(target.GetType());
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target)); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target));
Close(); Close();
NodeEditorWindow.TriggerOnValidate(target);
} }
} }
// Rename asset to input text // Rename asset to input text
@ -59,6 +60,7 @@ namespace XNodeEditor {
target.name = input; target.name = input;
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target)); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target));
Close(); Close();
NodeEditorWindow.TriggerOnValidate(target);
} }
} }
} }