Skip to content

Commit ecd7d3b

Browse files
committed
[修改]1. 修改参数为自动化生成处理
1 parent 62ca0d3 commit ecd7d3b

File tree

4 files changed

+92
-23
lines changed

4 files changed

+92
-23
lines changed

Editor/Inspector/GameAnalyticsComponentInspector.cs

Lines changed: 71 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Runtime/GameAnalytics/GameAnalyticsComponent.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ namespace GameFrameX.GameAnalytics.Runtime
1313
[AddComponentMenu("Game Framework/GameAnalytics")]
1414
public sealed class GameAnalyticsComponent : GameFrameworkComponent
1515
{
16-
private bool m_IsInit = false;
16+
private bool m_IsInit = false;
1717
[SerializeField] private List<GameAnalyticsComponentProvider> m_gameAnalyticsComponentProviders = new List<GameAnalyticsComponentProvider>();
18-
private List<IGameAnalyticsManager> m_GameAnalyticsManager;
18+
private List<IGameAnalyticsManager> m_GameAnalyticsManager;
1919

2020
protected override void Awake()
2121
{
2222
m_GameAnalyticsManager = new List<IGameAnalyticsManager>();
23-
IsAutoRegister = false;
23+
IsAutoRegister = false;
2424
base.Awake();
2525
}
2626

@@ -53,7 +53,7 @@ public void Init()
5353
if (Activator.CreateInstance(gameAnalyticsComponentType) is IGameAnalyticsManager gameAnalyticsManager)
5454
{
5555
Dictionary<string, string> args = new Dictionary<string, string>();
56-
foreach (var param in gameAnalyticsComponentProvider.Params)
56+
foreach (var param in gameAnalyticsComponentProvider.Setting)
5757
{
5858
args[param.Key] = param.Value;
5959
}
@@ -272,7 +272,7 @@ public class GameAnalyticsComponentProvider
272272
/// <summary>
273273
/// 参数
274274
/// </summary>
275-
public List<GameAnalyticsComponentParamKV> Params = new List<GameAnalyticsComponentParamKV>();
275+
public List<GameAnalyticsComponentParamKV> Setting = new List<GameAnalyticsComponentParamKV>();
276276
}
277277

278278
[Serializable]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
3+
namespace GameFrameX.GameAnalytics.Runtime
4+
{
5+
public interface IGameAnalyticsSetting
6+
{
7+
}
8+
9+
[Serializable]
10+
public class BaseGameAnalyticsSetting : IGameAnalyticsSetting
11+
{
12+
}
13+
}

Runtime/GameAnalytics/IGameAnalyticsSetting.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)