Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. On February 28th the Feedback website will shut down and be redirected to the Unity forums. See the full post for more information.
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Unity 2018.3 is now released.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Monetization 3.0 on mobile

Discussion in 'Unity Ads' started by piggybank1974, Feb 2, 2019.

  1. piggybank1974

    piggybank1974

    Joined:
    Dec 15, 2015
    Posts:
    513
    On my other games I've used the version 2.0 of the ad system, so I decided on the new app, to look into Monetization 3.0, as v2 is outdated.

    Anyways I've set the app up on the dashboard including enabling the service using the services tab, I've also made sure it's in test mode on the dashboard, no matter what mode the app is in.

    I came up with the following code.

    Code (CSharp):
    1.  
    2. namespace Scenes.MenuScene
    3. {
    4. public class AdManagerComponent : MonoBehaviour
    5. {
    6.   private String[] mAdTypes = new String[] { "none", "rewardedVideo", "video" };
    7.   private Boolean mIsReady;
    8.  
    9.   public String GameID = String.Empty;
    10.  
    11.   public AdTypes AdType = AdTypes.RewardVideo;
    12.  
    13.   public event EventHandler<AdResultEventArgs> AdResult;
    14.   public event EventHandler IsReady;
    15.  
    16.   protected virtual void OnIsReady(EventArgs e)
    17.   {
    18.    EventHandler handler = IsReady;
    19.    if (handler != null)
    20.     handler(this, e);
    21.   }
    22.  
    23.   protected virtual void OnAdResult(AdResultEventArgs e)
    24.   {
    25.    EventHandler<AdResultEventArgs> handler = AdResult;
    26.    if (handler != null)
    27.     handler(this, e);
    28.   }
    29.  
    30.   private void OnEnable()
    31.   {
    32.    mIsReady = false;
    33.  
    34.    if (String.IsNullOrEmpty(GameID) == false && Monetization.isSupported == true)
    35.     Monetization.Initialize(GameID, true);
    36.   }
    37.  
    38.   void Update()
    39.   {
    40.    if (AdType != AdTypes.none && mIsReady == false)
    41.      {
    42.       mIsReady = Monetization.IsReady(mAdTypes[(Int32)AdType]);
    43.       if (mIsReady == true)
    44.        OnIsReady(EventArgs.Empty);
    45.      }
    46.  
    47.   }
    48.  
    49.   public void ShowAdvert()
    50.   {
    51.    ShowAdCallbacks mShowAd = new ShowAdCallbacks();
    52.    mShowAd.finishCallback = ShowAd_finishCallback;
    53.    ShowAdPlacementContent mAdvert = Monetization.GetPlacementContent(mAdTypes[(Int32)AdType]) as ShowAdPlacementContent;
    54.    if (mAdvert != null)
    55.     mAdvert.Show(mShowAd);
    56.   }
    57.  
    58.   void ShowAd_finishCallback(ShowResult result)
    59.   {
    60.    OnAdResult(new AdResultEventArgs(result));
    61.   }
    62. }
    63. }
    Now on the desktop I see the ad screen display, and I can close it down and an event gets fired allow me to carry on etc, view another button actually.

    I've built the project "Android apk" , and installed it on one of my devices, but I just cannot get the app to show the advert on a device, so I can check it's all working before I release it.

    I only enable the script when I user want to view the ad hence the OnEnable method, and disable it once it's been seen or they have already watched an ad previously so it's already unlocked if you will, for several hours.

    Also the app is not published on the android app store so I cannot add the package name to the platform, would this be a problem for testing?

    Cheers
     
  2. DenisasK

    DenisasK

    Unity Technologies

    Joined:
    Oct 13, 2016
    Posts:
    64
    Hello @piggybank1974 ,

    Please, turn off ads from the service window and initialize a gameID via code. It should solve the issue.
     
  3. piggybank1974

    piggybank1974

    Joined:
    Dec 15, 2015
    Posts:
    513
    @DenisasK

    I figured out what the problem was, I happen to leave my app running, on my desk, I did see it work, the problem was I was not giving enough time for initialisation to work, "Monetization.Initialize" I moved it to the splash screen, where 5/8 seconds was enough to get it moving in the right direction.

    I've seen the package Manger version of the Ads but I'm blowed if I can work out how to use it, I wish unity would produce a video on this, there are 3 different way to utilise ads, and it's confusing to say the least.

    Thanks for the reply.