|
|
@ -31,7 +31,7 @@ public class AdsManager : MonoBehaviour
|
|
|
|
private bool loadingrAd = false;
|
|
|
|
private bool loadingrAd = false;
|
|
|
|
private RewardedTypes rewardType;
|
|
|
|
private RewardedTypes rewardType;
|
|
|
|
private bool isRewardAvailable = false;
|
|
|
|
private bool isRewardAvailable = false;
|
|
|
|
|
|
|
|
public bool isRewardedAdAvailable = false;
|
|
|
|
public static AdsManager Instance;
|
|
|
|
public static AdsManager Instance;
|
|
|
|
public Action<RewardedTypes> OnUserEarnedReward;
|
|
|
|
public Action<RewardedTypes> OnUserEarnedReward;
|
|
|
|
public Action OnAdmobInitializedEvent;
|
|
|
|
public Action OnAdmobInitializedEvent;
|
|
|
@ -42,12 +42,20 @@ public class AdsManager : MonoBehaviour
|
|
|
|
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Instance = this;
|
|
|
|
if (Instance != null && Instance != this)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Destroy(this);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Instance = this;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
DontDestroyOnLoad(gameObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//InitializeAdmob();
|
|
|
|
InitializeAdmob();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void FixedUpdate()
|
|
|
|
private void FixedUpdate()
|
|
|
@ -88,8 +96,8 @@ public class AdsManager : MonoBehaviour
|
|
|
|
private void OnAdPaid(AdValue adValue)
|
|
|
|
private void OnAdPaid(AdValue adValue)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Debug.Log(String.Format("ad paid {0} {1}.",
|
|
|
|
Debug.Log(String.Format("ad paid {0} {1}.",
|
|
|
|
adValue.Value,
|
|
|
|
adValue.Value,
|
|
|
|
adValue.CurrencyCode));
|
|
|
|
adValue.CurrencyCode));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void PauseGame()
|
|
|
|
private void PauseGame()
|
|
|
@ -210,7 +218,7 @@ public class AdsManager : MonoBehaviour
|
|
|
|
MobileAdsEventExecutor.ExecuteInUpdate(() =>
|
|
|
|
MobileAdsEventExecutor.ExecuteInUpdate(() =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Debug.LogError("Interstitial ad failed to open full screen content " +
|
|
|
|
Debug.LogError("Interstitial ad failed to open full screen content " +
|
|
|
|
"with error : " + error);
|
|
|
|
"with error : " + error);
|
|
|
|
LoadInterstitialAdWithDelay();
|
|
|
|
LoadInterstitialAdWithDelay();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -269,6 +277,7 @@ public class AdsManager : MonoBehaviour
|
|
|
|
if (error != null || ad == null)
|
|
|
|
if (error != null || ad == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OnrAdLoaded?.Invoke(false);
|
|
|
|
OnrAdLoaded?.Invoke(false);
|
|
|
|
|
|
|
|
isRewardedAdAvailable = false;
|
|
|
|
rewardedRetryAttempt++;
|
|
|
|
rewardedRetryAttempt++;
|
|
|
|
//load ad again
|
|
|
|
//load ad again
|
|
|
|
LoadRewardedAdWithDelay();
|
|
|
|
LoadRewardedAdWithDelay();
|
|
|
@ -281,6 +290,7 @@ public class AdsManager : MonoBehaviour
|
|
|
|
Debug.Log("rewarded ad loaded with response : "
|
|
|
|
Debug.Log("rewarded ad loaded with response : "
|
|
|
|
+ ad.GetResponseInfo());
|
|
|
|
+ ad.GetResponseInfo());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
isRewardedAdAvailable = true;
|
|
|
|
OnrAdLoaded?.Invoke(true);
|
|
|
|
OnrAdLoaded?.Invoke(true);
|
|
|
|
_rewardedAd = ad;
|
|
|
|
_rewardedAd = ad;
|
|
|
|
RegisterEventHandlers(_rewardedAd);
|
|
|
|
RegisterEventHandlers(_rewardedAd);
|
|
|
@ -319,7 +329,7 @@ public class AdsManager : MonoBehaviour
|
|
|
|
MobileAdsEventExecutor.ExecuteInUpdate(() =>
|
|
|
|
MobileAdsEventExecutor.ExecuteInUpdate(() =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Debug.LogError("Rewarded ad failed to open full screen content " +
|
|
|
|
Debug.LogError("Rewarded ad failed to open full screen content " +
|
|
|
|
"with error : " + error);
|
|
|
|
"with error : " + error);
|
|
|
|
LoadRewardedAdWithDelay();
|
|
|
|
LoadRewardedAdWithDelay();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -373,5 +383,6 @@ public enum RewardedTypes
|
|
|
|
Color,
|
|
|
|
Color,
|
|
|
|
Animation,
|
|
|
|
Animation,
|
|
|
|
InventoryPurchase,
|
|
|
|
InventoryPurchase,
|
|
|
|
Hint
|
|
|
|
Hint,
|
|
|
|
}
|
|
|
|
Coins
|
|
|
|
|
|
|
|
}
|