Skip to content

Commit 4b920ff

Browse files
committed
[增加] 主流平台的广告位ID的独立设置。并自动切换
1 parent 2342df0 commit 4b920ff

File tree

2 files changed

+62
-15
lines changed

2 files changed

+62
-15
lines changed

Editor/Inspector/AdvertisementComponentInspector.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,17 @@ namespace GameFrameX.Advertisement.Editor
1515
[CustomEditor(typeof(AdvertisementComponent))]
1616
internal sealed class AdvertisementComponentInspector : ComponentTypeComponentInspector
1717
{
18-
private SerializedProperty m_adUnitId = null;
19-
private GUIContent m_adUnitIdGUIContent = new GUIContent("广告位ID");
18+
private SerializedProperty m_adUnitIdAndroid = null;
19+
private SerializedProperty m_adUnitIdiOS = null;
20+
private SerializedProperty m_adUnitIdWebGL = null;
21+
private SerializedProperty m_adUnitIdWebGLWeChat = null;
22+
private SerializedProperty m_adUnitIdWebGLDouYin = null;
23+
private GUIContent m_adUnitIdAndroidGUIContent = new GUIContent("Android 广告位ID");
24+
private GUIContent m_adUnitIdiOSGUIContent = new GUIContent("IOS 广告位ID");
25+
private GUIContent m_adUnitIdWebGLGUIContent = new GUIContent("WebGL 广告位ID");
26+
private GUIContent m_adUnitIdWebGLWeChatGUIContent = new GUIContent("WebGL 微信 广告位ID");
27+
private GUIContent m_adUnitIdWebGLDouYinGUIContent = new GUIContent("WebGL 抖音 广告位ID");
2028

21-
2229
public override void OnInspectorGUI()
2330
{
2431
base.OnInspectorGUI();
@@ -27,23 +34,31 @@ public override void OnInspectorGUI()
2734

2835
EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode & Application.isPlaying);
2936
{
30-
EditorGUILayout.PropertyField(m_adUnitId, m_adUnitIdGUIContent);
37+
EditorGUILayout.PropertyField(m_adUnitIdAndroid, m_adUnitIdAndroidGUIContent);
38+
EditorGUILayout.PropertyField(m_adUnitIdiOS, m_adUnitIdiOSGUIContent);
39+
EditorGUILayout.PropertyField(m_adUnitIdWebGL, m_adUnitIdWebGLGUIContent);
40+
EditorGUILayout.PropertyField(m_adUnitIdWebGLWeChat, m_adUnitIdWebGLWeChatGUIContent);
41+
EditorGUILayout.PropertyField(m_adUnitIdWebGLDouYin, m_adUnitIdWebGLDouYinGUIContent);
3142
}
3243
EditorGUI.EndDisabledGroup();
3344

3445
serializedObject.ApplyModifiedProperties();
3546

3647
Repaint();
3748
}
38-
49+
3950
protected override void RefreshTypeNames()
4051
{
4152
RefreshComponentTypeNames(typeof(IAdvertisementManager));
4253
}
4354

4455
protected override void Enable()
4556
{
46-
m_adUnitId = serializedObject.FindProperty("m_adUnitId");
57+
m_adUnitIdAndroid = serializedObject.FindProperty("m_adUnitIdAndroid");
58+
m_adUnitIdiOS = serializedObject.FindProperty("m_adUnitIdiOS");
59+
m_adUnitIdWebGL = serializedObject.FindProperty("m_adUnitIdWebGL");
60+
m_adUnitIdWebGLWeChat = serializedObject.FindProperty("m_adUnitIdWebGLWeChat");
61+
m_adUnitIdWebGLDouYin = serializedObject.FindProperty("m_adUnitIdWebGLDouYin");
4762
}
4863
}
4964
}

Runtime/Advertisement/AdvertisementComponent.cs

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,45 @@
11
using System;
2-
using GameFrameX.Event.Runtime;
32
using GameFrameX.Runtime;
43
using UnityEngine;
54

65
namespace GameFrameX.Advertisement.Runtime
76
{
87
/// <summary>
9-
/// Mono 组件
8+
/// Advertisement 组件
109
/// </summary>
1110
[DisallowMultipleComponent]
1211
[AddComponentMenu("Game Framework/Advertisement")]
1312
public class AdvertisementComponent : GameFrameworkComponent
1413
{
1514
/// <summary>
16-
/// 广告位ID
15+
/// 广告位ID Android
16+
/// </summary>
17+
[SerializeField] private string m_adUnitIdAndroid = string.Empty;
18+
19+
/// <summary>
20+
/// 广告位ID iOS
21+
/// </summary>
22+
[SerializeField] private string m_adUnitIdiOS = string.Empty;
23+
24+
/// <summary>
25+
/// 广告位ID WebGL
26+
/// </summary>
27+
[SerializeField] private string m_adUnitIdWebGL = string.Empty;
28+
29+
/// <summary>
30+
/// 广告位ID WebGL
31+
/// </summary>
32+
[SerializeField] private string m_adUnitIdWebGLWeChat = string.Empty;
33+
34+
/// <summary>
35+
/// 广告位ID WebGL
1736
/// </summary>
18-
[SerializeField] private string m_adUnitId = string.Empty;
37+
[SerializeField] private string m_adUnitIdWebGLDouYin = string.Empty;
1938

2039
/// <summary>
2140
/// 广告位ID
2241
/// </summary>
23-
public string AdUnitId
24-
{
25-
get => m_adUnitId;
26-
set => m_adUnitId = value;
27-
}
42+
public string AdUnitId { get; private set; }
2843

2944
private IAdvertisementManager _advertisementManager;
3045

@@ -39,6 +54,23 @@ protected override void Awake()
3954
Log.Fatal("Advertisement manager is invalid.");
4055
return;
4156
}
57+
58+
AdUnitId =
59+
#if UNITY_WEBGL
60+
m_adUnitIdWebGL
61+
#if ENABLE_WECHAT_MINI_GAME
62+
m_adUnitIdWebGLWeChat
63+
#elif ENABLE_DOUYIN_MINI_GAME
64+
m_adUnitIdWebGLDouYin
65+
#else
66+
m_adUnitIdWebGL
67+
#endif
68+
#elif UNITY_ANDROID
69+
m_adUnitIdAndroid
70+
#elif UNITY_IOS
71+
m_adUnitIdiOS
72+
#endif
73+
;
4274
}
4375

4476
private void Start()

0 commit comments

Comments
 (0)