Skip to content

ChrisTJie/googleads-mobile-unity-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

85 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

** This project is currently on hold and I hope to have more time to update this project :( **

Google Mobile Ads Example for Unity

Features

  • Easy to use
  • Operation interface
  • Ad formats support:
    • Banner
    • Interstitial
    • Rewarded
    • Rewarded interstitial
    • (Optional) Native Ads Advanced (Unified)

Environment

  • Unity 2020.3.11f1
  • External Dependency Manager for Unity v1.2.165
  • Google Mobile Ads Unity Plugin v6.0.0
  • (Optional) Google Mobile Ads Unity Plugin v5.4.0.90
    • Contains Native Ads Advanced (Unified) functions

Requirements

  • Unity 2020 (LTS) and above.
  • Google Mobile Ads Unity Plugin v6.0.0
  • (Optional) Native ads build of the Unity plugin.
    • Require native ads build of the Google Mobile Ads Unity plugin to support Native Ads Advanced.
  • Mediation Test Suite plugin.
    • Currently Google Mobile Ads Mediation Test Suite does not support Google Mobile Ads Unity Plugin v6.0.0

Installation

  1. Download and Import Package.
  2. Adding an Ads Object to the scene.

2021-06-02-142858

Interface

  • Banner
  • Interstitial
  • Rewarded
  • Rewarded interstitial

image

  • (Optional) Native Ads Advanced (Unified)

image

Example Code

  • Manually request ads.
CTJ.Ads.Instance.RequestBanner();
CTJ.Ads.Instance.RequestInterstitial();
CTJ.Ads.Instance.RequestRewarded();
CTJ.Ads.Instance.RequestRewardedInterstitial();
CTJ.Ads.Instance.RequestNative(); // Optional
CTJ.Ads.Instance.ForceRequestNative(); // Optional
  • Show ads.
CTJ.Ads.Instance.ShowBannerAd();
CTJ.Ads.Instance.ShowInterstitialAd();
CTJ.Ads.Instance.ShowRewardedAd();
CTJ.Ads.Instance.ShowRewardedInterstitialAd();
CTJ.Ads.Instance.ShowMediationTestSuite(); // Optional
  • Destroy ads.
CTJ.Ads.Instance.DestroyBannerAd();
CTJ.Ads.Instance.DestroyInterstitialAd();
CTJ.Ads.Instance.DestroyUnifiedNativeAd(); // Optional
  • (Optional) Initialize native ads.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Demo : MonoBehaviour
{
    [SerializeField] private GameObject _NativeObject;
    [SerializeField] private GameObject _AdChoicesLogo;
    [SerializeField] private GameObject _Advertiser;
    [SerializeField] private GameObject _Body;
    [SerializeField] private GameObject _CallToAction;
    [SerializeField] private GameObject _Headline;
    [SerializeField] private GameObject _Icon;

    private void Start()
    {
        _NativeObject.SetActive(false);
        CTJ.Ads.Instance.EventAddListener_NativeInitialize(DemoNativeInitialize);
    }

    public void DemoNativeInitialize()
    {
        _AdChoicesLogo.GetComponent<RawImage>().texture = CTJ.Ads.Instance.GetAdChoicesLogo;
        _Advertiser.GetComponent<Text>().text = CTJ.Ads.Instance.GetAdvertiser;
        _Body.GetComponent<Text>().text = CTJ.Ads.Instance.GetBody;
        _CallToAction.GetComponent<Text>().text = CTJ.Ads.Instance.GetCallToAction;
        _Headline.GetComponent<Text>().text = CTJ.Ads.Instance.GetHeadline;
        _Icon.GetComponent<RawImage>().texture = CTJ.Ads.Instance.GetIcon;
        CTJ.Ads.Instance.RegisterAdChoicesLogo(_AdChoicesLogo);
        CTJ.Ads.Instance.RegisterAdvertiser(_Advertiser);
        CTJ.Ads.Instance.RegisterBody(_Body);
        CTJ.Ads.Instance.RegisterCallToAction(_CallToAction);
        CTJ.Ads.Instance.RegisterHeadline(_Headline);
        CTJ.Ads.Instance.RegisterIcon(_Icon);
        _NativeObject.SetActive(true);
    }
}

Releases

No releases published

Packages

No packages published

Languages