Playmaker Forum

PlayMaker Feedback => Action Requests => Topic started by: Sonic Punch Studio on November 22, 2013, 02:49:54 AM

Title: AdMob actions
Post by: Sonic Punch Studio 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
Title: Re: AdMob actions
Post by: Sonic Punch Studio on November 23, 2013, 05:29:21 AM
Bump. Aren't there anyone that can help me? :(
Title: Re: AdMob actions
Post by: Sonic Punch Studio on November 24, 2013, 07:29:45 PM
Bump. Really need some help here.
Title: Re: AdMob actions
Post by: TIGGYsmalls on November 25, 2013, 11:25:37 AM
I would like some actions for this too.
Title: Re: AdMob actions
Post by: Sonic Punch Studio 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.)
Title: Re: AdMob actions
Post by: jeanfabre 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
Title: Re: AdMob actions
Post by: TIGGYsmalls 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.
Title: Re: AdMob actions
Post by: jeanfabre 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
Title: Re: AdMob actions
Post by: Sonic Punch Studio 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
Title: Re: AdMob actions
Post by: TIGGYsmalls 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.
Title: Re: AdMob actions
Post by: jeanfabre 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
Title: Re: AdMob actions
Post by: Nitrohex 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
Title: Re: AdMob actions
Post by: TIGGYsmalls 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.
Title: Re: AdMob actions
Post by: Nitrohex 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.
Title: Re: AdMob actions
Post by: TIGGYsmalls 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).
Title: Re: AdMob actions
Post by: Nitrohex on December 05, 2013, 11:37:45 AM
Ok, i will try this out.

Thanks
Title: Re: AdMob actions
Post by: TIGGYsmalls on December 05, 2013, 11:53:48 AM
Ok, it works fine on my phone, you can play the game and see the ads working but it wont run in Unity properly. I get this error.

JNI: Unable to find method id for 'getName'
UnityEngine.AndroidJavaObject:CallStatic(String, Object[])
AdvertisementHandler:HideAds() (at Assets/Plugins/AdMob/AdvertisementHandler.cs:97)

Title: Re: AdMob actions
Post by: jeanfabre on December 05, 2013, 11:56:23 AM
Hi,

Have you passed this issue to the author? I think he will know what it means. I haven't yet developped for android, so can't really give you any hints...

bye,

Jean
Title: Re: AdMob actions
Post by: Nitrohex on December 05, 2013, 01:48:18 PM
Ok, it works fine on my phone, you can play the game and see the ads working but it wont run in Unity properly. I get this error.

JNI: Unable to find method id for 'getName'
UnityEngine.AndroidJavaObject:CallStatic(String, Object[])
AdvertisementHandler:HideAds() (at Assets/Plugins/AdMob/AdvertisementHandler.cs:97)

I think the plugin does not work in the editor, you should try on a device or emulator (i use bluestacks)


Title: Re: AdMob actions
Post by: MrMitch on February 18, 2014, 10:18:21 PM
The actions didn't work for me because there doesn't appear to be an AdvertisementHandler.cs included with the newer package, but i did notice that in the new package there is AdmobAd.cs so i went into that and i think i've solved the problem.

I've emailed NeatPlug to make sure the action is calling on the correct thing as i know next to nothing about scripting but it seems to work fine with the tests i've done.

Show Ad
Code: [Select]
using System;

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

public class ShowAdBanner : FsmStateAction {

public override void OnEnter(){
AdmobAdAndroid.Instance().ShowBannerAd();

Finish();

}
}

}


Hide Ad
Code: [Select]
using System;

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

public class HideAdBanner : FsmStateAction {

public override void OnEnter(){
AdmobAdAndroid.Instance().HideBannerAd();

Finish();
}
}
}
Title: Re: AdMob actions
Post by: bizilux on February 25, 2014, 06:22:39 PM
so will there ever be any actions for some plugin that displays admob interstitial ads...?

i mean this to me looks like quite highly requested thing... this topic was read 800 times for example, not to mention other similar topics...

so these 2 actions will work for showing interstitial ad, if i buy neatplug.com AdMob Ads Plugin???
Title: Re: AdMob actions
Post by: MrMitch on February 25, 2014, 08:01:28 PM
so will there ever be any actions for some plugin that displays admob interstitial ads...?

i mean this to me looks like quite highly requested thing... this topic was read 800 times for example, not to mention other similar topics...

so these 2 actions will work for showing interstitial ad, if i buy neatplug.com AdMob Ads Plugin???

No, these are for controlling Banner Ads.

I plan to look into Interstitial Ads, if i manage to get it working i'll post them here.
Title: Re: AdMob actions
Post by: bizilux on February 26, 2014, 05:05:31 AM
ah such a bummer... well hopefully you will have some luck...