Skip to content

Commit d8fffe6

Browse files
committed
[增加]1. 增加编辑视图界面的高度自动适配
1 parent 6544d5b commit d8fffe6

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

Editor/Inspector/GameAnalyticsComponentInspector.cs

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ internal sealed class GameAnalyticsComponentInspector : ComponentTypeComponentIn
2020
private SerializedProperty m_GameAnalyticsComponentProviders;
2121

2222
private readonly GUIContent m_GameAnalyticsComponentProvidersGUIContent = new GUIContent("游戏数据分析组件列表,按序上报");
23+
2324
// private readonly GUIContent m_AppIdGUIContent = new GUIContent("AppId");
2425
// private readonly GUIContent m_ChannelIdGUIContent = new GUIContent("ChannelId");
2526
// private readonly GUIContent m_ChannelGUIContent = new GUIContent("Channel");
2627
// private readonly GUIContent m_AppKeyGUIContent = new GUIContent("AppKey");
2728
// private readonly GUIContent m_SecretKeyGUIContent = new GUIContent("SecretKey");
2829
private readonly GUIContent m_ComponentTypeGUIContent = new GUIContent("ComponentType");
29-
private readonly GUIContent m_ParamsGUIContent = new GUIContent("Params");
30+
private readonly GUIContent m_ParamsGUIContent = new GUIContent("Params");
3031

3132
public override void OnInspectorGUI()
3233
{
@@ -57,10 +58,12 @@ protected override void RefreshTypeNames()
5758
protected override void Enable()
5859
{
5960
m_GameAnalyticsComponentProviders = serializedObject.FindProperty("m_gameAnalyticsComponentProviders");
60-
m_ReorderAbleList = new ReorderableList(serializedObject, m_GameAnalyticsComponentProviders, true, true, true, true);
61-
m_ReorderAbleList.drawElementCallback = DrawElementCallback;
62-
m_ReorderAbleList.elementHeightCallback = ElementHeightCallback;
63-
m_ReorderAbleList.drawHeaderCallback = DrawHeaderCallback;
61+
m_ReorderAbleList = new ReorderableList(serializedObject, m_GameAnalyticsComponentProviders, true, true, true, true)
62+
{
63+
drawElementCallback = DrawElementCallback,
64+
elementHeightCallback = ElementHeightCallback,
65+
drawHeaderCallback = DrawHeaderCallback,
66+
};
6467
}
6568

6669
private void DrawHeaderCallback(Rect rect)
@@ -70,18 +73,35 @@ private void DrawHeaderCallback(Rect rect)
7073

7174
private float ElementHeightCallback(int index)
7275
{
73-
SerializedProperty element = m_ReorderAbleList.serializedProperty.GetArrayElementAtIndex(index);
76+
SerializedProperty element = m_ReorderAbleList.serializedProperty.GetArrayElementAtIndex(index);
7477
SerializedProperty paramProperty = element.FindPropertyRelative("Params");
75-
return (EditorGUIUtility.singleLineHeight + 6) * (paramProperty.arraySize + 2) + EditorGUIUtility.standardVerticalSpacing * 2;
78+
if (paramProperty.isExpanded)
79+
{
80+
int count = 2;
81+
for (int i = 0; i < paramProperty.arraySize; i++)
82+
{
83+
var propertyElement = paramProperty.GetArrayElementAtIndex(i);
84+
if (propertyElement.isExpanded)
85+
{
86+
count += 2;
87+
}
88+
}
89+
90+
return (EditorGUIUtility.singleLineHeight + 6) * (paramProperty.arraySize + count) + EditorGUIUtility.standardVerticalSpacing * 2;
91+
}
92+
else
93+
{
94+
return (EditorGUIUtility.singleLineHeight + 6) * 2 + EditorGUIUtility.standardVerticalSpacing * 2;
95+
}
7696
}
7797

7898
void DrawElementCallback(Rect rect, int index, bool isActive, bool isFocused)
7999
{
80100
EditorGUI.indentLevel++;
81-
SerializedProperty element = m_ReorderAbleList.serializedProperty.GetArrayElementAtIndex(index);
82-
SerializedProperty componentTypeSerializedProperty = element.FindPropertyRelative("ComponentType");
101+
SerializedProperty element = m_ReorderAbleList.serializedProperty.GetArrayElementAtIndex(index);
102+
SerializedProperty componentTypeSerializedProperty = element.FindPropertyRelative("ComponentType");
83103
SerializedProperty componentTypeNameIndexSerializedProperty = element.FindPropertyRelative("ComponentTypeNameIndex");
84-
SerializedProperty paramProperty = element.FindPropertyRelative("Params");
104+
SerializedProperty paramProperty = element.FindPropertyRelative("Params");
85105

86106
// SerializedProperty appIdSerializedProperty = element.FindPropertyRelative("AppId");
87107
// SerializedProperty channelIdSerializedProperty = element.FindPropertyRelative("ChannelId");
@@ -105,10 +125,10 @@ void DrawElementCallback(Rect rect, int index, bool isActive, bool isFocused)
105125
EditorGUILayout.BeginHorizontal();
106126
{
107127
EditorGUI.PrefixLabel(rect, m_ComponentTypeGUIContent);
108-
rect.x += EditorGUIUtility.labelWidth - 14;
109-
componentTypeNameIndexSerializedProperty.intValue = EditorGUI.Popup(new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight), componentTypeNameIndexSerializedProperty.intValue, m_ManagerTypeNames);
110-
componentTypeSerializedProperty.stringValue = m_ManagerTypeNames[componentTypeNameIndexSerializedProperty.intValue];
111-
rect.y += EditorGUIUtility.singleLineHeight + 6;
128+
rect.x += EditorGUIUtility.labelWidth - 14;
129+
componentTypeNameIndexSerializedProperty.intValue = EditorGUI.Popup(new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight), componentTypeNameIndexSerializedProperty.intValue, m_ManagerTypeNames);
130+
componentTypeSerializedProperty.stringValue = m_ManagerTypeNames[componentTypeNameIndexSerializedProperty.intValue];
131+
rect.y += EditorGUIUtility.singleLineHeight + 6;
112132

113133
rect.x -= EditorGUIUtility.labelWidth - 14;
114134
EditorGUI.PropertyField(rect, paramProperty, true);

0 commit comments

Comments
 (0)