Advertising - VirtueSky/sunflower GitHub Wiki
Advertising for unity
(Tested with applovin > v5.11.3 and google admob > v8.5.2)
Use
Setting
Open tab Advertising in Magic Panel
- Create AdClient and AdVariable
- Choose AdNetwork Max or Admob
- You can click install sdk if your project doesn't have it yet.
- Add Scripting Define Symbols to use
Set id for AdUnitVariable
(For Admob, you can get the test Id by going to Context Menu
and selecting Get Id Test
)
Advertising
to the object in the scene to load the ads
Attach Script show ads (demo)
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using VirtueSky.Ads;
public class AdsManager : MonoBehaviour
{
public TextMeshProUGUI textNoti;
public AdUnitVariable banner;
public AdUnitVariable inter;
public AdUnitVariable reward;
public void ShowBanner()
{
Debug.Log(banner.IsReady());
banner.Show();
}
public void ShowInter()
{
if (inter.IsReady())
{
LogMessage("inter is ready");
inter.Show().OnCompleted(() => { LogMessage("inter is completed"); });
}
else
{
LogMessage("Inter is not ready");
}
}
public void ShowReward()
{
if (reward.IsReady())
{
LogMessage("reward is ready");
reward.Show().OnCompleted(() => { LogMessage("Reward is completed"); }).OnSkipped(() => { LogMessage("reward is skipped"); });
}
else
{
LogMessage("reward is not ready");
}
}
void LogMessage(string message)
{
textNoti.text = message;
Debug.Log(message);
}
}
Enable GDPR
Note: If - Android: Advertising will only be initialized after user consent allows requesting ads.
- iOS: If ATT is authorized, GDPR compliance will be initialized, and advertising will only be initialized after user consent allows requesting ads. If ATT is not authorized, GDPR compliance will not be initialized, and advertising will proceed without GDPR conditions.
- When using GDPR, make sure you have created the GDPR message in Admob
- Advertising is successfully initialized only when the Android logcat shows
currentAdClient: ...