@@ -27,7 +27,7 @@ internal sealed class GameAnalyticsComponentInspector : ComponentTypeComponentIn
2727 // private readonly GUIContent m_AppKeyGUIContent = new GUIContent("AppKey");
2828 // private readonly GUIContent m_SecretKeyGUIContent = new GUIContent("SecretKey");
2929 private readonly GUIContent m_ComponentTypeGUIContent = new GUIContent ( "ComponentType" ) ;
30- private readonly GUIContent m_ParamsGUIContent = new GUIContent ( "Params " ) ;
30+ private readonly GUIContent m_SettingGUIContent = new GUIContent ( "Setting" , "游戏数据分析组件设置 ") ;
3131
3232 public override void OnInspectorGUI ( )
3333 {
@@ -73,26 +73,28 @@ private void DrawHeaderCallback(Rect rect)
7373
7474 private float ElementHeightCallback ( int index )
7575 {
76- SerializedProperty element = m_ReorderAbleList . serializedProperty . GetArrayElementAtIndex ( index ) ;
77- SerializedProperty paramProperty = element . FindPropertyRelative ( "Params " ) ;
78- if ( paramProperty . isExpanded )
76+ SerializedProperty element = m_ReorderAbleList . serializedProperty . GetArrayElementAtIndex ( index ) ;
77+ SerializedProperty componentTypeNameIndexProperty = element . FindPropertyRelative ( "ComponentTypeNameIndex " ) ;
78+ if ( componentTypeNameIndexProperty . intValue > 0 )
7979 {
80- int count = 2 ;
81- for ( int i = 0 ; i < paramProperty . arraySize ; i ++ )
80+ SerializedProperty settingProperty = element . FindPropertyRelative ( "Setting" ) ;
81+ if ( settingProperty . isExpanded )
8282 {
83- var propertyElement = paramProperty . GetArrayElementAtIndex ( i ) ;
84- if ( propertyElement . isExpanded )
83+ int count = 2 ;
84+ for ( int i = 0 ; i < settingProperty . arraySize ; i ++ )
8585 {
86- count += 2 ;
86+ var propertyElement = settingProperty . GetArrayElementAtIndex ( i ) ;
87+ if ( propertyElement . isExpanded )
88+ {
89+ count += 2 ;
90+ }
8791 }
88- }
8992
90- return ( EditorGUIUtility . singleLineHeight + 6 ) * ( paramProperty . arraySize + count ) + EditorGUIUtility . standardVerticalSpacing * 2 ;
91- }
92- else
93- {
94- return ( EditorGUIUtility . singleLineHeight + 6 ) * 2 + EditorGUIUtility . standardVerticalSpacing * 2 ;
93+ return ( EditorGUIUtility . singleLineHeight + 6 ) * ( settingProperty . arraySize + count ) + EditorGUIUtility . standardVerticalSpacing * 2 ;
94+ }
9595 }
96+
97+ return ( EditorGUIUtility . singleLineHeight + 6 ) * 2 + EditorGUIUtility . standardVerticalSpacing * 2 ;
9698 }
9799
98100 void DrawElementCallback ( Rect rect , int index , bool isActive , bool isFocused )
@@ -101,7 +103,7 @@ void DrawElementCallback(Rect rect, int index, bool isActive, bool isFocused)
101103 SerializedProperty element = m_ReorderAbleList . serializedProperty . GetArrayElementAtIndex ( index ) ;
102104 SerializedProperty componentTypeSerializedProperty = element . FindPropertyRelative ( "ComponentType" ) ;
103105 SerializedProperty componentTypeNameIndexSerializedProperty = element . FindPropertyRelative ( "ComponentTypeNameIndex" ) ;
104- SerializedProperty paramProperty = element . FindPropertyRelative ( "Params " ) ;
106+ SerializedProperty settingProperty = element . FindPropertyRelative ( "Setting " ) ;
105107
106108 // SerializedProperty appIdSerializedProperty = element.FindPropertyRelative("AppId");
107109 // SerializedProperty channelIdSerializedProperty = element.FindPropertyRelative("ChannelId");
@@ -131,8 +133,59 @@ void DrawElementCallback(Rect rect, int index, bool isActive, bool isFocused)
131133 rect . y += EditorGUIUtility . singleLineHeight + 6 ;
132134
133135 rect . x -= EditorGUIUtility . labelWidth - 14 ;
134- EditorGUI . PropertyField ( rect , paramProperty , true ) ;
135- rect . y += EditorGUIUtility . singleLineHeight * paramProperty . arraySize + 6 ;
136+
137+ EditorGUI . PropertyField ( rect , settingProperty , m_SettingGUIContent , true ) ;
138+ rect . y += EditorGUIUtility . singleLineHeight * settingProperty . arraySize + 6 ;
139+
140+ if ( componentTypeNameIndexSerializedProperty . intValue > 0 )
141+ {
142+ var type = Utility . Assembly . GetType ( componentTypeSerializedProperty . stringValue ) ;
143+ if ( type != null )
144+ {
145+ var types = type . Assembly . GetTypes ( ) ;
146+ foreach ( var typeImpl in types )
147+ {
148+ if ( typeImpl . BaseType != typeof ( BaseGameAnalyticsSetting ) )
149+ {
150+ continue ;
151+ }
152+
153+ var fieldInfos = typeImpl . GetFields ( ) ;
154+
155+ if ( settingProperty . arraySize < fieldInfos . Length )
156+ {
157+ for ( int i = settingProperty . arraySize ; i < fieldInfos . Length ; i ++ )
158+ {
159+ settingProperty . InsertArrayElementAtIndex ( i ) ;
160+ }
161+ }
162+
163+
164+ for ( var i = 0 ; i < fieldInfos . Length ; i ++ )
165+ {
166+ var fieldInfo = fieldInfos [ i ] ;
167+
168+ var serializedProperty = settingProperty . GetArrayElementAtIndex ( i ) ;
169+ GUI . enabled = false ;
170+ var keyProperty = serializedProperty . FindPropertyRelative ( "Key" ) ;
171+
172+ if ( keyProperty . stringValue != fieldInfo . Name )
173+ {
174+ keyProperty . stringValue = fieldInfo . Name ;
175+ }
176+
177+ GUI . enabled = true ;
178+ rect . y += EditorGUIUtility . singleLineHeight + 6 ;
179+ }
180+
181+ break ;
182+ }
183+ }
184+ }
185+ else
186+ {
187+ settingProperty . isExpanded = false ;
188+ }
136189 }
137190 EditorGUILayout . EndHorizontal ( ) ;
138191
0 commit comments