playMaker

Author Topic: AdMob actions  (Read 19963 times)

Sonic Punch Studio

  • Playmaker Newbie
  • *
  • Posts: 21
AdMob actions
« on: November 22, 2013, 02:49:54 AM »
Hi there guys, I've recently purchased and integrated an AdMob plugin from neatplug.com and while it was integrated successfully I now run into a problem of not being able to full control it due to my lack of programming experience.

What I want to do is to be able to hide an ad banner when certain events are triggered (such as pressing a button or entering into another scene). There are other things that can be done with AdMob (as described in the integration guide: http://www.neatplug.com/integration-guide-unity3d-admob-ad-plugin), and I was wondering if anyone could help me in this area.

Other sepcifics: AdMob already works above Unity 3.2 (I currently run Unity 3.5.6f4 and investigating into upgrading 3.5.7 to see if anything breaks) and the plugin I purchased is universal to both Android and iOS. If there's any additional information required I'm happy to provide it.

- Damien
Intense bubble popping action! Get Bubble Virtuoso today!

Trailer:
Purchase: http://tinyurl.com/buyBVnow

Sonic Punch Studio

  • Playmaker Newbie
  • *
  • Posts: 21
Re: AdMob actions
« Reply #1 on: November 23, 2013, 05:29:21 AM »
Bump. Aren't there anyone that can help me? :(
Intense bubble popping action! Get Bubble Virtuoso today!

Trailer:
Purchase: http://tinyurl.com/buyBVnow

Sonic Punch Studio

  • Playmaker Newbie
  • *
  • Posts: 21
Re: AdMob actions
« Reply #2 on: November 24, 2013, 07:29:45 PM »
Bump. Really need some help here.
Intense bubble popping action! Get Bubble Virtuoso today!

Trailer:
Purchase: http://tinyurl.com/buyBVnow

TIGGYsmalls

  • Junior Playmaker
  • **
  • Posts: 80
Re: AdMob actions
« Reply #3 on: November 25, 2013, 11:25:37 AM »
I would like some actions for this too.

Sonic Punch Studio

  • Playmaker Newbie
  • *
  • Posts: 21
Re: AdMob actions
« Reply #4 on: November 26, 2013, 10:40:53 PM »
With some help from a friend of mine, I've managed to put together 2 actions that are specifically compatible for NeatPlug.com's AdMob plugin.

These two actions will allow you to show and hide the ad banner whenever you want.

Needless to say, these actions requires NeatPlug.com's AdMob plugin (universal).

I will look into creating other custom actions for this plugin later down the track, but for now I'm leaving it at these two actions. If anyone else is interested in creating other compatible actions, please feel free to add them to this thread.

Share the love!

- Damien

(Going to leave it unsolved as there are many functions in this plugin that are not yet covered.)
« Last Edit: November 26, 2013, 10:45:48 PM by Sonic Punch Studio »
Intense bubble popping action! Get Bubble Virtuoso today!

Trailer:
Purchase: http://tinyurl.com/buyBVnow

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15594
  • Official Playmaker Support
Re: AdMob actions
« Reply #5 on: November 28, 2013, 02:26:51 AM »
Hi,

 Sorry, I was away attending a game Jam.

 So with these two actions do you have what you need to move forward on this?

bye,

 Jean

TIGGYsmalls

  • Junior Playmaker
  • **
  • Posts: 80
Re: AdMob actions
« Reply #6 on: November 30, 2013, 11:43:45 AM »
Ok, So I took this AdMob package:

http://forum.unity3d.com/threads/173292-Admob-Unity-Package-that-work-with-Unity-3-2-amp-above

And imported into my scene and put the proper code in my Android Manifest and it works if I use the Advertisement Manager.

Then I tried to make my own Action and it doesn't work. Just stops when it get to the action.

Code: [Select]
using System;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("AdMob")]
[Tooltip("Shows the AdMob banner")]

public class ShowAdBanner : FsmStateAction {

public override void OnEnter(){
AdvertisementHandler.ShowAds();

Finish();

}
}
}

NullReferenceException: Object reference not set to an instance of an object
AdvertisementHandler.ShowAds () (at Assets/Scripts/AdvertisementHandler.cs:103)

So?

You have every right to roll your eyes and not help me.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15594
  • Official Playmaker Support
