Esempio n. 1
0
    /**
     * Instance method.
     */
    public static AdmobAd Instance()
    {
        if (_instance == null)
        {
            _instance = new AdmobAd();
        }

        return(_instance);
    }
Esempio n. 2
0
    // When interstitial window opens
    void OnPresentScreenInterstitial()
    {
        isInterstitialReady   = false;
        isInterstitialVisible = true;

        if (hideBannerOnInterstitial)
        {
            AdmobAd.Instance().HideBannerAd();
        }
    }
Esempio n. 3
0
    // Hide the banner advert from view
    public void hideBanner(bool overlapScreen = false)
    {
        // If this is an overlapping screen then remember the current banner state for when we close the overlapping window
        if (overlapScreen)
        {
            memBannerState = isBannerVisible;
        }

        // Just hiding the banner, it can also be re-shown again
        AdmobAd.Instance().HideBannerAd();
    }
Esempio n. 4
0
 // Show the banner advert
 public void showBanner(bool overlapScreen = false, bool force = false)
 {
     // If this is not an overlapping screen with the previous banner state as hidden
     if (!(overlapScreen && !memBannerState))
     {
         // Make sure we have a ready banner or we are forcing it
         if (isBannerReady || force)
         {
             AdmobAd.Instance().ShowBannerAd();
         }
     }
 }
Esempio n. 5
0
 void Awake()
 {
     if (_instanceFound)
     {
         Destroy(gameObject);
         return;
     }
     _instanceFound = true;
     // The gameObject will retain...
     DontDestroyOnLoad(this);
     AdmobAd.Instance();
 }
Esempio n. 6
0
    // Load a interstitial advert from Google
    public void loadInterstitial(bool displayImmediately)
    {
        // Make sure there isn't already an interstitial advert loading or ready
        if (!isInterstitialLoading && !isInterstitialReady)
        {
            // Load the interstitial and send the displayImmediately bool
            AdmobAd.Instance().LoadInterstitialAd(!displayImmediately);

            // Set the interstitial loading variable so we know we have a interstitial loading
            isInterstitialLoading = true;
        }
    }
Esempio n. 7
0
 // Show the interstitial we have loaded
 public void showInterstitial(bool force = false)
 {
     // Make sure we have a ready interstitial or we are forcing it
     if (isInterstitialReady || force)
     {
         AdmobAd.Instance().ShowInterstitialAd();
     }
     else
     {
         GoogleAnalytics.Instance.LogError("Interstital was requested but it wasn't ready", false);
     }
 }
Esempio n. 8
0
    // When interstitial window is closed (Via hardware back button or clicking the X)
    void OnDismissScreenInterstitial()
    {
        isInterstitialVisible = false;

        if (hideBannerOnInterstitial)
        {
            AdmobAd.Instance().ShowBannerAd();
        }

        if (keepInterstitialsLoaded)
        {
            loadInterstitial(false);
        }
    }
Esempio n. 9
0
    void Awake()
    {
        if (!Instance)
        {
            Instance = this;
            DontDestroyOnLoad(this);
        }
        else
        {
            Destroy(this.gameObject);
            Debug.LogWarning("You have duplicate AdMob Managers in your scene!");
        }

        AdmobAdAgent.RetainGameObject(ref _instanceFound, gameObject, null);
        AdmobAd.Instance();
    }
Esempio n. 10
0
    // Load a banner advert from Google
    public void loadBanner(AdmobAd.BannerAdType adSize, AdmobAd.AdLayout adPosition, bool displayImmediately = false)
    {
        // Make sure there isn't already a banner advert loading or ready
        if (!isBannerLoading && !isBannerReady)
        {
            // Load the banner advert with adSize and adPosition as requested
            AdmobAd.Instance().LoadBannerAd(adSize, adPosition);

            // Set the banner loading variable so we know we have a banner loading
            isBannerLoading = true;
        }

        if (displayImmediately)
        {
            showBanner(false, true);
        }
    }
    void Awake()
    {
        if (Instance)
        {
            DebugLog("You have duplicate AdMob_Manager.cs scripts in your scene! Admob might not work as expected!");
            Destroy(gameObject);
            return;
        }

        Instance = this;
        DontDestroyOnLoad(this);

        if (EnableAdMob)
        {
            AdmobAdAgent.RetainGameObject(ref AdMobAndroidReady, gameObject, null);
            AdIns = AdmobAd.Instance();
        }
    }
