Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
Google Mobile Ads Unity Plugin Change Log

**************
Version Next
**************

- Added Picture-in-Picture ad support.

**************
Version 11.4.0
**************
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace GoogleMobileAds.Api
{
public enum PictureInPictureAdPosition
{
Default = 0,
BottomRight = 1,
BottomLeft = 2,
TopLeft = 3,
TopRight = 4
}
}
241 changes: 241 additions & 0 deletions source/plugin/Assets/GoogleMobileAds/Api/PictureInPictureAd.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using UnityEngine;
using GoogleMobileAds.Common;

namespace GoogleMobileAds.Api
{
/// <summary>
/// A Picture-in-Picture (PiP) ad that displays in a floating window across screens.
/// </summary>
public class PictureInPictureAd
{
/// <summary>
/// Raised when the ad is estimated to have earned money.
/// </summary>
public event Action<AdValue> OnAdPaid;

/// <summary>
/// Raised when an ad is clicked.
/// </summary>
public event Action OnAdClicked;

/// <summary>
/// Raised when an impression is recorded for an ad.
/// </summary>
public event Action OnAdImpressionRecorded;

/// <summary>
/// Raised when the PiP ad is displayed on the screen.
/// </summary>
public event Action OnAdShown;

/// <summary>
/// Raised when the PiP ad is hidden from the screen.
/// </summary>
public event Action OnAdHidden;

/// <summary>
/// Raised when an ad opened full-screen content.
/// </summary>
public event Action OnAdFullScreenContentOpened;

/// <summary>
/// Raised when the ad closed full-screen content.
/// </summary>
public event Action OnAdFullScreenContentClosed;

protected internal IPictureInPictureAdClient _client;

protected internal PictureInPictureAd() {}

internal PictureInPictureAd(IPictureInPictureAdClient client)
{
_client = client;
RegisterAdEvents();
}

/// <summary>
/// Loads a Picture-in-Picture ad.
/// </summary>
public static void Load(string adUnitId,
AdRequest request,
Action<PictureInPictureAd, LoadAdError> adLoadCallback)
{
if (adLoadCallback == null)
{
Debug.LogError("adLoadCallback is null. No ad was loaded.");
return;
}

var client = MobileAds.GetClientFactory().BuildPictureInPictureAdClient();
client.CreatePictureInPictureAd();
client.OnAdLoaded += (sender, args) =>
{
var pipAd = new PictureInPictureAd(client);
MobileAds.RaiseAction(() =>
{
adLoadCallback(pipAd, null);
});
};
client.OnAdFailedToLoad += (sender, error) =>
{
var loadAdError = (error != null && error.LoadAdErrorClient != null)
? new LoadAdError(error.LoadAdErrorClient)
: null;
MobileAds.RaiseAction(() =>
{
adLoadCallback(null, loadAdError);
});
};
client.LoadAd(adUnitId, request);
}

/// <summary>
/// Shows the Picture-in-Picture ad on the screen at the specified corner position.
/// </summary>
public void Show(PictureInPictureAdPosition position = PictureInPictureAdPosition.Default)
{
if (_client != null)
{
_client.Show(position);
}
}

/// <summary>
/// Hides the Picture-in-Picture ad from the screen.
/// </summary>
public void Hide()
{
if (_client != null)
{
_client.Hide();
}
}

/// <summary>
/// Destroys the Picture-in-Picture ad and cleans up native resources.
/// </summary>
public void Destroy()
{
if (_client != null)
{
_client.Destroy();
}
}

/// <summary>
/// Returns the ResponseInfo for the loaded ad, or null if unavailable.
/// </summary>
public ResponseInfo GetResponseInfo()
{
return _client != null ? new ResponseInfo(_client.GetResponseInfoClient()) : null;
}

/// <summary>
/// Returns the current or last known position of the Picture-in-Picture ad.
/// </summary>
public PictureInPictureAdPosition GetAdPosition()
{
return _client != null ? _client.GetAdPosition() : PictureInPictureAdPosition.Default;
}

private void RegisterAdEvents()
{
if (_client == null)
{
return;
}

_client.OnAdShown += (sender, args) =>
{
MobileAds.RaiseAction(() =>
{
if (OnAdShown != null)
{
OnAdShown();
}
});
};

_client.OnAdHidden += (sender, args) =>
{
MobileAds.RaiseAction(() =>
{
if (OnAdHidden != null)
{
OnAdHidden();
}
});
};

_client.OnAdClicked += () =>
{
MobileAds.RaiseAction(() =>
{
if (OnAdClicked != null)
{
OnAdClicked();
}
});
};

_client.OnAdDidRecordImpression += (sender, args) =>
{
MobileAds.RaiseAction(() =>
{
if (OnAdImpressionRecorded != null)
{
OnAdImpressionRecorded();
}
});
};

_client.OnAdDidPresentFullScreenContent += (sender, args) =>
{
MobileAds.RaiseAction(() =>
{
if (OnAdFullScreenContentOpened != null)
{
OnAdFullScreenContentOpened();
}
});
};

_client.OnAdDidDismissFullScreenContent += (sender, args) =>
{
MobileAds.RaiseAction(() =>
{
if (OnAdFullScreenContentClosed != null)
{
OnAdFullScreenContentClosed();
}
});
};

_client.OnPaidEvent += (adValue) =>
{
MobileAds.RaiseAction(() =>
{
if (OnAdPaid != null)
{
OnAdPaid(adValue);
}
});
};
}
}
}
2 changes: 2 additions & 0 deletions source/plugin/Assets/GoogleMobileAds/Common/IClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public interface IClientFactory