Re: AdMob actions
« Reply #7 on: November 30, 2013, 12:51:20 PM »
Hi,

Where did you get the original code where it uses "AdvertisementHandler", I think you are missing some initialisation and variable assignment.

I don't own AdMob unfortunatly. Maybe you should contact the author to see if he's willing to collaborate so that I can fix this? or maybe he will tell you what's wrong here to begin with.


bye,

 Jean

Sonic Punch Studio

  • Playmaker Newbie
  • *
  • Posts: 21
Re: AdMob actions
« Reply #8 on: November 30, 2013, 11:37:17 PM »
Hi there! Sorry was busy these past few days.

@Jean: These two actions managed to solve some of my problems; "Some" because new unexpected behaviours has arisen during my implementation of the actions. Currently trying to create a new action for an ad load request - it's an ad-hoc solution since I dunno how to create spaces to where you enter integers and have the function refer to those values. Will post what I have once I've got it working for my own needs.

I've tried contacting the author of the NeatPlug.com version of the AdMob unity plugin with my problem but so far he hasn't replied back.

- Damien
Intense bubble popping action! Get Bubble Virtuoso today!

Trailer:
Purchase: http://tinyurl.com/buyBVnow

TIGGYsmalls

  • Junior Playmaker
  • **
  • Posts: 80
Re: AdMob actions
« Reply #9 on: December 02, 2013, 05:48:44 AM »
Code: [Select]
using UnityEngine;
using System.Collections;

public class AdvertisementManager : MonoBehaviour {

    void OnGUI()
    {
        // Make a background box
        GUI.Box(new Rect(10, 10, 100, 90), "Loader Menu");
       
        // Make the Enable Button
        if (GUI.Button(new Rect(20, 40, 80, 20), "Enable"))
        {
            AdvertisementHandler.EnableAds();
        }

        // Make the Disable Button
        if (GUI.Button(new Rect(20, 60, 80, 20), "Disable"))
        {           
            AdvertisementHandler.DisableAds();
        }

        // Make the Hide Button
        if (GUI.Button(new Rect(20, 80, 80, 20), "Hide"))
        {
            AdvertisementHandler.HideAds();
        }

        // Make the Show button.
        if (GUI.Button(new Rect(20, 100, 80, 20), "Show"))
        {
            AdvertisementHandler.ShowAds();
        }

    }

// Use this for initialization
void Start () {
        Debug.Log("Unity Calling Start");
        AdvertisementHandler.Instantiate("a14e2fb60918999", AdvertisementHandler.AdvSize.BANNER, AdvertisementHandler.AdvOrientation.HORIZONTAL, AdvertisementHandler.Position.BOTTOM, AdvertisementHandler.Position.CENTER_HORIZONTAL, false, AdvertisementHandler.AnimationInType.SLIDE_IN_LEFT, AdvertisementHandler.AnimationOutType.FADE_OUT, AdvertisementHandler.LevelOfDebug.LOW);
        AdvertisementHandler.EnableAds();
}

// Update is called once per frame
void Update () {

}
}


This is the code that he used to control the adverts. I'll ask on the unity forums too.

Thank you.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15594
  • Official Playmaker Support
Re: AdMob actions
« Reply #10 on: December 02, 2013, 06:01:34 AM »
Hi,

 no need, check the start method of this script, it instantiate

Code: [Select]
AdvertisementHandler.Instantiate("a14e2fb60918999", AdvertisementHandler.AdvSize.BANNER, AdvertisementHandler.AdvOrientation.HORIZONTAL, AdvertisementHandler.Position.BOTTOM, AdvertisementHandler.Position.CENTER_HORIZONTAL, false, AdvertisementHandler.AnimationInType.SLIDE_IN_LEFT, AdvertisementHandler.AnimationOutType.FADE_OUT, AdvertisementHandler.LevelOfDebug.LOW);
        AdvertisementHandler.EnableAds();

you need to do this as well, likely as another action, so that one action instantiate properly the admob and then work can be done on it.

So, your task right now is to create an action exposing the initialization options of Admob and explain PlayMaker user that they must firt run that action. Do this in each other actions by checking if AdvertisementHandler is ok ( likely checking for null).

bye,

 Jean

Nitrohex

  • Junior Playmaker
  • **
  • Posts: 50
