/// <summary> /// Displays an ad in a specified <a href="../manual/MonetizationPlacements.html">Placement</a> if it is ready, and passes a <a href="..api/UnityEngine.Advertisements.ShowResult.html"><c>ShowResult</c></a> enum to the <a href="../api/UnityEngine.Advertisements.ShowOptions.html"><c>ShowOptions.resultCallback</c></a> callback when the ad finishes. /// </summary> /// <param name="placementId">The unique identifier for a specific Placement, found on the <a href="https://operate.dashboard.unity3d.com/">developer dashboard</a>.</param> /// <param name="showOptions">A collection of options, including <c>resultCallback</c>, for modifying ad behavior.</param> public static void Show(string placementId, ShowOptions showOptions) { if (isShowing) { return; } if (showOptions != null) { #pragma warning disable 618 if (showOptions.resultCallback != null) { EventHandler <FinishEventArgs> finishHandler = null; finishHandler = (object sender, FinishEventArgs e) => { showOptions.resultCallback(e.showResult); #pragma warning restore 618 s_Platform.OnFinish -= finishHandler; }; s_Platform.OnFinish += finishHandler; } if (!string.IsNullOrEmpty(showOptions.gamerSid)) { var player = new MetaData("player"); player.Set("server_id", showOptions.gamerSid); SetMetaData(player); } } s_Platform.Show(string.IsNullOrEmpty(placementId) ? null : placementId); }
static public void Show(string zoneId = null, ShowOptions options = null) { #if UNITY_ANDROID || UNITY_IOS UnityAds.SharedInstance.Show(zoneId, options); _handleFinished = null; _handleSkipped = null; _handleFailed = null; _onContinue = null; if (string.IsNullOrEmpty(zoneId)) { zoneId = null; } //ShowOptions option = new ShowOptions(); //option.resultCallback = HandleShowResult; //Advertisement.Show(zoneId,option); #else if (options != null && options.resultCallback != null) { options.resultCallback(ShowResult.Failed); } #endif }
static public void Show(string zoneId = null, ShowOptions options = null) { #if UNITY_ANDROID || UNITY_IOS UnityAds.SharedInstance.Show(zoneId, options); #else if(options != null && options.resultCallback != null) { options.resultCallback(ShowResult.Failed); } #endif }
static public void Show(string zoneId = null, ShowOptions options = null) { #if UNITY_ANDROID || UNITY_IOS UnityAds.SharedInstance.Show(zoneId, options); #else if (options != null && options.resultCallback != null) { options.resultCallback(ShowResult.Failed); } #endif }
public void Show(string zoneId, ShowOptions options) { if(!_initialized) { if(options.resultCallback != null) { options.resultCallback(ShowResult.Failed); } return; } if(!ConfigManager.Instance.IsReady()) { if (ConfigManager.Instance.globalIntervals != null) Event.EventManager.sendMediationCappedEvent(Engine.Instance.AppId, null, "global", ConfigManager.Instance.globalIntervals.NextAvailable()); if(options.resultCallback != null) { options.resultCallback(ShowResult.Failed); } return; } Zone zone = ZoneManager.Instance.GetZone(zoneId); if(zone == null) { if(options.resultCallback != null) { options.resultCallback(ShowResult.Failed); } return; } Adapter adapter = zone.SelectAdapter(); if(adapter == null) { if(options.resultCallback != null) { options.resultCallback(ShowResult.Failed); } return; } Utils.LogDebug("Consuming global ad slot"); ConfigManager.Instance.globalIntervals.Consume(); if(ConfigManager.Instance.globalIntervals.IsEmpty()) { Utils.LogDebug("Global ad interval list empty"); ConfigManager.Instance.RequestAdSources(); } EventHandler finishedHandler = null; EventHandler skippedHandler = null; EventHandler failedHandler = null; EventHandler closeHandler = null; closeHandler = (object sender, EventArgs e) => { _isShowing = false; adapter.Unsubscribe(Adapter.EventType.adDidClose, closeHandler); if(finishedHandler != null) { adapter.Unsubscribe(Adapter.EventType.adFinished, finishedHandler); } if(skippedHandler != null) { adapter.Unsubscribe(Adapter.EventType.adSkipped, skippedHandler); } if(failedHandler != null) { adapter.Unsubscribe(Adapter.EventType.error, failedHandler); } }; adapter.Subscribe(Adapter.EventType.adDidClose, closeHandler); if(options != null) { if(options.pause) { EventHandler showHandler = null; showHandler = (object sender, EventArgs e) => { PauseGame(); adapter.Unsubscribe(Adapter.EventType.adWillOpen, showHandler); }; adapter.Subscribe(Adapter.EventType.adWillOpen, showHandler); } finishedHandler = (object sender, EventArgs e) => { _isShowing = false; if(options.resultCallback != null) options.resultCallback(ShowResult.Finished); if(options.pause) { ResumeGame(); } adapter.Unsubscribe(Adapter.EventType.adFinished, finishedHandler); finishedHandler = null; }; adapter.Subscribe(Adapter.EventType.adFinished, finishedHandler); skippedHandler = (object sender, EventArgs e) => { _isShowing = false; if(options.resultCallback != null) options.resultCallback(ShowResult.Skipped); if(options.pause) { ResumeGame(); } adapter.Unsubscribe(Adapter.EventType.adSkipped, skippedHandler); skippedHandler = null; }; adapter.Subscribe(Adapter.EventType.adSkipped, skippedHandler); failedHandler = (object sender, EventArgs e) => { _isShowing = false; if(options.resultCallback != null) options.resultCallback(ShowResult.Failed); if(options.pause) { ResumeGame(); } adapter.Unsubscribe(Adapter.EventType.error, failedHandler); failedHandler = null; }; adapter.Subscribe(Adapter.EventType.error, failedHandler); } Event.EventManager.sendMediationShowEvent(AppId, zone.Id, adapter.Id); adapter.Show(zone.Id, adapter.Id, options); _isShowing = true; }
public void Show(string zoneId, ShowOptions options) { if (!_initialized) { if (options.resultCallback != null) { options.resultCallback(ShowResult.Failed); } return; } if (!ConfigManager.Instance.IsReady()) { if (ConfigManager.Instance.globalIntervals != null) { Event.EventManager.sendMediationCappedEvent(Engine.Instance.AppId, null, "global", ConfigManager.Instance.globalIntervals.NextAvailable()); } if (options.resultCallback != null) { options.resultCallback(ShowResult.Failed); } return; } Zone zone = ZoneManager.Instance.GetZone(zoneId); if (zone == null) { if (options.resultCallback != null) { options.resultCallback(ShowResult.Failed); } return; } Adapter adapter = zone.SelectAdapter(); if (adapter == null) { if (options.resultCallback != null) { options.resultCallback(ShowResult.Failed); } return; } Utils.LogDebug("Consuming global ad slot"); ConfigManager.Instance.globalIntervals.Consume(); if (ConfigManager.Instance.globalIntervals.IsEmpty()) { Utils.LogDebug("Global ad interval list empty"); ConfigManager.Instance.RequestAdSources(); } EventHandler finishedHandler = null; EventHandler skippedHandler = null; EventHandler failedHandler = null; EventHandler closeHandler = null; closeHandler = (object sender, EventArgs e) => { _isShowing = false; adapter.Unsubscribe(Adapter.EventType.adDidClose, closeHandler); if (finishedHandler != null) { adapter.Unsubscribe(Adapter.EventType.adFinished, finishedHandler); } if (skippedHandler != null) { adapter.Unsubscribe(Adapter.EventType.adSkipped, skippedHandler); } if (failedHandler != null) { adapter.Unsubscribe(Adapter.EventType.error, failedHandler); } }; adapter.Subscribe(Adapter.EventType.adDidClose, closeHandler); if (options != null) { if (options.pause) { EventHandler showHandler = null; showHandler = (object sender, EventArgs e) => { PauseGame(); adapter.Unsubscribe(Adapter.EventType.adWillOpen, showHandler); }; adapter.Subscribe(Adapter.EventType.adWillOpen, showHandler); } finishedHandler = (object sender, EventArgs e) => { _isShowing = false; if (options.resultCallback != null) { options.resultCallback(ShowResult.Finished); } if (options.pause) { ResumeGame(); } adapter.Unsubscribe(Adapter.EventType.adFinished, finishedHandler); finishedHandler = null; }; adapter.Subscribe(Adapter.EventType.adFinished, finishedHandler); skippedHandler = (object sender, EventArgs e) => { _isShowing = false; if (options.resultCallback != null) { options.resultCallback(ShowResult.Skipped); } if (options.pause) { ResumeGame(); } adapter.Unsubscribe(Adapter.EventType.adSkipped, skippedHandler); skippedHandler = null; }; adapter.Subscribe(Adapter.EventType.adSkipped, skippedHandler); failedHandler = (object sender, EventArgs e) => { _isShowing = false; if (options.resultCallback != null) { options.resultCallback(ShowResult.Failed); } if (options.pause) { ResumeGame(); } adapter.Unsubscribe(Adapter.EventType.error, failedHandler); failedHandler = null; }; adapter.Subscribe(Adapter.EventType.error, failedHandler); } Event.EventManager.sendMediationShowEvent(AppId, zone.Id, adapter.Id); adapter.Show(zone.Id, adapter.Id, options); _isShowing = true; }