@@ -28,7 +28,7 @@ internal sealed class GameAnalyticsComponentInspector : ComponentTypeComponentIn
2828 // private readonly GUIContent m_AppKeyGUIContent = new GUIContent("AppKey");
2929 // private readonly GUIContent m_SecretKeyGUIContent = new GUIContent("SecretKey");
3030 private readonly GUIContent m_ComponentTypeGUIContent = new GUIContent ( "ComponentType" ) ;
31- private readonly GUIContent m_SettingGUIContent = new GUIContent ( "Setting" , "游戏数据分析组件设置" ) ;
31+ private readonly GUIContent m_SettingGUIContent = new GUIContent ( "Setting" , "游戏数据分析组件设置" ) ;
3232
3333 public override void OnInspectorGUI ( )
3434 {
@@ -61,9 +61,9 @@ protected override void Enable()
6161 m_GameAnalyticsComponentProviders = serializedObject . FindProperty ( "m_gameAnalyticsComponentProviders" ) ;
6262 m_ReorderAbleList = new ReorderableList ( serializedObject , m_GameAnalyticsComponentProviders , true , true , true , true )
6363 {
64- drawElementCallback = DrawElementCallback ,
64+ drawElementCallback = DrawElementCallback ,
6565 elementHeightCallback = ElementHeightCallback ,
66- drawHeaderCallback = DrawHeaderCallback ,
66+ drawHeaderCallback = DrawHeaderCallback ,
6767 } ;
6868 }
6969
@@ -74,9 +74,9 @@ private void DrawHeaderCallback(Rect rect)
7474
7575 private float ElementHeightCallback ( int index )
7676 {
77- SerializedProperty element = m_ReorderAbleList . serializedProperty . GetArrayElementAtIndex ( index ) ;
77+ SerializedProperty element = m_ReorderAbleList . serializedProperty . GetArrayElementAtIndex ( index ) ;
7878 SerializedProperty componentTypeNameIndexProperty = element . FindPropertyRelative ( "ComponentTypeNameIndex" ) ;
79- if ( componentTypeNameIndexProperty . intValue > 0 )
79+ if ( componentTypeNameIndexProperty . intValue > 0 && componentTypeNameIndexProperty . intValue < m_ManagerTypeNames . Length )
8080 {
8181 SerializedProperty settingProperty = element . FindPropertyRelative ( "Setting" ) ;
8282 if ( settingProperty . isExpanded )
@@ -101,10 +101,10 @@ private float ElementHeightCallback(int index)
101101 void DrawElementCallback ( Rect rect , int index , bool isActive , bool isFocused )
102102 {
103103 EditorGUI . indentLevel ++ ;
104- SerializedProperty element = m_ReorderAbleList . serializedProperty . GetArrayElementAtIndex ( index ) ;
105- SerializedProperty componentTypeSerializedProperty = element . FindPropertyRelative ( "ComponentType" ) ;
104+ SerializedProperty element = m_ReorderAbleList . serializedProperty . GetArrayElementAtIndex ( index ) ;
105+ SerializedProperty componentTypeSerializedProperty = element . FindPropertyRelative ( "ComponentType" ) ;
106106 SerializedProperty componentTypeNameIndexSerializedProperty = element . FindPropertyRelative ( "ComponentTypeNameIndex" ) ;
107- SerializedProperty settingProperty = element . FindPropertyRelative ( "Setting" ) ;
107+ SerializedProperty settingProperty = element . FindPropertyRelative ( "Setting" ) ;
108108
109109 // SerializedProperty appIdSerializedProperty = element.FindPropertyRelative("AppId");
110110 // SerializedProperty channelIdSerializedProperty = element.FindPropertyRelative("ChannelId");
@@ -127,61 +127,68 @@ void DrawElementCallback(Rect rect, int index, bool isActive, bool isFocused)
127127
128128 EditorGUILayout . BeginHorizontal ( ) ;
129129 {
130- EditorGUI . PrefixLabel ( rect , m_ComponentTypeGUIContent ) ;
131- rect . x += EditorGUIUtility . labelWidth - 14 ;
132- componentTypeNameIndexSerializedProperty . intValue = EditorGUI . Popup ( new Rect ( rect . x , rect . y , rect . width , EditorGUIUtility . singleLineHeight ) , componentTypeNameIndexSerializedProperty . intValue , m_ManagerTypeNames ) ;
133- componentTypeSerializedProperty . stringValue = m_ManagerTypeNames [ componentTypeNameIndexSerializedProperty . intValue ] ;
134- rect . y += EditorGUIUtility . singleLineHeight + 6 ;
130+ if ( m_ManagerTypeNames . Length > 0 && m_ManagerTypeNames . Length > componentTypeNameIndexSerializedProperty . intValue )
131+ {
132+ EditorGUI . PrefixLabel ( rect , m_ComponentTypeGUIContent ) ;
133+ rect . x += EditorGUIUtility . labelWidth - 14 ;
134+ componentTypeNameIndexSerializedProperty . intValue = EditorGUI . Popup ( new Rect ( rect . x , rect . y , rect . width , EditorGUIUtility . singleLineHeight ) , componentTypeNameIndexSerializedProperty . intValue , m_ManagerTypeNames ) ;
135+ componentTypeSerializedProperty . stringValue = m_ManagerTypeNames [ componentTypeNameIndexSerializedProperty . intValue ] ;
136+ rect . y += EditorGUIUtility . singleLineHeight + 6 ;
135137
136- rect . x -= EditorGUIUtility . labelWidth - 14 ;
138+ rect . x -= EditorGUIUtility . labelWidth - 14 ;
137139
138- EditorGUI . PropertyField ( rect , settingProperty , m_SettingGUIContent , true ) ;
139- rect . y += EditorGUIUtility . singleLineHeight * settingProperty . arraySize + 6 ;
140+ EditorGUI . PropertyField ( rect , settingProperty , m_SettingGUIContent , true ) ;
141+ rect . y += EditorGUIUtility . singleLineHeight * settingProperty . arraySize + 6 ;
140142
141- if ( componentTypeNameIndexSerializedProperty . intValue > 0 )
142- {
143- var type = Utility . Assembly . GetType ( componentTypeSerializedProperty . stringValue ) ;
144- if ( type != null )
143+ if ( componentTypeNameIndexSerializedProperty . intValue > 0 )
145144 {
146- var types = type . Assembly . GetTypes ( ) ;
147- foreach ( var typeImpl in types )
145+ var type = Utility . Assembly . GetType ( componentTypeSerializedProperty . stringValue ) ;
146+ if ( type != null )
148147 {
149- if ( typeImpl . BaseType != typeof ( BaseGameAnalyticsSetting ) )
148+ var types = type . Assembly . GetTypes ( ) ;
149+ foreach ( var typeImpl in types )
150150 {
151- continue ;
152- }
151+ if ( typeImpl . BaseType != typeof ( BaseGameAnalyticsSetting ) )
152+ {
153+ continue ;
154+ }
153155
154- var fieldInfos = typeImpl . GetFields ( ) ;
156+ var fieldInfos = typeImpl . GetFields ( ) ;
155157
156- if ( settingProperty . arraySize < fieldInfos . Length )
157- {
158- for ( int i = settingProperty . arraySize ; i < fieldInfos . Length ; i ++ )
158+ if ( settingProperty . arraySize < fieldInfos . Length )
159159 {
160- settingProperty . InsertArrayElementAtIndex ( i ) ;
160+ for ( int i = settingProperty . arraySize ; i < fieldInfos . Length ; i ++ )
161+ {
162+ settingProperty . InsertArrayElementAtIndex ( i ) ;
163+ }
161164 }
162- }
163165
164166
165- for ( var i = 0 ; i < fieldInfos . Length ; i ++ )
166- {
167- var fieldInfo = fieldInfos [ i ] ;
167+ for ( var i = 0 ; i < fieldInfos . Length ; i ++ )
168+ {
169+ var fieldInfo = fieldInfos [ i ] ;
168170
169- var serializedProperty = settingProperty . GetArrayElementAtIndex ( i ) ;
170- GUI . enabled = false ;
171- var keyProperty = serializedProperty . FindPropertyRelative ( "Key" ) ;
171+ var serializedProperty = settingProperty . GetArrayElementAtIndex ( i ) ;
172+ GUI . enabled = false ;
173+ var keyProperty = serializedProperty . FindPropertyRelative ( "Key" ) ;
172174
173- if ( keyProperty . stringValue != fieldInfo . Name )
174- {
175- keyProperty . stringValue = fieldInfo . Name ;
175+ if ( keyProperty . stringValue != fieldInfo . Name )
176+ {
177+ keyProperty . stringValue = fieldInfo . Name ;
178+ }
179+
180+ GUI . enabled = true ;
181+ rect . y += EditorGUIUtility . singleLineHeight + 6 ;
176182 }
177183
178- GUI . enabled = true ;
179- rect . y += EditorGUIUtility . singleLineHeight + 6 ;
184+ break ;
180185 }
181-
182- break ;
183186 }
184187 }
188+ else
189+ {
190+ settingProperty . isExpanded = false ;
191+ }
185192 }
186193 else
187194 {
0 commit comments