示例#1
0
 public void Show()
 {
     if (_ad.State == Microsoft.Advertising.WinRT.UI.InterstitialAdState.Ready)
     {
         showWhenReady = false;
         AppCallbacks.Instance.InvokeOnUIThread(() =>
         {
             //TODO: this try/catch does not get c++ unhandled exceptions that ad sdk throws
             try
             {
                 _ad.Show();
             }
             catch (Exception ex)
             {
                 Marshal(this.errorCallback, new Microsoft.UnityPlugins.AdErrorEventArgs(
                             Microsoft.UnityPlugins.ErrorCode.Other, ex.Message));
                 Marshal(this.completedCallback, null);
             }
         }, true);
     }
     else if (_ad.State == Microsoft.Advertising.WinRT.UI.InterstitialAdState.NotReady &&
              hasPendingAdRequest)
     {
         showWhenReady = true;
     }
 }
示例#2
0
        private static void ConfigureMicrosoftInterstitalAd()
        {
            Microsoft.Advertising.WinRT.UI.InterstitialAd interstitialAd = new Microsoft.Advertising.WinRT.UI.InterstitialAd();
            interstitialAd.AdReady           += (s, e) => { RaiseActionOnAppThread(WSANativeInterstitialAd.AdReady, WSAInterstitialAdType.Microsoft); };
            interstitialAd.ErrorOccurred     += (s, e) => { RaiseActionOnAppThread(WSANativeInterstitialAd.ErrorOccurred, WSAInterstitialAdType.Microsoft, e.ErrorMessage); };
            interstitialAd.Completed         += (s, e) => { RaiseActionOnAppThread(WSANativeInterstitialAd.Completed, WSAInterstitialAdType.Microsoft); };
            interstitialAd.Cancelled         += (s, e) => { RaiseActionOnAppThread(WSANativeInterstitialAd.Cancelled, WSAInterstitialAdType.Microsoft); };
            WSANativeInterstitialAd._Request += (adType, adVariant, appId, adUnitId) =>
            {
                if (adType == WSAInterstitialAdType.Microsoft)
                {
                    AppCallbacks.Instance.InvokeOnUIThread(() =>
                    {
#if UNITY_WSA_10_0
                        interstitialAd.RequestAd(adVariant == WSAInterstitialAdVariant.Display ? Microsoft.Advertising.WinRT.UI.AdType.Display : Microsoft.Advertising.WinRT.UI.AdType.Video,
                                                 appId, adUnitId);
#else
                        interstitialAd.RequestAd(Microsoft.Advertising.WinRT.UI.AdType.Video, appId, adUnitId);
#endif
                    }, false);
                }
            };
            WSANativeInterstitialAd._Show += (adType) =>
            {
                if (adType == WSAInterstitialAdType.Microsoft && interstitialAd != null && interstitialAd.State == Microsoft.Advertising.WinRT.UI.InterstitialAdState.Ready)
                {
                    AppCallbacks.Instance.InvokeOnUIThread(() =>
                    {
                        interstitialAd.Show();
                    }, false);
                }
            };
        }
 public void Show()
 {
     if (_ad.State == Microsoft.Advertising.WinRT.UI.InterstitialAdState.Ready)
     {
         showWhenReady = false;
         AppCallbacks.Instance.InvokeOnUIThread(() =>
         {
             _ad.Show();
         }, true);
     }
     else if (_ad.State == Microsoft.Advertising.WinRT.UI.InterstitialAdState.NotReady &&
              hasPendingAdRequest)
     {
         showWhenReady = true;
     }
 }