162 lines
4.7 KiB
C#
162 lines
4.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using System.Runtime.InteropServices;
|
|
using System;
|
|
|
|
#if UNITY_IOS
|
|
namespace AudienceNetwork
|
|
{
|
|
public static class AdSettings
|
|
{
|
|
[DllImport("__Internal")]
|
|
private static extern void FBAdSettingsBridgeSetAdvertiserTrackingEnabled(bool advertiserTrackingEnabled);
|
|
|
|
public static void SetAdvertiserTrackingEnabled(bool advertiserTrackingEnabled)
|
|
{
|
|
FBAdSettingsBridgeSetAdvertiserTrackingEnabled(advertiserTrackingEnabled);
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
|
|
public partial class AdManager : BF.MonoSingleton<AdManager>
|
|
{
|
|
private const string Tag = "AdManager:";
|
|
private const string Key = "9uHgeBwag3NXva9MC23ToO3q11Ve59bF1uwg4qGltdGmCQ7OSByFZ_3b1ZF7krMlkHQo5gXzIokVDsvg1rwbr-";
|
|
string bannerAdUnitId = "YOUR_BANNER_AD_UNIT_ID"; // Retrieve the ID from your account
|
|
string adInterstitialUnitId = "YOUR_AD_UNIT_ID";
|
|
#if UNITY_IOS || UNITY_IPHONE
|
|
string adRewardUnitId = "1043ecded04c561b";
|
|
#else
|
|
string adRewardUnitId = "3fdcc8a796773aa2";
|
|
#endif
|
|
public Action<string> luaAdRevenuePaidEventCallback;
|
|
// Start is called before the first frame update
|
|
public void Init(string init = "")
|
|
{
|
|
MaxSdkCallbacks.OnSdkInitializedEvent += (MaxSdkBase.SdkConfiguration sdkConfiguration) =>
|
|
{
|
|
#if UNITY_IOS || UNITY_IPHONE
|
|
if (MaxSdkUtils.CompareVersions(UnityEngine.iOS.Device.systemVersion, "14.5") != MaxSdkUtils.VersionComparisonResult.Lesser)
|
|
{
|
|
// Note that App transparency tracking authorization can be checked via `sdkConfiguration.AppTrackingStatus` for Unity Editor and iOS targets
|
|
// 1. Set Meta ATE flag here, THEN
|
|
if (MaxSdkBase.AppTrackingStatus.Authorized == sdkConfiguration.AppTrackingStatus)
|
|
AudienceNetwork.AdSettings.SetAdvertiserTrackingEnabled(true);
|
|
else
|
|
AudienceNetwork.AdSettings.SetAdvertiserTrackingEnabled(false);
|
|
}
|
|
#endif
|
|
// Show Mediation Debugger
|
|
// MaxSdk.ShowMediationDebugger();
|
|
// MaxSdk.SetVerboseLogging(true);
|
|
// AppLovin SDK is initialized, start loading ads
|
|
LoadAds();
|
|
};
|
|
|
|
MaxSdk.SetSdkKey(Key);
|
|
MaxSdk.SetUserId(SystemInfo.deviceUniqueIdentifier);
|
|
// MaxSdk.SetVerboseLogging(true);
|
|
MaxSdk.InitializeSdk();
|
|
|
|
}
|
|
|
|
private void LoadAds()
|
|
{
|
|
InitializeRewardedAds();
|
|
// InitializeBannerAds();
|
|
// InitializeInterstitialAds();
|
|
}
|
|
|
|
public void SetAdRevenuePaidEventCallback(Action<string> callback)
|
|
{
|
|
luaAdRevenuePaidEventCallback = callback;
|
|
}
|
|
|
|
public bool IsRewardedAdReady()
|
|
{
|
|
return MaxSdk.IsRewardedAdReady(adRewardUnitId);
|
|
}
|
|
|
|
public void ShowRewardedAd(Action<int> callback = null)
|
|
{
|
|
#if UNITY_EDITOR
|
|
callback?.Invoke(0);
|
|
return;
|
|
#endif
|
|
if (MaxSdk.IsRewardedAdReady(adRewardUnitId))
|
|
{
|
|
Debug.Log(Tag + "==================== ShowRewardedAd");
|
|
|
|
_rewardCallback = callback;
|
|
_rewardOK = false;
|
|
MaxSdk.ShowRewardedAd(adRewardUnitId);
|
|
}
|
|
}
|
|
|
|
|
|
public bool IsInterstitialReady()
|
|
{
|
|
return MaxSdk.IsInterstitialReady(adInterstitialUnitId);
|
|
}
|
|
|
|
public void ShowInterstitial(Action<int> callback = null)
|
|
{
|
|
if (MaxSdk.IsInterstitialReady(adInterstitialUnitId))
|
|
{
|
|
_interstitialAdCallback = callback;
|
|
MaxSdk.ShowInterstitial(adInterstitialUnitId);
|
|
}
|
|
}
|
|
|
|
|
|
public void ShowBanner()
|
|
{
|
|
MaxSdk.ShowBanner(bannerAdUnitId);
|
|
MaxSdk.StartBannerAutoRefresh(bannerAdUnitId);
|
|
}
|
|
|
|
public void HideBanner()
|
|
{
|
|
MaxSdk.StopBannerAutoRefresh(bannerAdUnitId);
|
|
MaxSdk.HideBanner(bannerAdUnitId);
|
|
}
|
|
|
|
public void DestroyBanner()
|
|
{
|
|
MaxSdk.DestroyBanner(bannerAdUnitId);
|
|
}
|
|
|
|
public bool IsPrivacyOptionsRequired()
|
|
{
|
|
#if UNITY_IOS || UNITY_IPHONE
|
|
return BF.BFUMPManager.IsPrivacyOptionsRequired();
|
|
#elif UNITY_ANDROID && !UNITY_EDITOR
|
|
return BF.BFMain.Instance.SDKMgr.BFNativeSDKMgr.IsPrivacyOptionsRequired();
|
|
#else
|
|
return false;
|
|
#endif
|
|
}
|
|
|
|
public void ShowPrivacyOptionsForm()
|
|
{
|
|
#if UNITY_IOS || UNITY_IPHONE
|
|
BF.BFUMPManager.ShowPrivacyOptionsForm();
|
|
#elif UNITY_ANDROID && !UNITY_EDITOR
|
|
BF.BFMain.Instance.SDKMgr.BFNativeSDKMgr.ShowPrivacyOptionsForm();
|
|
#endif
|
|
}
|
|
|
|
public bool CheckCanRequestAds()
|
|
{
|
|
#if UNITY_IOS || UNITY_IPHONE
|
|
return BF.BFUMPManager.IsPrivacyOptionsRequired();
|
|
#elif UNITY_ANDROID && !UNITY_EDITOR
|
|
return BF.BFMain.Instance.SDKMgr.BFNativeSDKMgr.IsPrivacyOptionsRequired();
|
|
#else
|
|
return true;
|
|
#endif
|
|
}
|
|
}
|