Re: AdMob actions
« Reply #11 on: December 03, 2013, 03:49:20 PM »
Ok, So I took this AdMob package:

http://forum.unity3d.com/threads/173292-Admob-Unity-Package-that-work-with-Unity-3-2-amp-above

And imported into my scene and put the proper code in my Android Manifest and it works if I use the Advertisement Manager.

Then I tried to make my own Action and it doesn't work. Just stops when it get to the action.

Code: [Select]
using System;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("AdMob")]
[Tooltip("Shows the AdMob banner")]

public class ShowAdBanner : FsmStateAction {

public override void OnEnter(){
AdvertisementHandler.ShowAds();

Finish();

}
}
}

NullReferenceException: Object reference not set to an instance of an object
AdvertisementHandler.ShowAds () (at Assets/Scripts/AdvertisementHandler.cs:103)

So?

You have every right to roll your eyes and not help me.

Hi TIGGYsmalls,

I'm new to implementing Admob, i have tried to implement http://forum.unity3d.com/threads/173292-Admob-Unity-Package-that-work-with-Unity-3-2-amp-above plugin, but i'm not sure what should i put in my android manifest file....

Should i delete the AndroidManifest.xml that is in the plugins/android folder or?
Do i need to put the plugin in every scene in order to work in every scene trough out the game?
Do i need playmaker actions in order to make this plugin work?

Could you please elaborate as much as you can on implementing this free admob plugin?

Thanks in advance
Sign Up Now @ StartApp.com

TIGGYsmalls

  • Junior Playmaker
  • **
  • Posts: 80
Re: AdMob actions
« Reply #12 on: December 03, 2013, 04:29:52 PM »
You have to build your game, then look in temp folders for the manifest unity builds for your game.

Code: [Select]
<activity android:name="com.google.ads.AdActivity"

android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

Then you have to put this line of code in before </application> in that manifest then save it to Assets > Plugins > Android. In your project.

Then I'm stuck. You can put the AdvertisementManager.cs script on anything to get the adverts but I don't know how to make actions to control them, that one I've made doesn't work.

Wish I could be of more help.

Nitrohex

  • Junior Playmaker
  • **
  • Posts: 50
Re: AdMob actions
« Reply #13 on: December 03, 2013, 04:56:54 PM »
I did exactly as you wrote, and i put the AdvertisementManager prefab in my first scene, i set my pub. id, ad modes and positions but when i test, my game crashes only when i pick the level that the plugin is in...

Anyway, i appreciate you help on this, hopefully we can solve our issues asap.

Thanks again.
Sign Up Now @ StartApp.com

TIGGYsmalls

  • Junior Playmaker
  • **
  • Posts: 80
Re: AdMob actions
« Reply #14 on: December 05, 2013, 09:55:31 AM »
Start Adverts.

Code: [Select]
using System;


namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("AdMob")]
[Tooltip("Starts AdMob banner")]

public class StartAdBanner : FsmStateAction {

[ActionSection("Setup")]

[RequiredField]
[Tooltip("Google advert account id.")]
public FsmString AdString;



public override void OnEnter(){
AdvertisementHandler.Instantiate(AdString.Value, AdvertisementHandler.AdvSize.BANNER, AdvertisementHandler.AdvOrientation.HORIZONTAL, AdvertisementHandler.Position.BOTTOM, AdvertisementHandler.Position.CENTER_HORIZONTAL, false, AdvertisementHandler.AnimationInType.SLIDE_IN_LEFT, AdvertisementHandler.AnimationOutType.FADE_OUT, AdvertisementHandler.LevelOfDebug.LOW);
        AdvertisementHandler.EnableAds();

Finish();

}
}
}

Show Adverts.

Code: [Select]
using System;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("AdMob")]
[Tooltip("Shows the AdMob banner")]

public class ShowAdBanner : FsmStateAction {

public override void OnEnter(){
AdvertisementHandler.ShowAds();

Finish();

}
}
}

Hide Adverts.

Code: [Select]
using System;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("AdMob")]
[Tooltip("Shows the AdMob banner")]

public class HideAdBanner : FsmStateAction {

public override void OnEnter(){
AdvertisementHandler.HideAds();

Finish();
}
}
}

Ok this does work (somehow).