update AdManager

This commit is contained in:
atusi 2021-11-12 14:27:38 +09:00
parent 52bc654764
commit f3f1c9522f
1 changed files with 78 additions and 1 deletions

View File

@ -10,6 +10,14 @@ public sealed class AdManager : SingletonMonoBehaviour<AdManager> {
private static readonly string IRONSOURCE_APP_KEY = "11bc928bd"; private static readonly string IRONSOURCE_APP_KEY = "11bc928bd";
#endif #endif
private Action<bool> _rewardAdCallback = null;
private readonly int ASYNC_FRAME_LIMIT = 60;
private int _async_frame_count = 0;
private bool _rewardAdOpen = false;
private bool _rewardAdClose = false;
private bool _rewardAdFinish = false;
private float _timeScale = 0.0f;
void Awake(){ void Awake(){
#if DEVELOPMENT_BUILD #if DEVELOPMENT_BUILD
IronSource.Agent.validateIntegration (); IronSource.Agent.validateIntegration ();
@ -24,6 +32,30 @@ public sealed class AdManager : SingletonMonoBehaviour<AdManager> {
} }
void Update (){ void Update (){
if(_rewardAdOpen){
_rewardAdOpen = false;
pauseGame();
}else if(_rewardAdClose){
if(_rewardAdFinish){
_rewardAdClose = false;
InterstitialIntervalReset();
this.RewardAdCallbackClose(_rewardAdFinish);
}else if(ASYNC_FRAME_LIMIT > _async_frame_count){
_async_frame_count++;
}else{
_rewardAdClose = false;
this.RewardAdCallbackClose(_rewardAdFinish);
}
}
if(_interstitialAdOpen){
_interstitialAdOpen = false;
pauseGame();
}else if(_interstitialAdClose){
_interstitialAdClose = false;
resumeGame();
LoadInterstitial ();
InterstitialIntervalReset();
}
} }
void OnApplicationPause(bool isPaused) { void OnApplicationPause(bool isPaused) {
@ -43,7 +75,30 @@ public sealed class AdManager : SingletonMonoBehaviour<AdManager> {
IronSource.Agent.hideBanner(); IronSource.Agent.hideBanner();
} }
public void InitializeRewardedAds(){
IronSourceEvents.onRewardedVideoAdOpenedEvent += RewardedVideoAdOpenedEvent;
IronSourceEvents.onRewardedVideoAdClosedEvent += RewardedVideoAdClosedEvent;
IronSourceEvents.onRewardedVideoAvailabilityChangedEvent += RewardedVideoAvailabilityChangedEvent;
IronSourceEvents.onRewardedVideoAdStartedEvent += RewardedVideoAdStartedEvent;
IronSourceEvents.onRewardedVideoAdRewardedEvent += RewardedVideoAdRewardedEvent;
IronSourceEvents.onRewardedVideoAdShowFailedEvent += RewardedVideoAdShowFailedEvent;
}
private void RewardedVideoAdOpenedEvent(){
_rewardAdOpen = true;
}
private void RewardedVideoAdClosedEvent(){
_rewardAdClose = true;
}
private void RewardedVideoAvailabilityChangedEvent(bool available){
}
private void RewardedVideoAdStartedEvent(){
}
private void RewardedVideoAdRewardedEvent(IronSourcePlacement placement){
_rewardAdFinish = true;
}
private void RewardedVideoAdShowFailedEvent (IronSourceError error){
_rewardAdClose = true;
}
public bool IsLoadedRewardVideo(){ public bool IsLoadedRewardVideo(){
#if DEVELOPMENT_BUILD || UNITY_EDITOR #if DEVELOPMENT_BUILD || UNITY_EDITOR
return !UsayaStorageManager.LoadOrDefault(UsayaStorageFilename.Settings_Data, "DebugAlwaysVideoFailToLoad", false); return !UsayaStorageManager.LoadOrDefault(UsayaStorageFilename.Settings_Data, "DebugAlwaysVideoFailToLoad", false);
@ -68,4 +123,26 @@ public sealed class AdManager : SingletonMonoBehaviour<AdManager> {
} }
#endif #endif
} }
private void RewardAdCallbackClose(bool success){
resumeGame();
_rewardAdCallback(success);
}
private void pauseGame(){
SoundManager.Instance.PauseBGM();
SoundManager.Instance.StopSE();
if(Time.timeScale > 0.0f){
_timeScale = Time.timeScale;
// TimeManager.Instance.Stop();
}
}
private void resumeGame(){
SoundManager.Instance.ReplayBGM();
if(_timeScale > 0.0f){
Time.timeScale = _timeScale;
// TimeManager.Instance.ChangeTimeScale(_timeScale);
_timeScale = 0.0f;
}
}
} }