INativeOverlayAdClient BuildNativeOverlayAdClient();

IPictureInPictureAdClient BuildPictureInPictureAdClient();

IApplicationPreferencesClient ApplicationPreferencesInstance();

IMobileAdsClient MobileAdsInstance();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using GoogleMobileAds.Api;

namespace GoogleMobileAds.Common
{
public interface IPictureInPictureAdClient
{
// Ad event fired when the picture in picture ad has loaded.
event EventHandler<EventArgs> OnAdLoaded;
// Ad event fired when the picture in picture ad has failed to load.
event EventHandler<LoadAdErrorClientEventArgs> OnAdFailedToLoad;
// Ad event fired when the picture in picture ad is displayed on screen.
event EventHandler<EventArgs> OnAdShown;
// Ad event fired when the picture in picture ad is hidden from screen.
event EventHandler<EventArgs> OnAdHidden;
// Ad event fired when an ad impression has been recorded.
event EventHandler<EventArgs> OnAdDidRecordImpression;
// Ad event fired when an ad has been clicked.
event Action OnAdClicked;
// Ad event fired when the ad opens an overlay covering the screen.
event EventHandler<EventArgs> OnAdDidPresentFullScreenContent;
// Ad event fired when the ad overlay is dismissed.
event EventHandler<EventArgs> OnAdDidDismissFullScreenContent;
// Ad event fired when the picture in picture ad is estimated to have earned money.
event Action<AdValue> OnPaidEvent;

// Creates a picture in picture ad wrapper.
void CreatePictureInPictureAd();

// Loads a picture in picture ad.
void LoadAd(string adUnitId, AdRequest request);

// Shows the picture in picture ad on screen.
void Show(PictureInPictureAdPosition position);

// Hides the picture in picture ad.
void Hide();

// Destroys the picture in picture ad.
void Destroy();

// Returns the current or last known position of the picture in picture ad.
PictureInPictureAdPosition GetAdPosition();

// Returns the response info for the loaded ad.
IResponseInfoClient GetResponseInfoClient();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ public INativeOverlayAdClient BuildNativeOverlayAdClient()
" on non-Android runtime");
}

public IPictureInPictureAdClient BuildPictureInPictureAdClient()
{
if (Application.platform == RuntimePlatform.Android)
{
return new GoogleMobileAds.Android.PictureInPictureAdClient();
}
throw new InvalidOperationException(@"Called " + MethodBase.GetCurrentMethod().Name +
" on non-Android runtime");
}

public IApplicationPreferencesClient ApplicationPreferencesInstance() {
if (Application.platform == RuntimePlatform.Android) {
return new GoogleMobileAds.Android.ApplicationPreferencesClient();
Expand Down Expand Up @@ -180,7 +190,7 @@ private bool IsNextGenEnabled()
new AndroidJavaClass(GoogleMobileAds.Android.NextGenUtils.MobileAdsClassName);
_nextGenEnabled = true;
}
catch (AndroidJavaException)
catch (Exception)
{
_nextGenEnabled = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ internal class NextGenUtils {
public const string UnityBannerAdCallbackClassName =
"com.google.unity.ads.nextgen.UnityBannerAdCallback";

public const string UnityPictureInPictureAdClassName =
"com.google.unity.ads.nextgen.UnityPictureInPictureAd";
public const string UnityPictureInPictureAdCallbackClassName =
"com.google.unity.ads.nextgen.UnityPictureInPictureAdCallback";

public const string UnityInterstitialAdClassName =
"com.google.unity.ads.nextgen.UnityInterstitialAd";
public const string UnityInterstitialAdCallbackClassName =
Expand Down
Loading