@@ -350,7 +350,7 @@ public static EEESettings GetEditorSettings()
350350 {
351351 overrideEventDrawer = EditorPrefs . GetBool ( eeeOverrideEventDrawerKey , true ) ,
352352 showPrivateMembers = EditorPrefs . GetBool ( eeeShowPrivateMembersKey , true ) ,
353- showInvokeField = EditorPrefs . GetBool ( eeeShowInvokeFieldKey , true ) ,
353+ showInvokeField = EditorPrefs . GetBool ( eeeShowInvokeFieldKey , false ) ,
354354 displayArgumentType = EditorPrefs . GetBool ( eeeDisplayArgumentTypeKey , true ) ,
355355 groupSameComponentType = EditorPrefs . GetBool ( eeeGroupSameComponentTypeKey , false ) ,
356356 useHotkeys = EditorPrefs . GetBool ( eeeUseHotkeys , true ) ,
@@ -507,6 +507,68 @@ public FunctionData(SerializedProperty listener, Object target = null, MethodInf
507507 MethodInfo cachedFindMethodInfo = null ;
508508 static EasyEventEditorHandler . EEESettings cachedSettings ;
509509
510+ #if UNITY_2018_4_OR_NEWER
511+ private static UnityEventBase GetDummyEventStep ( string propertyPath , System . Type propertyType , BindingFlags bindingFlags )
512+ {
513+ UnityEventBase dummyEvent = null ;
514+
515+ while ( propertyPath . Length > 0 )
516+ {
517+ if ( propertyPath . StartsWith ( "." ) )
518+ propertyPath = propertyPath . Substring ( 1 ) ;
519+
520+ string [ ] splitPath = propertyPath . Split ( new char [ ] { '.' } , 2 ) ;
521+
522+ FieldInfo newField = propertyType . GetField ( splitPath [ 0 ] , bindingFlags ) ;
523+
524+ if ( newField == null )
525+ break ;
526+
527+ propertyType = newField . FieldType ;
528+ if ( propertyType . IsArray )
529+ {
530+ propertyType = propertyType . GetElementType ( ) ;
531+ }
532+ else if ( propertyType . IsGenericType && propertyType . GetGenericTypeDefinition ( ) == typeof ( List < > ) )
533+ {
534+ propertyType = propertyType . GetGenericArguments ( ) [ 0 ] ;
535+ }
536+
537+ if ( splitPath . Length == 1 )
538+ break ;
539+
540+ propertyPath = splitPath [ 1 ] ;
541+ if ( propertyPath . StartsWith ( "Array.data[" ) )
542+ propertyPath = propertyPath . Split ( new char [ ] { ']' } , 2 ) [ 1 ] ;
543+ }
544+
545+ if ( propertyType . IsSubclassOf ( typeof ( UnityEventBase ) ) )
546+ dummyEvent = System . Activator . CreateInstance ( propertyType ) as UnityEventBase ;
547+
548+ return dummyEvent ;
549+ }
550+
551+ private static UnityEventBase GetDummyEvent ( SerializedProperty property )
552+ {
553+ Object targetObject = property . serializedObject . targetObject ;
554+ if ( targetObject == null )
555+ return new UnityEvent ( ) ;
556+
557+ UnityEventBase dummyEvent = null ;
558+ System . Type targetType = targetObject . GetType ( ) ;
559+ BindingFlags bindingFlags = BindingFlags . Instance | BindingFlags . Public | BindingFlags . NonPublic ;
560+
561+ do
562+ {
563+ dummyEvent = GetDummyEventStep ( property . propertyPath , targetType , bindingFlags ) ;
564+ bindingFlags = BindingFlags . Instance | BindingFlags . NonPublic ;
565+ targetType = targetType . BaseType ;
566+ } while ( dummyEvent == null && targetType != null ) ;
567+
568+ return dummyEvent ?? new UnityEvent ( ) ;
569+ }
570+ #endif
571+
510572 private void PrepareState ( SerializedProperty propertyForState )
511573 {
512574 DrawerState state ;
@@ -540,51 +602,7 @@ private void PrepareState(SerializedProperty propertyForState)
540602
541603 // Setup dummy event
542604#if UNITY_2018_4_OR_NEWER
543- Object targetObject = currentProperty . serializedObject . targetObject ;
544- if ( targetObject == null )
545- {
546- dummyEvent = new UnityEvent ( ) ;
547- }
548- else
549- {
550- string propertyPath = currentProperty . propertyPath ;
551- System . Type propertyType = targetObject . GetType ( ) ;
552-
553- while ( propertyPath . Length > 0 )
554- {
555- if ( propertyPath . StartsWith ( "." ) )
556- propertyPath = propertyPath . Substring ( 1 ) ;
557-
558- string [ ] splitPath = propertyPath . Split ( new char [ ] { '.' } , 2 ) ;
559-
560- FieldInfo newField = propertyType . GetField ( splitPath [ 0 ] , BindingFlags . Instance | BindingFlags . NonPublic | BindingFlags . Public ) ;
561-
562- if ( newField == null )
563- break ;
564-
565- propertyType = newField . FieldType ;
566- if ( propertyType . IsArray )
567- {
568- propertyType = propertyType . GetElementType ( ) ;
569- }
570- else if ( propertyType . IsGenericType && typeof ( List < > ) . IsAssignableFrom ( propertyType ) )
571- {
572- propertyType = propertyType . GetGenericArguments ( ) [ 0 ] ;
573- }
574-
575- if ( splitPath . Length == 1 )
576- break ;
577-
578- propertyPath = splitPath [ 1 ] ;
579- if ( propertyPath . StartsWith ( "Array.data[" ) )
580- propertyPath = propertyPath . Split ( new char [ ] { ']' } , 2 ) [ 1 ] ;
581- }
582-
583- if ( propertyType . IsSubclassOf ( typeof ( UnityEventBase ) ) )
584- dummyEvent = System . Activator . CreateInstance ( propertyType ) as UnityEventBase ;
585- else
586- dummyEvent = new UnityEvent ( ) ;
587- }
605+ dummyEvent = GetDummyEvent ( propertyForState ) ;
588606#else
589607 string eventTypeName = currentProperty . FindPropertyRelative ( "m_TypeName" ) . stringValue ;
590608 System . Type eventType = EasyEventEditorHandler . FindTypeInAllAssemblies ( eventTypeName ) ;
@@ -895,10 +913,15 @@ MethodInfo InvokeFindMethod(string functionName, object targetObject, UnityEvent
895913 if ( findMethod == null )
896914 {
897915 // Rather not reinvent the wheel considering this function calls different functions depending on the number of args the event has...
916+ // Unity 2020.1 changed the function signature for the FindMethod method (the second parameter is a Type instead of an object)
898917 findMethod = eventObject . GetType ( ) . GetMethod ( "FindMethod" , BindingFlags . NonPublic | BindingFlags . Instance , null ,
899918 new System . Type [ ] {
900919 typeof ( string ) ,
920+ #if UNITY_2020_1_OR_NEWER
921+ typeof ( System . Type ) ,
922+ #else
901923 typeof ( object ) ,
924+ #endif
902925 typeof( PersistentListenerMode ) ,
903926 typeof ( System . Type )
904927 } ,
@@ -913,7 +936,11 @@ MethodInfo InvokeFindMethod(string functionName, object targetObject, UnityEvent
913936 return null ;
914937 }
915938
916- return findMethod . Invoke ( eventObject , new object [ ] { functionName , targetObject , listenerMode , argType } ) as MethodInfo ;
939+ #if UNITY_2020_1_OR_NEWER
940+ return findMethod . Invoke ( eventObject , new object [ ] { functionName , targetObject ? . GetType ( ) , listenerMode , argType } ) as MethodInfo ;
941+ #else
942+ return findMethod . Invoke ( eventObject , new object [ ] { functionName , targetObject , listenerMode , argType } ) as MethodInfo ;
943+ #endif
917944 }
918945
919946 System . Type [ ] GetEventParams ( UnityEventBase eventIn )
@@ -951,9 +978,13 @@ string GetFunctionArgStr(string functionName, object targetObject, PersistentLis
951978 void DrawHeaderCallback ( Rect headerRect )
952979 {
953980 // We need to know where to position the invoke field based on the length of the title in the UI
954- GUIContent headerTitle = new GUIContent ( string . IsNullOrEmpty ( currentLabelText ) ? "Event" : currentLabelText + " " + GetEventParamsStr ( dummyEvent ) ) ;
981+ GUIContent headerTitle = new GUIContent ( string . IsNullOrEmpty ( currentLabelText ) ? "Event" : currentLabelText + " " + GetEventParamsStr ( dummyEvent ) ) ;
982+ float headerStartOffset = EditorStyles . label . CalcSize ( headerTitle ) . x ;
983+
955984 GUI . Label ( headerRect , headerTitle ) ;
956985
986+ if ( cachedSettings . showInvokeField )
987+ DrawInvokeField ( headerRect , headerStartOffset ) ;
957988 }
958989
959990 Rect [ ] GetElementRects ( Rect rect )
@@ -1577,4 +1608,4 @@ void RemoveCallback(ReorderableList list)
15771608
15781609} // namespace Merlin
15791610
1580- #endif
1611+ #endif
0 commit comments