質問編集履歴
4
アセットや環境を詳しく追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -17,16 +17,13 @@
|
|
17
17
|
- シーンを移動する。
|
18
18
|
※Teratailの最大文字数制限を超過してしまうため、一部削減しています。
|
19
19
|
```
|
20
|
-
|
20
|
+
I Unity : onResume
|
21
21
|
...
|
22
|
+
I Unity : 広告を初期化することを試みます。
|
22
23
|
...
|
23
|
-
|
24
|
+
I Unity : 広告の表示条件が満たされていません。再初期化します。
|
24
25
|
...
|
25
|
-
08-21 18:59:31.662 9854 9870 I Unity : 広告の表示条件が満たされていません。再初期化します。
|
26
|
-
08-21 18:59:31.662 9854 9870 I Unity : UnityEngine.StackTraceUtility:ExtractStackTrace ()
|
27
|
-
...
|
28
|
-
|
26
|
+
I Unity : 広告が閉じられました。シーン遷移を続行します。
|
29
|
-
...
|
30
27
|
```
|
31
28
|
特に初期化の際のエラーといったものは見られませんでした。
|
32
29
|
|
@@ -48,12 +45,15 @@
|
|
48
45
|
### 補足情報(FW/ツールのバージョンなど)
|
49
46
|
- Unity 2020.3.4f1
|
50
47
|
- Advertisement Legacy 4.4.2
|
48
|
+
~~ 追記 ~~
|
49
|
+
- Windows10 22H2
|
51
|
-
|
50
|
+
- 実機→Android9.0 PIE
|
51
|
+
- adb: 1.0.41
|
52
|
+
- APILevel: 26
|
53
|
+
-
|
52
54
|
|
53
|
-
繰り返しになりますが、UnityEditorでは広告がしっかりと表示されております。(仮ですが)
|
54
|
-
|
55
55
|
私は初心者であるため色々なツッコミどころがあるかと思われますが、どうかご伝授お願いします...。
|
56
|
-
何か必要な情報がありましたら、ご遠慮なく言ってください。
|
56
|
+
何か必要な情報がありましたら、ご遠慮なく言ってください。
|
57
57
|
### 追記 2
|
58
58
|
@blanket 様からのご伝授により、AdsInitializerに以下のように改善しました。
|
59
59
|
```cs
|
@@ -332,4 +332,9 @@
|
|
332
332
|
- 初期化が原因なのは確実、できていない
|
333
333
|
- テストモードが原因ではない
|
334
334
|
- apkには異常はない?
|
335
|
-
ということもわかりました。
|
335
|
+
ということもわかりました。
|
336
|
+
|
337
|
+
# 追記3
|
338
|
+
アセットは以下のようなものを入れています。(パッケージマネージャーのプロジェクト内より)
|
339
|
+

|
340
|
+
それに加え、PlayFabSDKもあります。TextMeshProも。それ以外は特に入れていません。
|
3
コードの追記などをしました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -34,20 +34,8 @@
|
|
34
34
|
~~以下、関連するソースコードと変数などの情報を記述します。~~
|
35
35
|
追記の欄をご確認ください。旧コードが必要な場合はコメントしていただければと思います。
|
36
36
|
- 広告マネージャー(AdsInitializer.cs) ※Initalizerと書かれてはいますが表示処理関数も含まれています。
|
37
|
-
また、GameManager(シーン推移)からは、ShowUnityAds関数は以下のように呼ばれます。
|
37
|
+
~~また、GameManager(シーン推移)からは、ShowUnityAds関数は以下のように呼ばれます。~~
|
38
|
-
```cs
|
39
|
-
...
|
40
|
-
if (Random.value < Paramaters.Entity.adDisplayChance)
|
41
|
-
{
|
42
|
-
|
38
|
+
追記の欄をご覧ください。
|
43
|
-
yield return StartCoroutine(AdsInitializer.Instance.ShowUnityAds(() =>
|
44
|
-
{
|
45
|
-
Debug.Log("広告が閉じられました。シーン遷移を続行します。");
|
46
|
-
}));
|
47
|
-
AudioListener.volume = 1f;
|
48
|
-
}
|
49
|
-
...
|
50
|
-
```
|
51
39
|
- Paramaters.Entity.adDisplayChanceはfloat型であり1fです。
|
52
40
|
|
53
41
|
### 試したこと
|
@@ -56,7 +44,6 @@
|
|
56
44
|
- AdsのSDKのVerを下げて実装→しようとしたがQiitaに「動かなくなる」という趣旨のことが書かれてあったため却下
|
57
45
|
- Googleを調べる→X
|
58
46
|
- AdsManagerのインスタンスがないのかと思われましたが存在確認はしっかりと取れました。
|
59
|
-
-
|
60
47
|
|
61
48
|
### 補足情報(FW/ツールのバージョンなど)
|
62
49
|
- Unity 2020.3.4f1
|
@@ -67,17 +54,13 @@
|
|
67
54
|
|
68
55
|
私は初心者であるため色々なツッコミどころがあるかと思われますが、どうかご伝授お願いします...。
|
69
56
|
何か必要な情報がありましたら、ご遠慮なく言ってください。お願いします...
|
70
|
-
### 追記
|
57
|
+
### 追記 2
|
71
58
|
@blanket 様からのご伝授により、AdsInitializerに以下のように改善しました。
|
72
59
|
```cs
|
73
60
|
using System.Collections;
|
74
|
-
using System.Collections.Generic;
|
75
61
|
using UnityEngine;
|
76
62
|
using UnityEngine.UI;
|
77
63
|
using UnityEngine.Advertisements;
|
78
|
-
#if UNITY_EDITOR
|
79
|
-
using UnityEditor.Advertisements;
|
80
|
-
#endif
|
81
64
|
|
82
65
|
public class AdsInitializer : MonoBehaviour, IUnityAdsInitializationListener, IUnityAdsLoadListener, IUnityAdsShowListener
|
83
66
|
{
|
@@ -89,7 +72,9 @@
|
|
89
72
|
private System.Action onAdClosed;
|
90
73
|
public static AdsInitializer Instance = null;
|
91
74
|
private bool isAdReady;
|
75
|
+
private int _retryAttempts = 0; // 再試行回数
|
92
76
|
|
77
|
+
|
93
78
|
private void Awake()
|
94
79
|
{
|
95
80
|
if (Instance == null)
|
@@ -102,34 +87,17 @@
|
|
102
87
|
Destroy(gameObject);
|
103
88
|
}
|
104
89
|
isAdReady = false;
|
105
|
-
#if UNITY_IOS
|
106
|
-
_gameId = "XXXXXXX";
|
107
|
-
_interstitialAdPracementId = "Interstitial_iOS";
|
108
|
-
_rewardAdPracementId = "Rewarded_iOS";
|
109
|
-
_bannerAdPracementId = "Banner_iOS";
|
110
|
-
#elif UNITY_ANDROID
|
111
|
-
_gameId = "XXXXXXX";
|
112
|
-
_interstitialAdPracementId = "Interstitial_Android";
|
113
|
-
_rewardAdPracementId = "Rewarded_Android";
|
114
|
-
_bannerAdPracementId = "Banner_Android";
|
115
|
-
#else
|
116
|
-
_gameId = "XXXXXXX";
|
117
|
-
_interstitialAdPracementId = "Interstitial_Android";
|
118
|
-
_rewardAdPracementId = "Rewarded_Android";
|
119
|
-
_bannerAdPracementId = "Banner_Android";
|
120
|
-
#endif
|
121
90
|
}
|
122
91
|
|
123
92
|
private void Start()
|
124
93
|
{
|
125
94
|
Debug.Log("Game IDは" + _gameId + "に初期化されています。");
|
126
|
-
Debug.Log("
|
95
|
+
Debug.Log((Instance == null ? "Instanceがnullです。" : "Instanceがnullではありません。"));
|
127
96
|
|
128
97
|
if (!Advertisement.isInitialized && Advertisement.isSupported)
|
129
98
|
{
|
130
99
|
Debug.Log("広告を初期化することを試みます。");
|
131
|
-
|
100
|
+
Invoke(nameof(InitializeAds), 2f);
|
132
|
-
|
133
101
|
}
|
134
102
|
else if (Advertisement.isInitialized)
|
135
103
|
{
|
@@ -140,15 +108,34 @@
|
|
140
108
|
{
|
141
109
|
Debug.LogWarning("広告の初期化またはサポートがありません。");
|
142
110
|
}
|
143
|
-
|
144
111
|
}
|
145
112
|
|
146
113
|
|
147
114
|
private void InitializeAds()
|
148
115
|
{
|
116
|
+
#if UNITY_IOS
|
117
|
+
_gameId = "5678792";
|
118
|
+
_interstitialAdPracementId = "Interstitial_iOS";
|
119
|
+
_rewardAdPracementId = "Rewarded_iOS";
|
120
|
+
_bannerAdPracementId = "Banner_iOS";
|
121
|
+
#elif UNITY_ANDROID
|
122
|
+
_gameId = "5678793";
|
123
|
+
_interstitialAdPracementId = "Interstitial_Android";
|
124
|
+
_rewardAdPracementId = "Rewarded_Android";
|
125
|
+
_bannerAdPracementId = "Banner_Android";
|
126
|
+
#else
|
127
|
+
_gameId = "5678793";
|
128
|
+
_interstitialAdPracementId = "Interstitial_Android";
|
129
|
+
_rewardAdPracementId = "Rewarded_Android";
|
130
|
+
_bannerAdPracementId = "Banner_Android";
|
131
|
+
#endif
|
132
|
+
|
133
|
+
// https://teratail.com/questions/gz01z3aeeplu99#reply-idhv4lq3k7eujv これをみてくれ
|
134
|
+
|
149
135
|
if (!Advertisement.isInitialized && Advertisement.isSupported)
|
150
136
|
{
|
151
|
-
Advertisement.Initialize(
|
137
|
+
Advertisement.Initialize("5678793", true, this);
|
138
|
+
Debug.Log("広告を表示しました。");
|
152
139
|
}
|
153
140
|
else
|
154
141
|
{
|
@@ -158,57 +145,71 @@
|
|
158
145
|
|
159
146
|
public IEnumerator ShowUnityAds(System.Action onAdClosedCallback)
|
160
147
|
{
|
161
|
-
if (Instance == null)
|
162
|
-
{
|
163
|
-
Debug.LogError("広告マネージャーのインスタンスがnullです。");
|
164
|
-
}
|
165
|
-
|
166
148
|
bool adClosed = false;
|
167
149
|
onAdClosed = () => adClosed = true;
|
168
150
|
|
169
|
-
Debug.Log("広告はサポート" + (Advertisement.isSupported ? "されています" : "されていません"));
|
170
|
-
Debug.Log("isAdReadyは" + (isAdReady ? "true" : "false"));
|
171
|
-
Debug.Log("初期化は" + (Advertisement.isInitialized ? "されています" : "されていません"));
|
172
|
-
|
173
|
-
if (
|
151
|
+
if (/*isAdReady*/true)
|
174
152
|
{
|
175
|
-
if (
|
153
|
+
if (Advertisement.isInitialized && /* isAdReady */ true)
|
176
154
|
{
|
177
|
-
Debug.Log("広告を
|
155
|
+
Debug.Log("広告を表示します。");
|
178
|
-
Advertisement.
|
156
|
+
Advertisement.Show(_interstitialAdPracementId, this);
|
179
|
-
|
180
|
-
// 広告が準備完了するまで待機
|
181
|
-
while (!isAdReady)
|
182
|
-
{
|
183
|
-
yield return null;
|
184
|
-
}
|
185
157
|
}
|
158
|
+
else
|
159
|
+
{
|
160
|
+
Debug.LogError("広告が初期化されていないか、ロードされていません。");
|
161
|
+
}
|
186
162
|
|
187
|
-
Debug.Log("広告を表示します。");
|
188
|
-
Advertisement.Show(_interstitialAdPracementId, Instance);
|
189
|
-
|
190
|
-
// 広告が閉じるまで待機
|
163
|
+
// 広告が閉じられるまで待機
|
191
164
|
while (!adClosed)
|
192
165
|
{
|
193
166
|
yield return null;
|
194
167
|
}
|
195
168
|
|
169
|
+
Debug.Log("広告が閉じられました。シーン遷移を続行します。");
|
196
170
|
onAdClosedCallback?.Invoke();
|
197
171
|
}
|
198
172
|
else
|
199
173
|
{
|
200
|
-
Debug.Log("広告の
|
174
|
+
Debug.Log("広告の準備ができていません。");
|
201
|
-
Advertisement.Initialize(_gameId, true, Instance);
|
202
175
|
onAdClosedCallback?.Invoke();
|
203
176
|
}
|
177
|
+
LoadAd();
|
178
|
+
yield return new WaitForSeconds(1);
|
204
179
|
}
|
205
180
|
|
181
|
+
public void TestLog()
|
182
|
+
{
|
183
|
+
Debug.Log("テストです。");
|
184
|
+
}
|
185
|
+
|
186
|
+
private IEnumerator WaitForAdToClose(System.Action onAdClosedCallback)
|
187
|
+
{
|
188
|
+
bool adClosed = false;
|
189
|
+
onAdClosedCallback += () => adClosed = true;
|
190
|
+
|
191
|
+
// タイムアウトの設定(例えば10秒)
|
192
|
+
float timeout = 10f;
|
193
|
+
float elapsedTime = 0f;
|
194
|
+
|
195
|
+
while (!adClosed && elapsedTime < timeout)
|
196
|
+
{
|
197
|
+
elapsedTime += Time.deltaTime;
|
198
|
+
yield return null;
|
199
|
+
}
|
200
|
+
|
201
|
+
if (!adClosed)
|
202
|
+
{
|
203
|
+
Debug.LogWarning("広告は時間内に閉じず、元の機能を再開しました。");
|
204
|
+
onAdClosedCallback?.Invoke();
|
205
|
+
}
|
206
|
+
}
|
207
|
+
|
206
208
|
public void OnInitializationComplete()
|
207
209
|
{
|
208
210
|
Debug.Log("広告の初期化が完了しました。");
|
209
211
|
// 初期化が完了したので、広告をロード
|
210
|
-
isAdReady = false; // 初期化後にロードが行われるので、isAdReadyをリセット
|
211
|
-
|
212
|
+
LoadAd();
|
212
213
|
}
|
213
214
|
|
214
215
|
public void OnInitializationFailed(UnityAdsInitializationError error, string message)
|
@@ -216,35 +217,61 @@
|
|
216
217
|
Debug.LogError($"Initialization failed: {error} - {message}");
|
217
218
|
}
|
218
219
|
|
220
|
+
private void LoadAd()
|
221
|
+
{
|
222
|
+
if (!isAdReady)
|
223
|
+
{
|
224
|
+
Advertisement.Load(_interstitialAdPracementId, this);
|
225
|
+
}
|
226
|
+
}
|
227
|
+
|
219
228
|
public void OnUnityAdsAdLoaded(string placementId)
|
220
229
|
{
|
221
230
|
Debug.Log($"広告ユニット {placementId} がロードされました。");
|
222
231
|
if (placementId == _interstitialAdPracementId)
|
223
232
|
{
|
224
233
|
isAdReady = true;
|
234
|
+
_retryAttempts = 0; // リセット
|
225
235
|
}
|
226
236
|
}
|
227
237
|
|
228
|
-
|
229
238
|
public void OnUnityAdsFailedToLoad(string placementId, UnityAdsLoadError error, string message)
|
230
239
|
{
|
231
|
-
Debug.LogError($"
|
240
|
+
Debug.LogError($"Failed to load Ad: {placementId} - {error} - {message}");
|
232
241
|
isAdReady = false;
|
233
|
-
onAdClosed?.Invoke();
|
234
|
-
}
|
235
242
|
|
236
|
-
|
243
|
+
if (_retryAttempts < 3) // 最大3回再試行
|
237
|
-
|
244
|
+
{
|
238
|
-
|
245
|
+
_retryAttempts++;
|
239
|
-
|
246
|
+
StartCoroutine(RetryLoadAd());
|
247
|
+
}
|
240
248
|
}
|
241
249
|
|
242
250
|
public void OnUnityAdsShowFailure(string placementId, UnityAdsShowError error, string message)
|
243
251
|
{
|
244
252
|
Debug.LogError($"Error showing Ad Unit {placementId}: {error} - {message}");
|
253
|
+
isAdReady = false;
|
254
|
+
|
255
|
+
if (_retryAttempts < 3)
|
256
|
+
{
|
257
|
+
_retryAttempts++;
|
258
|
+
// StartCoroutine(RetryShowAd());
|
245
|
-
|
259
|
+
InitializeAds();
|
260
|
+
}
|
246
261
|
}
|
247
262
|
|
263
|
+
public IEnumerator RetryShowAd()
|
264
|
+
{
|
265
|
+
yield return new WaitForSeconds(2f); // 2秒後に再試行
|
266
|
+
ShowUnityAds(onAdClosed); // 再試行する
|
267
|
+
}
|
268
|
+
|
269
|
+
private IEnumerator RetryLoadAd()
|
270
|
+
{
|
271
|
+
yield return new WaitForSeconds(2f); // 2秒後に再試行
|
272
|
+
LoadAd();
|
273
|
+
}
|
274
|
+
|
248
275
|
public void OnUnityAdsShowStart(string placementId)
|
249
276
|
{
|
250
277
|
Debug.Log("広告表示開始");
|
@@ -258,12 +285,11 @@
|
|
258
285
|
public void OnUnityAdsShowComplete(string placementId, UnityAdsShowCompletionState showCompletionState)
|
259
286
|
{
|
260
287
|
Debug.Log("広告表示完了");
|
288
|
+
isAdReady = false;
|
261
289
|
onAdClosed?.Invoke();
|
262
|
-
// 広告
|
290
|
+
LoadAd(); // 次の広告をロード
|
263
|
-
Advertisement.Load(_interstitialAdPracementId, this);
|
264
291
|
}
|
265
292
|
}
|
266
|
-
|
267
293
|
```
|
268
294
|
そして、呼び出す側のスクリプトにも少々改善を加えました。
|
269
295
|
```cs
|
@@ -279,19 +305,8 @@
|
|
279
305
|
|
280
306
|
AudioListener.volume = 1f;
|
281
307
|
}
|
282
|
-
if (!isMoving)
|
283
|
-
{
|
284
|
-
|
308
|
+
yield break;
|
285
|
-
fade.enabled = true;
|
286
|
-
fade.color = new Color(0f, 0f, 0f, 0f);
|
287
|
-
for (int i = 0; i < 10; i++)
|
288
|
-
|
309
|
+
...
|
289
|
-
fade.color = new Color(0f, 0f, 0f, i * 0.1f);
|
290
|
-
yield return new WaitForSeconds(0.1f);
|
291
|
-
}
|
292
|
-
SceneManager.LoadScene(scenename);
|
293
|
-
StartCoroutine(FadeOut());
|
294
|
-
}
|
295
310
|
```
|
296
311
|
そのログがこちらです。一部は削減しています。
|
297
312
|
```
|
@@ -311,4 +326,10 @@
|
|
311
326
|
- 表示開始~終了までの一連の長れが実行されている
|
312
327
|
- サポートはされている
|
313
328
|
- 初期化がされていない
|
329
|
+
- GameIDやインタースティシャル広告のユニットが誤っているわけではない
|
330
|
+
また、
|
331
|
+
ということがわかりました。また、 @blanket 様のアドバイスや自分の判断による修正により
|
332
|
+
- 初期化が原因なのは確実、できていない
|
333
|
+
- テストモードが原因ではない
|
334
|
+
- apkには異常はない?
|
314
|
-
ということ
|
335
|
+
ということもわかりました。
|
2
少々改善
title
CHANGED
File without changes
|
body
CHANGED
@@ -103,17 +103,17 @@
|
|
103
103
|
}
|
104
104
|
isAdReady = false;
|
105
105
|
#if UNITY_IOS
|
106
|
-
_gameId = "
|
106
|
+
_gameId = "XXXXXXX";
|
107
107
|
_interstitialAdPracementId = "Interstitial_iOS";
|
108
108
|
_rewardAdPracementId = "Rewarded_iOS";
|
109
109
|
_bannerAdPracementId = "Banner_iOS";
|
110
110
|
#elif UNITY_ANDROID
|
111
|
-
_gameId = "
|
111
|
+
_gameId = "XXXXXXX";
|
112
112
|
_interstitialAdPracementId = "Interstitial_Android";
|
113
113
|
_rewardAdPracementId = "Rewarded_Android";
|
114
114
|
_bannerAdPracementId = "Banner_Android";
|
115
115
|
#else
|
116
|
-
_gameId = "
|
116
|
+
_gameId = "XXXXXXX";
|
117
117
|
_interstitialAdPracementId = "Interstitial_Android";
|
118
118
|
_rewardAdPracementId = "Rewarded_Android";
|
119
119
|
_bannerAdPracementId = "Banner_Android";
|
1
修正案をいただいたため追記をしました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -19,46 +19,61 @@
|
|
19
19
|
```
|
20
20
|
08-21 18:58:51.167 9854 9854 I Unity : onResume
|
21
21
|
...
|
22
|
-
08-21 18:58:57.999 9854 9870 I Unity : UnityEngine.StackTraceUtility:ExtractStackTrace () (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/StackTrace.cs:37)
|
23
|
-
08-21 18:58:57.999 9854 9870 I Unity : UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
|
24
|
-
08-21 18:58:57.999 9854 9870 I Unity : UnityEngine.Logger:Log (UnityEngine.LogType,object)
|
25
22
|
...
|
26
|
-
08-21 18:58:57.999 9854 9870 I Unity :
|
27
|
-
08-21 18:58:58.078 9854 9870 I Unity : THIS: x<sup>2</sup>=0
|
28
|
-
...
|
29
|
-
(UnityEngine.LogType,UnityEngine.Object,string,object[])
|
30
|
-
08-21 18:58:58.078 9854 9870 I Unity : UnityEngine.Logger:Log (UnityEngine.LogType,object)
|
31
|
-
08-21 18:58:58.078 9854 9870 I Unity : UnityEngine.Debug:Log (object)
|
32
|
-
08-21 18:58:58.078 9854 9870 I Unity : Factor:<ViewFormula>g__GenerateEquation|11_0 (int,int,int) (at D:/UnityProject/Swap Factor/Assets/Scripts/GamePlay/Factor.cs:39)
|
33
|
-
08-21 18:58:58.078 9854 9870 I Unity : Factor:ViewFormula (int) (at D:/UnityProject/Swap Factor/Assets/Scripts/GamePlay/Factor.cs:88)
|
34
|
-
...
|
35
23
|
08-21 18:58:58.220 9854 9870 I Unity : 広告を初期化することを試みます。
|
36
24
|
...
|
37
|
-
08-21 18:58:58.220 9854 9870 I Unity : UnityEngine.Debug:Log (object)
|
38
|
-
08-21 18:58:58.220 9854 9870 I Unity : AdsInitializer:Start () (at D:/UnityProject/Swap Factor/Assets/Scripts/Ad/AdsInitializer.cs:50)
|
39
|
-
08-21 18:58:58.220 9854 9870 I Unity :
|
40
|
-
08-21 18:58:58.220 9854 9870 I Unity : (Filename: /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/StackTrace.cs Line: 37)
|
41
|
-
08-21 18:58:58.220 9854 9870 I Unity :
|
42
25
|
08-21 18:59:31.662 9854 9870 I Unity : 広告の表示条件が満たされていません。再初期化します。
|
43
|
-
08-21 18:59:31.662 9854 9870 I Unity : UnityEngine.StackTraceUtility:ExtractStackTrace () (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/StackTrace.cs:37)
|
44
|
-
08-21 18:59:31.662 9854 9870 I Unity : UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
|
45
|
-
08-21 18:59:31.662 9854 9870 I Unity : UnityEngine.
|
26
|
+
08-21 18:59:31.662 9854 9870 I Unity : UnityEngine.StackTraceUtility:ExtractStackTrace ()
|
46
27
|
...
|
47
28
|
08-21 18:59:31.687 9854 9870 I Unity : 広告が閉じられました。シーン遷移を続行します。
|
48
|
-
08-21 18:59:31.687 9854 9870 I Unity : UnityEngine.StackTraceUtility:ExtractStackTrace () (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/StackTrace.cs:37)
|
49
|
-
08-21 18:59:31.687 9854 9870 I Unity : UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
|
50
|
-
08-21 18:59:31.687 9854 9870 I Unity : UnityEngine.Logger:Log (UnityEngine.LogType,object)
|
51
29
|
...
|
52
30
|
```
|
53
31
|
特に初期化の際のエラーといったものは見られませんでした。
|
54
32
|
|
55
33
|
### 該当のソースコード
|
56
|
-
以下、関連するソースコードと変数などの情報を記述します。
|
34
|
+
~~以下、関連するソースコードと変数などの情報を記述します。~~
|
35
|
+
追記の欄をご確認ください。旧コードが必要な場合はコメントしていただければと思います。
|
57
36
|
- 広告マネージャー(AdsInitializer.cs) ※Initalizerと書かれてはいますが表示処理関数も含まれています。
|
37
|
+
また、GameManager(シーン推移)からは、ShowUnityAds関数は以下のように呼ばれます。
|
58
38
|
```cs
|
39
|
+
...
|
40
|
+
if (Random.value < Paramaters.Entity.adDisplayChance)
|
41
|
+
{
|
42
|
+
AudioListener.volume = 0f;
|
43
|
+
yield return StartCoroutine(AdsInitializer.Instance.ShowUnityAds(() =>
|
44
|
+
{
|
45
|
+
Debug.Log("広告が閉じられました。シーン遷移を続行します。");
|
46
|
+
}));
|
47
|
+
AudioListener.volume = 1f;
|
48
|
+
}
|
49
|
+
...
|
50
|
+
```
|
51
|
+
- Paramaters.Entity.adDisplayChanceはfloat型であり1fです。
|
52
|
+
|
53
|
+
### 試したこと
|
54
|
+
- GPT4oに聞く→まともな解決策が提案されず
|
55
|
+
- Teratailで検索→こちらの状況とは当てはまらず
|
56
|
+
- AdsのSDKのVerを下げて実装→しようとしたがQiitaに「動かなくなる」という趣旨のことが書かれてあったため却下
|
57
|
+
- Googleを調べる→X
|
58
|
+
- AdsManagerのインスタンスがないのかと思われましたが存在確認はしっかりと取れました。
|
59
|
+
-
|
60
|
+
|
61
|
+
### 補足情報(FW/ツールのバージョンなど)
|
62
|
+
- Unity 2020.3.4f1
|
63
|
+
- Advertisement Legacy 4.4.2
|
64
|
+
IsReady関数は何故か実装されていません。
|
65
|
+
|
66
|
+
繰り返しになりますが、UnityEditorでは広告がしっかりと表示されております。(仮ですが)
|
67
|
+
|
68
|
+
私は初心者であるため色々なツッコミどころがあるかと思われますが、どうかご伝授お願いします...。
|
69
|
+
何か必要な情報がありましたら、ご遠慮なく言ってください。お願いします...
|
70
|
+
### 追記 1
|
71
|
+
@blanket 様からのご伝授により、AdsInitializerに以下のように改善しました。
|
72
|
+
```cs
|
59
73
|
using System.Collections;
|
60
74
|
using System.Collections.Generic;
|
61
75
|
using UnityEngine;
|
76
|
+
using UnityEngine.UI;
|
62
77
|
using UnityEngine.Advertisements;
|
63
78
|
#if UNITY_EDITOR
|
64
79
|
using UnityEditor.Advertisements;
|
@@ -88,17 +103,17 @@
|
|
88
103
|
}
|
89
104
|
isAdReady = false;
|
90
105
|
#if UNITY_IOS
|
91
|
-
_gameId = "
|
106
|
+
_gameId = "5678792";
|
92
107
|
_interstitialAdPracementId = "Interstitial_iOS";
|
93
108
|
_rewardAdPracementId = "Rewarded_iOS";
|
94
109
|
_bannerAdPracementId = "Banner_iOS";
|
95
110
|
#elif UNITY_ANDROID
|
96
|
-
_gameId = "
|
111
|
+
_gameId = "5678793";
|
97
112
|
_interstitialAdPracementId = "Interstitial_Android";
|
98
113
|
_rewardAdPracementId = "Rewarded_Android";
|
99
114
|
_bannerAdPracementId = "Banner_Android";
|
100
115
|
#else
|
101
|
-
_gameId = "
|
116
|
+
_gameId = "5678793";
|
102
117
|
_interstitialAdPracementId = "Interstitial_Android";
|
103
118
|
_rewardAdPracementId = "Rewarded_Android";
|
104
119
|
_bannerAdPracementId = "Banner_Android";
|
@@ -107,28 +122,60 @@
|
|
107
122
|
|
108
123
|
private void Start()
|
109
124
|
{
|
125
|
+
Debug.Log("Game IDは" + _gameId + "に初期化されています。");
|
126
|
+
Debug.Log("AdsManagerの数は" + GameObject.FindGameObjectsWithTag("Ads").Length.ToString());
|
127
|
+
|
110
128
|
if (!Advertisement.isInitialized && Advertisement.isSupported)
|
111
129
|
{
|
112
130
|
Debug.Log("広告を初期化することを試みます。");
|
113
|
-
|
131
|
+
InitializeAds();
|
132
|
+
|
114
133
|
}
|
134
|
+
else if (Advertisement.isInitialized)
|
135
|
+
{
|
136
|
+
Debug.Log("広告はすでに初期化されています。");
|
137
|
+
OnInitializationComplete();
|
138
|
+
}
|
115
139
|
else
|
116
140
|
{
|
117
141
|
Debug.LogWarning("広告の初期化またはサポートがありません。");
|
118
142
|
}
|
143
|
+
|
119
144
|
}
|
120
145
|
|
146
|
+
|
147
|
+
private void InitializeAds()
|
148
|
+
{
|
149
|
+
if (!Advertisement.isInitialized && Advertisement.isSupported)
|
150
|
+
{
|
151
|
+
Advertisement.Initialize(_gameId, true, Instance);
|
152
|
+
}
|
153
|
+
else
|
154
|
+
{
|
155
|
+
Debug.LogWarning("Unity Ads is not supported or already initialized.");
|
156
|
+
}
|
157
|
+
}
|
158
|
+
|
121
159
|
public IEnumerator ShowUnityAds(System.Action onAdClosedCallback)
|
122
160
|
{
|
161
|
+
if (Instance == null)
|
162
|
+
{
|
163
|
+
Debug.LogError("広告マネージャーのインスタンスがnullです。");
|
164
|
+
}
|
165
|
+
|
123
166
|
bool adClosed = false;
|
124
167
|
onAdClosed = () => adClosed = true;
|
125
168
|
|
169
|
+
Debug.Log("広告はサポート" + (Advertisement.isSupported ? "されています" : "されていません"));
|
170
|
+
Debug.Log("isAdReadyは" + (isAdReady ? "true" : "false"));
|
171
|
+
Debug.Log("初期化は" + (Advertisement.isInitialized ? "されています" : "されていません"));
|
172
|
+
|
126
173
|
if (Advertisement.isInitialized && Advertisement.isSupported)
|
127
174
|
{
|
128
175
|
if (!isAdReady)
|
129
176
|
{
|
130
177
|
Debug.Log("広告をロードしています...");
|
131
|
-
Advertisement.Load(_interstitialAdPracementId,
|
178
|
+
Advertisement.Load(_interstitialAdPracementId, Instance);
|
132
179
|
|
133
180
|
// 広告が準備完了するまで待機
|
134
181
|
while (!isAdReady)
|
@@ -138,7 +185,7 @@
|
|
138
185
|
}
|
139
186
|
|
140
187
|
Debug.Log("広告を表示します。");
|
141
|
-
Advertisement.Show(_interstitialAdPracementId,
|
188
|
+
Advertisement.Show(_interstitialAdPracementId, Instance);
|
142
189
|
|
143
190
|
// 広告が閉じるまで待機
|
144
191
|
while (!adClosed)
|
@@ -150,22 +197,23 @@
|
|
150
197
|
}
|
151
198
|
else
|
152
199
|
{
|
153
|
-
Debug.Log("広告の表示条件が満たされていません。再初期化します。");
|
200
|
+
Debug.Log("広告の表示条件が満たされていません。再初期化します。");
|
154
|
-
Advertisement.Initialize(_gameId, true,
|
201
|
+
Advertisement.Initialize(_gameId, true, Instance);
|
155
202
|
onAdClosedCallback?.Invoke();
|
156
203
|
}
|
157
204
|
}
|
158
205
|
|
159
206
|
public void OnInitializationComplete()
|
160
207
|
{
|
161
|
-
Debug.Log("広告の初期化が完了しました。");
|
208
|
+
Debug.Log("広告の初期化が完了しました。");
|
162
209
|
// 初期化が完了したので、広告をロード
|
210
|
+
isAdReady = false; // 初期化後にロードが行われるので、isAdReadyをリセット
|
163
211
|
Advertisement.Load(_interstitialAdPracementId, this);
|
164
212
|
}
|
165
213
|
|
166
214
|
public void OnInitializationFailed(UnityAdsInitializationError error, string message)
|
167
215
|
{
|
168
|
-
Debug.LogError($"Initialization failed: {error} - {message}");
|
216
|
+
Debug.LogError($"Initialization failed: {error} - {message}");
|
169
217
|
}
|
170
218
|
|
171
219
|
public void OnUnityAdsAdLoaded(string placementId)
|
@@ -177,6 +225,7 @@
|
|
177
225
|
}
|
178
226
|
}
|
179
227
|
|
228
|
+
|
180
229
|
public void OnUnityAdsFailedToLoad(string placementId, UnityAdsLoadError error, string message)
|
181
230
|
{
|
182
231
|
Debug.LogError($"Error loading Ad Unit: {placementId} - {error} - {message}");
|
@@ -184,6 +233,12 @@
|
|
184
233
|
onAdClosed?.Invoke();
|
185
234
|
}
|
186
235
|
|
236
|
+
private IEnumerator RetryLoadAd()
|
237
|
+
{
|
238
|
+
yield return new WaitForSeconds(5); // 5秒後に再試行
|
239
|
+
Advertisement.Load(_interstitialAdPracementId, this);
|
240
|
+
}
|
241
|
+
|
187
242
|
public void OnUnityAdsShowFailure(string placementId, UnityAdsShowError error, string message)
|
188
243
|
{
|
189
244
|
Debug.LogError($"Error showing Ad Unit {placementId}: {error} - {message}");
|
@@ -208,37 +263,52 @@
|
|
208
263
|
Advertisement.Load(_interstitialAdPracementId, this);
|
209
264
|
}
|
210
265
|
}
|
266
|
+
|
211
267
|
```
|
212
|
-
|
268
|
+
そして、呼び出す側のスクリプトにも少々改善を加えました。
|
213
269
|
```cs
|
214
|
-
...
|
215
270
|
if (Random.value < Paramaters.Entity.adDisplayChance)
|
216
271
|
{
|
217
272
|
AudioListener.volume = 0f;
|
273
|
+
Debug.Log("広告表示開始");
|
218
274
|
yield return StartCoroutine(AdsInitializer.Instance.ShowUnityAds(() =>
|
219
275
|
{
|
220
276
|
Debug.Log("広告が閉じられました。シーン遷移を続行します。");
|
221
277
|
}));
|
278
|
+
Debug.Log("広告表示終了");
|
279
|
+
|
222
280
|
AudioListener.volume = 1f;
|
223
281
|
}
|
282
|
+
if (!isMoving)
|
224
|
-
|
283
|
+
{
|
284
|
+
isMoving = true;
|
285
|
+
fade.enabled = true;
|
286
|
+
fade.color = new Color(0f, 0f, 0f, 0f);
|
287
|
+
for (int i = 0; i < 10; i++)
|
288
|
+
{
|
289
|
+
fade.color = new Color(0f, 0f, 0f, i * 0.1f);
|
290
|
+
yield return new WaitForSeconds(0.1f);
|
291
|
+
}
|
292
|
+
SceneManager.LoadScene(scenename);
|
293
|
+
StartCoroutine(FadeOut());
|
294
|
+
}
|
225
295
|
```
|
296
|
+
そのログがこちらです。一部は削減しています。
|
297
|
+
```
|
226
|
-
|
298
|
+
I Unity : Game IDは(AndroidのゲームID)に初期化されています。
|
227
|
-
|
228
|
-
### 試したこと
|
229
|
-
|
299
|
+
I Unity : AdsManagerの数は1
|
230
|
-
|
300
|
+
I Unity : 広告を初期化することを試みます。
|
231
|
-
- AdsのSDKのVerを下げて実装→しようとしたがQiitaに「動かなくなる」という趣旨のことが書かれてあったため却下
|
232
|
-
- Googleを調べる→X
|
233
|
-
- AdsManagerのインスタンスがないのかと思われましたが存在確認はしっかりと取れました。
|
234
|
-
-
|
235
|
-
|
236
|
-
### 補足情報(FW/ツールのバージョンなど)
|
237
|
-
|
301
|
+
I Unity : 広告表示開始
|
238
|
-
|
302
|
+
I Unity : 広告はサポートされています
|
239
|
-
|
303
|
+
I Unity : 初期化はされていません
|
240
|
-
|
241
|
-
|
304
|
+
I Unity : 広告の表示条件が満たされていません。再初期化します。
|
242
|
-
|
243
|
-
私は初心者であるため色々なツッコミどころがあるかと思われますが、どうかご伝授お願いします...。
|
244
|
-
|
305
|
+
I Unity : 広告が閉じられました。シーン遷移を続行します。
|
306
|
+
I Unity : 広告表示終了
|
307
|
+
```
|
308
|
+
以下のことより、
|
309
|
+
- Game Idの間違いではない
|
310
|
+
- 初期化をしようとはしている
|
311
|
+
- 表示開始~終了までの一連の長れが実行されている
|
312
|
+
- サポートはされている
|
313
|
+
- 初期化がされていない
|
314
|
+
ということがわかりました。
|