Esempio n. 12
0
    void Start()
    {
        // Set the banner ID and interstitial ID for this app
        AdmobAd.Instance().Init(bannerID, interstitialID);

        // Check if adverts are enabled
        isAdvertsEnabled = AdmobAd.Instance().IsAdEnabled();

        if (!isAdvertsEnabled)
        {
            enableAllAds();
        }

        // LoadInterstitialAd takes a boolean stating if it should hold the advert until manually shown or not
        if (loadInterstitialOnStart)
        {
            loadInterstitial(showInterstitialOnStart);
        }
    }
    void Start()
    {
        // Set the banner ID and interstitial ID for this app
        AdmobAd.Instance().Init(bannerID, interstitialID);

        // Check if adverts are enabled
        isAdvertsEnabled = AdmobAd.Instance().IsAdEnabled();
        //TODO: my inserts
        loadBanner(AdmobAd.BannerAdType.Universal_Banner_320x50, AdmobAd.AdLayout.Top_Centered, true);
        ////////////////
        if (!isAdvertsEnabled)
        {
            enableAllAds();
        }

        // LoadInterstitialAd takes a boolean stating if it should hold the advert until manually shown or not
        if (loadInterstitialOnStart)
        {
            loadInterstitial(showInterstitialOnStart);
        }
        //StartCoroutine(AdMob_Manager.Instance.waitForInterstitialLoad());
    }
Esempio n. 14
0
	// Load a banner advert from Google
	public void loadBanner(AdmobAd.BannerAdType adSize, AdmobAd.AdLayout adPosition, bool displayImmediately = false)
	{
		// Make sure there isn't already a banner advert loading or ready
		if(!isBannerLoading && !isBannerReady){
			// Load the banner advert with adSize and adPosition as requested
			AdmobAd.Instance().LoadBannerAd(adSize, adPosition);
			
			// Set the banner loading variable so we know we have a banner loading
			isBannerLoading = true;
		}
		
		if(displayImmediately)
			showBanner(false, true);
	}
Esempio n. 15
0
 public void enableAllAds()
 {
     AdmobAd.Instance().EnableAd();
     isAdvertsEnabled = true;
 }
Esempio n. 16
0
 // Disable all interstitials and banner adverts
 public void disableAllAds()
 {
     AdmobAd.Instance().DisableAd();
     isAdvertsEnabled = false;
 }
    void Awake()
    {
        if(Instance){
            DebugLog("You have duplicate AdMob_Manager.cs scripts in your scene! Admob might not work as expected!");
            Destroy (gameObject);
            return;
        }

        Instance = this;
        DontDestroyOnLoad(this);

        if(EnableAdMob){
            AdmobAdAgent.RetainGameObject(ref AdMobAndroidReady, gameObject, null);
            AdIns = AdmobAd.Instance();
        }
    }
