@@ -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 ) ;
0 commit comments