diff --git a/Scripts/Editor/NodeEditorReflection.cs b/Scripts/Editor/NodeEditorReflection.cs index 18b72fa..3b66f1d 100644 --- a/Scripts/Editor/NodeEditorReflection.cs +++ b/Scripts/Editor/NodeEditorReflection.cs @@ -86,9 +86,24 @@ namespace XNodeEditor { KeyValuePair[] items = GetContextMenuMethods(obj); if (items.Length != 0) { contextMenu.AddSeparator(""); + List invalidatedEntries = new List(); + foreach (var checkValidate in items) { + if (checkValidate.Key.validate && !(bool) checkValidate.Value.Invoke(obj, null)) + { + invalidatedEntries.Add(checkValidate.Key); + } + } for (int i = 0; i < items.Length; i++) { KeyValuePair kvp = items[i]; - contextMenu.AddItem(new GUIContent(kvp.Key.menuItem), false, () => kvp.Value.Invoke(obj, null)); + if (invalidatedEntries.Contains(kvp.Key)) + { + contextMenu.AddDisabledItem(new GUIContent(kvp.Key.menuItem)); + } + else + { + contextMenu.AddItem(new GUIContent(kvp.Key.menuItem), false, () => kvp.Value.Invoke(obj, null)); + + } } } }