11using UnityEditor ;
22using System ;
3+ using System . Linq ;
34using UnityEngine ;
45
56namespace Editor . EditorUI
@@ -9,10 +10,15 @@ public abstract class BaseEventListenerCustomInspector : UnityEditor.Editor
910 protected const string EventSOVariableName = "_baseEvent" ;
1011
1112 protected SerializedProperty _baseEventProp ;
13+ protected Type [ ] _tArgs ;
14+ protected string _types ;
15+
16+ protected abstract bool ValidateEventType ( System . Object obj ) ;
1217
1318 protected virtual void OnEnable ( )
1419 {
1520 _baseEventProp = serializedObject . FindProperty ( EventSOVariableName ) ;
21+ _types = string . Empty ;
1622 }
1723
1824 protected void DrawEventInspector ( string label , string tooltip , Func < UnityEngine . Object , bool > validationLogic )
@@ -38,7 +44,45 @@ protected void DrawEventInspector(string label, string tooltip, Func<UnityEngine
3844 DrawPropertiesExcluding ( serializedObject , "m_Script" , EventSOVariableName ) ;
3945 serializedObject . ApplyModifiedProperties ( ) ;
4046 }
47+
48+ protected void GetArgTypes ( Type type )
49+ {
50+ if ( type != null )
51+ {
52+ var allArgs = type . GetGenericArguments ( ) ;
53+
54+ //Skipping the first one. Not sure if this is always applicable
55+ _tArgs = new Type [ allArgs . Length - 1 ] ;
56+ for ( int i = 1 ; i < allArgs . Length ; i ++ )
57+ {
58+ _tArgs [ i - 1 ] = allArgs [ i ] ;
59+ _types += _tArgs [ i - 1 ] . Name ;
60+ if ( i < allArgs . Length - 1 )
61+ {
62+ _types += ", " ;
63+ }
64+ }
65+ }
66+ }
67+
68+ protected bool ValidateArgCountAndTypes ( Type @interface )
69+ {
70+ var args = @interface . GetGenericArguments ( ) ;
71+
72+ if ( args . Length == _tArgs . Length )
73+ {
74+ for ( int i = 0 ; i < args . Length ; i ++ )
75+ {
76+ if ( args [ i ] != _tArgs [ i ] )
77+ {
78+ return false ;
79+ }
80+ }
81+
82+ return true ;
83+ }
4184
42- protected abstract bool ValidationLogic ( System . Object obj ) ;
85+ return false ;
86+ }
4387 }
4488}
0 commit comments