EasyAdmob is Unity editor plugin helps you to embed Admob units with simple code without getting inside hardcore programming.
include banner, interstitial and rewarded ads.
handling ads callbacks.
setup ad request.
Ad custom size.
Ad custom pos.
Mediation Extra.
Ad Birthday.
To setup admob you need at lest one ad unit(banner, interstitial or rewarded). After creating ad unit copy ad app id and ad unit id.
Open your unity project and import EasyAdmob package and drag EasyAdmob to your loading scene if you don't select your build platform yet you should see platform select inside EasyAdmob inspector window then select it after that EasyAdmob update it's inspector window it should look like this:
it's easy and simple to add ad app and unit ids. IOs and Android ad units ids are speared and auto saved so you don't have to worry about losing your EasyAdmob configuration while you are switching between platforms.
EasyAdmob depend on Google Admob Library for unity so you must to download it. To download this library click on Google Admob Library and download the latest version.
there are three types of callbacks function :
With EventArgs as parameter.
With AdFaildToLoadEventArgs as parameter.
With Reward as parameter.
you need to create your functions to receive this types of parameters in this tutorial we will take Rewarded Ads as example.
first check rewarded ad box in the inspector window, Then create a C# script file with the name "AdsManager". After that, Create your functions and handle the callbacks inside your code.
The following code is a prototype for the basic code to handle and use rewarded ad inside your unity project.
using UnityEngine;
using UnityEngine.UI;
using EasyAdmob;
using GoogleMobileAds.Api;
using System;
public class TestScript : MonoBehaviour
{
enum AdStatus
{
Init,
Worked,
Faild,
Rewarded
}
AdStatus RAdStatus;
public Button RewardedAdB;
public Text RewardedLog;
// Use this for initialization
void Start()
{
// Add listener to rewarded ad button;
RewardedAdB.onClick.AddListener(() => {
EasyAdmobLib.Instance.ShowRewardedAd(); // Use this to show Rewarded Ad anywhere in your code.
Debug.Log("Reward ad btn click"); });
}
private void Update()
{
RewardedLog.text = RAdStatus.ToString();
}
public void OnRewardedAdEvent( EventArgs e)
{
RAdStatus = AdStatus.Worked;
Debug.Log("Ad rewarded event received." + e.ToString());
}
public void OnRewardedAdFEvent( AdFailedToLoadEventArgs e)
{
RAdStatus = AdStatus.Faild;
Debug.Log("Ad rewarded faild event received.");
}
public void OnRewardedAdREvent( Reward e)
{
RAdStatus = AdStatus.Rewarded;
Debug.Log("Ad rewarded reward received - " + e.Type + "|" + e.Amount);
}
}
after that attach your script to any gameobject in your scene.
To add callbacks to one of EasyAdmob events it must have the same parameter type, click plus button on the right of the event you want to receive a callback from after that click the circle on the left of event window then select your gameobject with your script attached to it. After that from the drop down menu pick up your callback. Thats it all.
you can access EasyAdmob library inside your code by typing "EasyAdmobLib.Instance." followed by the parameter or function you want to Access.
public void ShowBannerAd() use this to show banner ad you should call it once inside your project.
public void ShowInterstitialAd() use this to show interstitial ad you should call it once inside your project.
public void ShowRewardedAd()use this to show Rewarded ad you should call it once inside your project.
public Reward GetReward() use this to receive the last Reward you can use it to get the last reward.
Instance use it to access EasyAdmob Functions and members.
EasyAdmob Ids:
public string AAppId = "";
public string ABannerId = "";
public string AInterstitialId = "";
public string ARewardedId = "";
public string IAppId = "";
public string IBannerId = "";
public string IInterstitialId = "";
public string IRewardedId = "";
EasyAdmob Ad Request Members:
public Gender gender;
public bool childDirectedtreatment;
public string keywords;
public string extraKey;
public string extraValue;
public string testDeviceId;
public AdPosition adPosition;
public EasyAdSize size;
EasyAdmob Events:
public ObjArgEvent BOnAdClosed.
public ObjArgEvent BOnAdLoaded.
public ObjArgEvent BOnAdOpening.
public ObjAdFEvent BOnAdFailedToLoad.
public ObjArgEvent BOnAdLeavingApplication.
public ObjArgEvent IOnAdClosed.
public ObjArgEvent IOnAdLoaded.
public ObjArgEvent IOnAdOpening.
public ObjAdFEvent IOnAdFailedToLoad.
public ObjArgEvent IOnAdLeavingApplication.
public ObjArgEvent ROnAdStarted.
public ObjArgEvent ROnAdClosed.
public ObjArgEvent ROnAdLoaded.
public ObjArgEvent ROnAdOpening.
public ObjAdFEvent ROnAdFailedToLoad.
public ObjRewEvent ROnAdRewarded.
public ObjArgEvent ROnAdLeavingApplication.
EasyAdmob bool's:
public bool BannerAd, interstitialAdb, RewardedAd use the to activate ad units.
public bool isAndroid use it to select Android platform.
public bool isIOS use it to select IOs platform.
All Copyrights are reserved
E.Yazan Mamon Suliman