예제 #1
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);
                }
            };
        }
예제 #2
0
 public void Request(string appId, string adUnitId, AdType type)
 {
     hasPendingAdRequest = true;
     AppCallbacks.Instance.InvokeOnUIThread(() =>
     {
         try
         {
             _ad.RequestAd((Microsoft.Advertising.WinRT.UI.AdType)type, appId, adUnitId);
         }
         catch (Exception ex)
         {
             System.Diagnostics.Debug.WriteLine(ex.Message);
             hasPendingAdRequest = false;
         }
     }, true);
 }
예제 #3
0
 public void Request(string appId, string adUnitId, AdType type)
 {
     hasPendingAdRequest = true;
     AppCallbacks.Instance.InvokeOnUIThread(() =>
     {
         //TODO: this try/catch does not get c++ unhandled exceptions that ad sdk throws
         try
         {
             _ad.RequestAd((Microsoft.Advertising.WinRT.UI.AdType)type, appId, adUnitId);
         }
         catch (Exception ex)
         {
             System.Diagnostics.Debug.WriteLine(ex.Message);
             hasPendingAdRequest = false;
             Marshal(this.errorCallback, new Microsoft.UnityPlugins.AdErrorEventArgs(
                         Microsoft.UnityPlugins.ErrorCode.Other, ex.Message));
         }
     }, true);
 }