Skip to content

Commit

Permalink
Fix disabling invoke button when invoke cannot be called
Browse files Browse the repository at this point in the history
- Follow up fix for bug exposed by Lyuma's fix null pointer exception on the EventTrigger component where the invoke button was supposed to be disabled, but wasn't because the button draw was happening outside the disabled group.
  • Loading branch information
MerlinVR committed Nov 11, 2019
1 parent 2b89d98 commit ada1021
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions EasyEventEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -810,16 +810,16 @@ void DrawInvokeField(Rect position, float headerStartOffset)
GUIStyle textStyle = EditorStyles.miniLabel;
textStyle.alignment = TextAnchor.MiddleLeft;

bool executeInvoke = GUI.Button(buttonPos, "", EditorStyles.miniButton);
GUI.Label(textPos, "Invoke"/* + " (" + string.Join(", ", eventInvokeArgs.Select(e => e.Name).ToArray()) + ")"*/, textStyle);

MethodInfo invokeMethod = InvokeFindMethod("Invoke", dummyEvent, dummyEvent, PersistentListenerMode.EventDefined);
FieldInfo serializedField = currentProperty.serializedObject.targetObject.GetType().GetField(currentProperty.name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);

object[] invokeTargets = currentProperty.serializedObject.targetObjects.Select(target => target == null || serializedField == null ? null : serializedField.GetValue(target)).Where(f => f != null).ToArray();

EditorGUI.BeginDisabledGroup(invokeTargets.Length == 0 || invokeMethod == null);

bool executeInvoke = GUI.Button(buttonPos, "", EditorStyles.miniButton);
GUI.Label(textPos, "Invoke"/* + " (" + string.Join(", ", eventInvokeArgs.Select(e => e.Name).ToArray()) + ")"*/, textStyle);

if (eventInvokeArgs.Length > 0)
{
System.Type argType = eventInvokeArgs[0];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.merlin.easyeventeditor",
"displayName": "Easy Event Editor",
"version": "1.0.0",
"version": "1.0.1",
"unity": "2017.4",
"description": "Drop in replacement for the default Unity event editor drawer that allows listener reordering and a few other things",
"keywords": ["Event", "Editor", "Delegate"],
Expand Down

0 comments on commit ada1021

Please sign in to comment.