Esempio n. 18
0
    void OnGUI()
    {
        if (UnityEngine.GUI.Button(new Rect(10f, 100f, _buttonWidth, _buttonHeight), "Hide Banner"))
        {
            AdmobAd.Instance().HideBannerAd();
        }

        if (UnityEngine.GUI.Button(new Rect(20f + _buttonWidth, 100f, _buttonWidth, _buttonHeight), "Show Banner"))
        {
            AdmobAd.Instance().ShowBannerAd();
        }

        if (UnityEngine.GUI.Button(new Rect(30f + 2f * _buttonWidth, 100f, _buttonWidth, _buttonHeight), "Destroy Banner"))
        {
            AdmobAd.Instance().DestroyBannerAd();
        }

        if (UnityEngine.GUI.Button(new Rect(10f, 200f, _buttonWidth, _buttonHeight), "Load Banner (Bottom)"))
        {
            AdmobAd.Instance().LoadBannerAd(AdmobAd.BannerAdType.Universal_SmartBanner, AdmobAd.AdLayout.Bottom_Centered);
        }

        if (UnityEngine.GUI.Button(new Rect(20f + _buttonWidth, 200f, _buttonWidth, _buttonHeight), "Load Banner (Top)"))
        {
            AdmobAd.Instance().LoadBannerAd(AdmobAd.BannerAdType.Universal_SmartBanner, AdmobAd.AdLayout.Top_Centered);
        }

        if (UnityEngine.GUI.Button(new Rect(30f + 2f * _buttonWidth, 200f, _buttonWidth, _buttonHeight), "Load Banner (MRect Center)"))
        {
            AdmobAd.Instance().LoadBannerAd(AdmobAd.BannerAdType.Tablets_IAB_MRect_300x250, AdmobAd.AdLayout.Middle_Centered);
        }


        if (UnityEngine.GUI.Button(new Rect(10f, 300f, _buttonWidth, _buttonHeight), "Load Banner (Bottom)\nWith Offset (0, 100)"))
        {
            AdmobAd.Instance().LoadBannerAd(AdmobAd.BannerAdType.Universal_SmartBanner, AdmobAd.AdLayout.Bottom_Centered, 0, 100, false, null);
        }

        if (UnityEngine.GUI.Button(new Rect(20f + _buttonWidth, 300f, _buttonWidth, _buttonHeight), "Load Banner (Top)\nWith Offset (0, 100)"))
        {
            AdmobAd.Instance().LoadBannerAd(AdmobAd.BannerAdType.Universal_SmartBanner, AdmobAd.AdLayout.Top_Centered, 0, 100, false, null);
        }

        if (UnityEngine.GUI.Button(new Rect(30f + 2f * _buttonWidth, 300f, _buttonWidth, _buttonHeight), "Move to Top"))
        {
            AdmobAd.Instance().RepositionBannerAd(AdmobAd.AdLayout.Top_Centered);
        }

        if (UnityEngine.GUI.Button(new Rect(10f, 400f, _buttonWidth, _buttonHeight), "Load & Show Interstitial"))
        {
            AdmobAd.Instance().LoadInterstitialAd(false);
        }

        if (UnityEngine.GUI.Button(new Rect(20f + _buttonWidth, 400f, _buttonWidth, _buttonHeight), "Load & Hide Interstitial"))
        {
            AdmobAd.Instance().LoadInterstitialAd(true);
        }

        if (UnityEngine.GUI.Button(new Rect(30f + 2f * _buttonWidth, 400f, _buttonWidth, _buttonHeight), "Show Interstitial"))
        {
            AdmobAd.Instance().ShowInterstitialAd();
        }
    }
    // public void DestroyInterstitial() // Not supported by NeatPlug!
    /// <summary>
    /// Loads a banner advert into memory.
    /// </summary>
    /// <param name="AdType">Admob banner ad type.</param>
    /// <param name="AdLayout">Admob ad position.</param>
    /// <param name="DisplayImmediately">If set to <c>true</c> display the banner immediately when it has finished loading.</param>
    /// <param name="AdChildDirected">Ad child directed.</param>
    public void LoadBanner(AdmobAd.BannerAdType AdType, AdmobAd.AdLayout AdLayout, bool DisplayImmediately = false, AdmobAd.TagForChildrenDirectedTreatment AdChildDirected = AdmobAd.TagForChildrenDirectedTreatment.Unset)
    {
        if(!EnableAdMob)
            return;

        // Get the name of the current method
        string MethodName = "LoadBanner";

        DebugLog(MethodName + " called");

        // Update the state items (Values used to determine if the action in this method should be ran)
        ActionState[MethodName].UpdateItems(new List<bool>(){ !BannerIsLoading, !BannerIsReady, !BannerIsVisible });

        // Check if we can perform the action for the current method
        if(CanPerformAction(MethodName, ActionState[MethodName].items)){
            // Mark the banner as loading
            BannerIsLoading = true;

            // If we want to display the banner as soon as it's loaded then mark the wanted visible variable as true
            BannerWantedVisible = DisplayImmediately;

            // Load a banner ad marking it as hidden, this script will handle showing the banner
            AdIns.LoadBannerAd(AdType, AdLayout, Vector2.zero, true, new Dictionary<string, string>(), AdChildDirected);

            BannerInMemoryType = AdType;
            BannerInMemoryLayout = AdLayout;
        } else {
            // We already have a banner loading, ready or visible.. if we tried to load the same banner type maybe reposition or simply ShowBanner would be better here
            if(AdType == BannerInMemoryType){
                if(AdLayout != BannerInMemoryLayout)
                    RepositionBanner(0, 0, AdLayout);

                if(DisplayImmediately)
                    ShowBanner();
            }
        }
    }
    /// <summary>
    /// Repositions the banner.
    /// </summary>
    /// <param name="xPos">X position.</param>
    /// <param name="yPos">Y position.</param>
    /// <param name="AdLayout">Admob ad position.</param>
    public void RepositionBanner(int xPos, int yPos, AdmobAd.AdLayout AdLayout = AdmobAd.AdLayout.Top_Left)
    {
        if(!EnableAdMob)
            return;

        // Get the name of the current method
        string MethodName = "RepositionBanner";

        DebugLog(MethodName + " called");

        // Update the state items (Values used to determine if the action in this method should be ran)
        ActionState[MethodName].UpdateItems(new List<bool>(){ BannerIsReady });

        // Check if we can perform the action for the current method
        if(CanPerformAction(MethodName, ActionState[MethodName].items)){
            // Reposition the banner
            AdIns.RepositionBannerAd(AdLayout, xPos, yPos);
        }
    }
Esempio n. 21
0
 // Load a new banner advert
 public void refreshBanner()
 {
     // Note: Not yet sure if the banner is hidden whilst this loads a new ad or if the previous banner stays until refreshed
     AdmobAd.Instance().RefreshBannerAd();
 }
Esempio n. 22
0
 void Awake()
 {
     // Do not modify the codes below.
     AdmobAdAgent.RetainGameObject(ref _instanceFound, gameObject, null);
     AdmobAd.Instance();
 }
Esempio n. 23
0
    // Destroy the banner advert
    public void destroyBanner()
    {
        isBannerReady = false;

        AdmobAd.Instance().DestroyBannerAd();
    }