Example #1
0
        public DFP_AdPlugin_iOS(AdDesc desc, AdCreatedCallbackMethod createdCallback)
        {
                        #if !IOS_DISABLE_GOOGLE_ADS
            bool pass = true;
            try
            {
                eventCallback = desc.EventCallback;
                native        = DFP_InitAd(desc.Testing);
                int gravity = convertGravity(desc.iOS_DFP_AdGravity);

                DFP_CreateAd(native, gravity, convertAdSize(desc.iOS_DFP_AdSize), desc.iOS_DFP_UnitID);
                Visible = desc.Visible;
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
                pass = false;
            }

            if (createdCallback != null)
            {
                createdCallback(pass);
            }
                        #endif
        }
		public iAd_AdPlugin_iOS(AdDesc desc, AdCreatedCallbackMethod createdCallback)
		{
			eventCallback = desc.EventCallback;
			native = iAd_InitAd(desc.Testing);
			int gravity = convertGravity(desc.iOS_iAd_AdGravity);
			
			iAd_CreateAd(native, gravity);
			Visible = desc.Visible;
			if (createdCallback != null) createdCallback(true);
		}
Example #3
0
        public iAd_AdPlugin_iOS(AdDesc desc, AdCreatedCallbackMethod createdCallback)
        {
            eventCallback = desc.EventCallback;
            native        = iAd_InitAd(desc.Testing);
            int gravity = convertGravity(desc.iOS_iAd_AdGravity);

            iAd_CreateAd(native, gravity);
            Visible = desc.Visible;
            if (createdCallback != null)
            {
                createdCallback(true);
            }
        }
		public DFP_AdPlugin_Android(AdDesc desc, AdCreatedCallbackMethod createdCallback)
		{
			this.createdCallback = createdCallback;
			try
			{
				eventCallback = desc.EventCallback;
				native = new AndroidJavaClass("com.reignstudios.reignnative.DFP_AdsNative");
				visible = desc.Visible;
				id = Guid.NewGuid().ToString();
				native.CallStatic("CreateAd", desc.Android_DFP_UnitID, desc.Testing, desc.Visible, convertGravity(desc.Android_DFP_AdGravity), convertAdSize(desc.Android_DFP_AdSize), id);
			}
			catch (Exception e)
			{
				Debug.LogError(e.Message);
				if (createdCallback != null) createdCallback(false);
			}
		}
		public AdMob_AdPlugin_iOS(AdDesc desc, AdCreatedCallbackMethod createdCallback)
		{
			bool pass = true;
			try
			{
				eventCallback = desc.EventCallback;
				native = AdMob_InitAd(desc.Testing);
				int gravity = convertGravity(desc.iOS_AdMob_AdGravity);
				
				AdMob_CreateAd(native, gravity, convertAdSize(desc.iOS_AdMob_AdSize), desc.iOS_AdMob_UnitID);
				Visible = desc.Visible;
			}
			catch (Exception e)
			{
				Debug.LogError(e.Message);
				pass = false;
			}
				
			if (createdCallback != null) createdCallback(pass);
		}
 public Amazon_AdPlugin_Android(AdDesc desc, AdCreatedCallbackMethod createdCallback)
 {
     this.createdCallback = createdCallback;
     try
     {
         eventCallback = desc.EventCallback;
         native        = new AndroidJavaClass("com.reignstudios.reignnative.Amazon_AdsNative");
         visible       = desc.Visible;
         id            = Guid.NewGuid().ToString();
         native.CallStatic("CreateAd", desc.Android_AmazonAds_ApplicationKey, desc.Testing, desc.Visible, convertGravity(desc.Android_AmazonAds_AdGravity), convertAdSize(desc.Android_AmazonAds_AdSize), desc.Android_AmazonAds_RefreshRate, id);
     }
     catch (Exception e)
     {
         Debug.LogError(e.Message);
         if (createdCallback != null)
         {
             createdCallback(false);
         }
     }
 }
Example #7
0
        public AdMob_AdPlugin_Native(AdDesc desc, AdCreatedCallbackMethod createdCallback)
        {
            eventCallback = desc.EventCallback;
            testing       = desc.Testing;

            WinRTPlugin.Dispatcher.BeginInvoke(delegate()
            {
                bool pass = true;
                try
                {
                    adView = new AdView();
                    setGravity(desc.WP8_AdMob_AdGravity);

                    adView.AdUnitID = desc.WP8_AdMob_UnitID;
                    adView.Format   = desc.WP8_AdMob_AdSize == WP8_AdMob_AdSize.Banner ? AdFormats.Banner : AdFormats.SmartBanner;

                    setVisible(desc.Visible);
                    adView.ReceivedAd        += adView_ReceivedAd;
                    adView.FailedToReceiveAd += adView_FailedToReceiveAd;

                    WinRTPlugin.AdGrid.Children.Add(adView);

                    AdRequest request = new AdRequest();
                    //request.ForceTesting = desc.Testing;// Looks like there is a bug in AdMob if this is enabled.
                    adView.LoadAd(request);

                    Debug.Log("Created Ad of AdUnitID: " + adView.AdUnitID);
                }
                catch (Exception e)
                {
                    pass = false;
                    Debug.LogError(e.Message);
                }

                if (createdCallback != null)
                {
                    createdCallback(pass);
                }
            });
        }
		public DFP_AdPlugin_iOS(AdDesc desc, AdCreatedCallbackMethod createdCallback)
		{
			#if !IOS_DISABLE_GOOGLE_ADS
			bool pass = true;
			try
			{
				eventCallback = desc.EventCallback;
				native = DFP_InitAd(desc.Testing);
				int gravity = convertGravity(desc.iOS_DFP_AdGravity);

				DFP_CreateAd(native, gravity, convertAdSize(desc.iOS_DFP_AdSize), desc.iOS_DFP_UnitID);
				Visible = desc.Visible;
			}
			catch (Exception e)
			{
				Debug.LogError(e.Message);
				pass = false;
			}

			if (createdCallback != null) createdCallback(pass);
			#endif
		}
		public AdMob_AdPlugin_Native(AdDesc desc, AdCreatedCallbackMethod createdCallback)
		{
			eventCallback = desc.EventCallback;
			testing = desc.Testing;

			WinRTPlugin.Dispatcher.BeginInvoke(delegate()
			{
				bool pass = true;
				try
				{
					adView = new AdView();
					setGravity(desc.WP8_AdMob_AdGravity);

					adView.AdUnitID = desc.WP8_AdMob_UnitID;
					adView.Format = desc.WP8_AdMob_AdSize == WP8_AdMob_AdSize.Banner ? AdFormats.Banner : AdFormats.SmartBanner;

					setVisible(desc.Visible);
					adView.ReceivedAd += adView_ReceivedAd;
					adView.FailedToReceiveAd += adView_FailedToReceiveAd;

					WinRTPlugin.AdGrid.Children.Add(adView);

					AdRequest request = new AdRequest();
					//request.ForceTesting = desc.Testing;// Looks like there is a bug in AdMob if this is enabled.
					adView.LoadAd(request);

					Debug.Log("Created Ad of AdUnitID: " + adView.AdUnitID);
				}
				catch (Exception e)
				{
					pass = false;
					Debug.LogError(e.Message);
				}

				if (createdCallback != null) createdCallback(pass);
			});
		}
Example #10
0
        public AdMob_AdPlugin_iOS(AdDesc desc, AdCreatedCallbackMethod createdCallback)
        {
            bool pass = true;

            try
            {
                eventCallback = desc.EventCallback;
                native        = AdMob_InitAd(desc.Testing);
                int gravity = convertGravity(desc.iOS_AdMob_AdGravity);

                AdMob_CreateAd(native, gravity, convertAdSize(desc.iOS_AdMob_AdSize), desc.iOS_AdMob_UnitID);
                Visible = desc.Visible;
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
                pass = false;
            }

            if (createdCallback != null)
            {
                createdCallback(pass);
            }
        }
Example #11
0
        public MM_AdPlugin(AdDesc desc, AdCreatedCallbackMethod createdCallback, MonoBehaviour service)
        {
            this.service = service;

            try
            {
                this.desc = desc;
                testing   = desc.Testing;
                adEvent   = desc.EventCallback;

                gravity = AdGravity.CenterScreen;
                                #if !DISABLE_REIGN
                                #if UNITY_EDITOR
                refreshRate = desc.Editor_MillennialMediaAdvertising_RefreshRate;
                apid        = desc.Editor_MillennialMediaAdvertising_APID;
                userAgent   = "";
                gravity     = desc.Editor_MillennialMediaAdvertising_AdGravity;
                uiScale     = desc.Editor_AdScale;
                                #elif UNITY_BLACKBERRY
                refreshRate = desc.BB10_MillennialMediaAdvertising_RefreshRate;
                apid        = desc.BB10_MillennialMediaAdvertising_APID;

                IntPtr handle = IntPtr.Zero;
                if (Common.deviceinfo_get_details(ref handle) != 0)
                {
                    throw new Exception("Failed: deviceinfo_get_details");
                }
                string deviceType = Common.deviceinfo_details_get_keyboard(handle) == 0 ? "Touch" : "Kbd";
                Common.deviceinfo_free_details(ref handle);
                string osVersion = System.Text.RegularExpressions.Regex.Match(SystemInfo.operatingSystem, @"\d*\.\d*\.\d*\.\d*").Groups[0].Value;
                userAgent = WWW.EscapeURL("Mozilla/5.0 (BB10; " + deviceType + ") AppleWebKit/537.10+ (KHTML, like Gecko) Version/" + osVersion + " Mobile Safari/537.10+");

                gravity = desc.BB10_MillennialMediaAdvertising_AdGravity;
                uiScale = desc.BB10_AdScale;
                                #elif UNITY_WP8
                refreshRate = desc.WP8_MillennialMediaAdvertising_RefreshRate;
                apid        = desc.WP8_MillennialMediaAdvertising_APID;
                userAgent   = "";
                gravity     = desc.WP8_MillennialMediaAdvertising_AdGravity;
                uiScale     = desc.WP8_AdScale;
                                #elif UNITY_METRO
                refreshRate = desc.WinRT_MillennialMediaAdvertising_RefreshRate;
                apid        = desc.WinRT_MillennialMediaAdvertising_APID;
                userAgent   = "";
                gravity     = desc.WinRT_MillennialMediaAdvertising_AdGravity;
                uiScale     = desc.WinRT_AdScale;
                                #elif UNITY_IOS
                refreshRate = desc.iOS_MillennialMediaAdvertising_RefreshRate;
                apid        = desc.iOS_MillennialMediaAdvertising_APID;
                userAgent   = "";
                gravity     = desc.iOS_MillennialMediaAdvertising_AdGravity;
                uiScale     = desc.iOS_AdScale;
                                #elif UNITY_ANDROID
                refreshRate = desc.Android_MillennialMediaAdvertising_RefreshRate;
                apid        = desc.Android_MillennialMediaAdvertising_APID;
                userAgent   = "";
                gravity     = desc.Android_MillennialMediaAdvertising_AdGravity;
                uiScale     = desc.Android_AdScale;
                                #elif UNITY_STANDALONE_WIN
                refreshRate = desc.Win32_MillennialMediaAdvertising_RefreshRate;
                apid        = desc.Win32_MillennialMediaAdvertising_APID;
                userAgent   = "";
                gravity     = desc.Win32_MillennialMediaAdvertising_AdGravity;
                uiScale     = desc.Win32_AdScale;
                                #elif UNITY_STANDALONE_OSX
                refreshRate = desc.OSX_MillennialMediaAdvertising_RefreshRate;
                apid        = desc.OSX_MillennialMediaAdvertising_APID;
                userAgent   = "";
                gravity     = desc.OSX_MillennialMediaAdvertising_AdGravity;
                uiScale     = desc.OSX_AdScale;
                                #elif UNITY_STANDALONE_LINUX
                refreshRate = desc.Linux_MillennialMediaAdvertising_RefreshRate;
                apid        = desc.Linux_MillennialMediaAdvertising_APID;
                userAgent   = "";
                gravity     = desc.Linux_MillennialMediaAdvertising_AdGravity;
                uiScale     = desc.Linux_AdScale;
                                #endif
                                #endif

                // make sure ad refresh rate doesn't go under 1 min
                if (refreshRate < 60)
                {
                    refreshRate = 60;
                }

                // create or get device ID
                if (PlayerPrefs.HasKey("Reign_MMWebAds_DeviceID"))
                {
                    deviceID = PlayerPrefs.GetString("Reign_MMWebAds_DeviceID");
                }
                else
                {
                                        #if UNITY_EDITOR || UNITY_STANDALONE
                    var hash = new SHA1CryptoServiceProvider().ComputeHash(Guid.NewGuid().ToByteArray());
                    deviceID = BitConverter.ToString(hash).ToLower();
                                        #else
                    deviceID = Guid.NewGuid().ToString().Replace("-", "0").ToLower() + "0000";
                                        #endif

                    PlayerPrefs.SetString("Reign_MMWebAds_DeviceID", deviceID);
                }

                if (desc.UseClassicGUI)
                {
                    guiSytle = new GUIStyle()
                    {
                        stretchWidth  = true,
                        stretchHeight = true
                    };
                }
                else
                {
                    // Create Ad Canvas
                    adCanvas = new GameObject("MM Ad");
                    GameObject.DontDestroyOnLoad(adCanvas);
                    adCanvas.AddComponent <RectTransform>();
                    var canvas = adCanvas.AddComponent <Canvas>();
                    canvas.renderMode   = RenderMode.ScreenSpaceOverlay;
                    canvas.sortingOrder = 1000;
                    adCanvas.AddComponent <CanvasScaler>();
                    adCanvas.AddComponent <GraphicRaycaster>();

                    // Create ad
                    var ad = new GameObject("AdButtonImage");
                    ad.transform.parent = adCanvas.transform;
                    adRect                 = ad.AddComponent <RectTransform>();
                    adImage                = ad.AddComponent <Image>();
                    adImage.sprite         = Resources.Load <Sprite>("Reign/Ads/AdLoading");
                    adImage.preserveAspect = true;
                    var button = ad.AddComponent <Button>();
                    button.onClick.AddListener(adClicked);
                }

                // set default visible state
                Visible = desc.Visible;
                SetGravity(gravity);

                // load ad
                service.StartCoroutine(init(createdCallback));

                // set screen size changed callback
                ReignServices.ScreenSizeChangedCallback += ReignServices_ScreenSizeChangedCallback;
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
                if (createdCallback != null)
                {
                    createdCallback(false);
                }
            }
        }
		private async void init(AdDesc desc, AdCreatedCallbackMethod createdCallback)
		#endif
		{
			if (WinRTPlugin.AdGrid == null)
			{
				if (createdCallback != null) createdCallback(false);
				return;
			}

			#if WINDOWS_PHONE
			WinRTPlugin.Dispatcher.BeginInvoke(delegate()
			#else
			await WinRTPlugin.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, delegate()
			#endif
			{
				bool pass = true;
				try
				{
					adControl = new AdControl();
					#if WINDOWS_PHONE || UNITY_WP_8_1
					adControl.IsAutoRefreshEnabled = desc.WP8_MicrosoftAdvertising_UseBuiltInRefresh;
					if (!desc.WP8_MicrosoftAdvertising_UseBuiltInRefresh)
					{
						manualRefreshTimer = new DispatcherTimer();
						manualRefreshTimer.Interval = TimeSpan.FromSeconds(desc.WP8_MicrosoftAdvertising_RefreshRate);
						manualRefreshTimer.Tick += timer_Tick;
						manualRefreshTimer.Start();
					}

					adControl.IsEngagedChanged += adControl_IsEngagedChanged;
					adControl.AdRefreshed += adControl_AdRefreshed;
					#else
					adControl.IsAutoRefreshEnabled = desc.WinRT_MicrosoftAdvertising_UseBuiltInRefresh;
					if (!desc.WinRT_MicrosoftAdvertising_UseBuiltInRefresh)
					{
						manualRefreshTimer = new DispatcherTimer();
						manualRefreshTimer.Interval = TimeSpan.FromSeconds(desc.WinRT_MicrosoftAdvertising_RefreshRate);
						manualRefreshTimer.Tick += timer_Tick;
						manualRefreshTimer.Start();
					}

					adControl.IsEngagedChanged += adControl_IsEngagedChanged;
					adControl.AdRefreshed += adControl_AdRefreshed;
					#endif

					adControl.ErrorOccurred += adControl_ErrorOccurred;
					#if WINDOWS_PHONE
					adControl.SetValue(System.Windows.Controls.Canvas.ZIndexProperty, 98);
					#else
					adControl.SetValue(Windows.UI.Xaml.Controls.Canvas.ZIndexProperty, 98);
					#endif
			
					#if WINDOWS_PHONE || UNITY_WP_8_1
					adControl.ApplicationId = desc.Testing ? "test_client" : desc.WP8_MicrosoftAdvertising_ApplicationID;
					adControl.AdUnitId = desc.WP8_MicrosoftAdvertising_UnitID;
					switch (desc.WP8_MicrosoftAdvertising_AdSize)
					{
						case WP8_MicrosoftAdvertising_AdSize.Wide_640x100:
							adControl.Width = 640;
							adControl.Height = 100;
							if (desc.Testing) adControl.AdUnitId = "Image640_100";
							break;

						case WP8_MicrosoftAdvertising_AdSize.Wide_480x80:
							adControl.Width = 480;
							adControl.Height = 80;
							if (desc.Testing) adControl.AdUnitId = "Image480_80";
							break;

						case WP8_MicrosoftAdvertising_AdSize.Wide_320x50:
							adControl.Width = 320;
							adControl.Height = 50;
							if (desc.Testing) adControl.AdUnitId = "Image320_50";
							break;

						case WP8_MicrosoftAdvertising_AdSize.Wide_300x50:
							adControl.Width = 300;
							adControl.Height = 50;
							if (desc.Testing) adControl.AdUnitId = "Image300_50";
							break;

						default:
							Debug.LogError("AdPlugin: Unsuported Ad size");
							break;
					}
					#elif UNITY_METRO
					adControl.ApplicationId = desc.Testing ? "d25517cb-12d4-4699-8bdc-52040c712cab" : desc.WinRT_MicrosoftAdvertising_ApplicationID;
					adControl.AdUnitId = desc.WinRT_MicrosoftAdvertising_UnitID;
					switch (desc.WinRT_MicrosoftAdvertising_AdSize)
					{
						case WinRT_MicrosoftAdvertising_AdSize.Tall_160x600:
							adControl.Width = 160;
							adControl.Height = 600;
							if (desc.Testing) adControl.AdUnitId = "10043134";
							break;

						case WinRT_MicrosoftAdvertising_AdSize.Tall_300x600:
							adControl.Width = 300;
							adControl.Height = 600;
							if (desc.Testing) adControl.AdUnitId = "10043030";
							break;

						case WinRT_MicrosoftAdvertising_AdSize.Wide_300x250:
							adControl.Width = 300;
							adControl.Height = 250;
							if (desc.Testing) adControl.AdUnitId = "10043008";
							break;

						case WinRT_MicrosoftAdvertising_AdSize.Wide_728x90:
							adControl.Width = 728;
							adControl.Height = 90;
							if (desc.Testing) adControl.AdUnitId = "10042998";
							break;

						case WinRT_MicrosoftAdvertising_AdSize.Square_250x250:
							adControl.Width = 250;
							adControl.Height = 250;
							if (desc.Testing) adControl.AdUnitId = "10043105";
							break;

						default:
							Debug.LogError("AdPlugin: Unsuported Ad size");
							break;
					}
					#endif

					#if WINDOWS_PHONE || UNITY_WP_8_1
					setGravity(desc.WP8_MicrosoftAdvertising_AdGravity);
					#else
					setGravity(desc.WinRT_MicrosoftAdvertising_AdGravity);
					#endif
					
					eventCallback = desc.EventCallback;
					WinRTPlugin.AdGrid.Children.Add(adControl);
					setVisible(desc.Visible);
					Debug.Log("Created Ad of ApplicationID: " + adControl.ApplicationId + " AdUnitID" + adControl.AdUnitId);
				}
				catch (Exception e)
				{
					adControl = null;
					Debug.LogError(e.Message);
				}

				ReignServices.InvokeOnUnityThread(delegate
				{
					if (createdCallback != null) createdCallback(pass);
				});
			});
		}
Example #13
0
        private async void init(AdDesc desc, AdCreatedCallbackMethod createdCallback)
        {
            if (WinRTPlugin.AdGrid == null)
            {
                if (createdCallback != null)
                {
                    createdCallback(false);
                }
                return;
            }

            await WinRTPlugin.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, delegate()
            {
                bool pass = true;
                try
                {
                    adControl                 = new AdControl();
                    adControl.AdClick        += adControl_Clicked;
                    adControl.AdLoaded       += adControl_AdRefreshed;
                    adControl.AdLoadingError += adControl_ErrorOccurred;
                    adControl.AdCovered      += adControl_AdCovered;
                    adControl.NoAd           += adControl_NoAd;
                    adControl.IsTest          = desc.Testing;
                    adControl.CollapseOnError = true;

                    adControl.SetValue(Windows.UI.Xaml.Controls.Canvas.ZIndexProperty, 98);

                                        #if UNITY_WP_8_1
                    adControl.RefreshInterval = desc.WP8_AdDuplex_RefreshRate;
                    adControl.AppKey          = desc.WP8_AdDuplex_ApplicationKey;
                    adControl.AdUnitId        = desc.WP8_AdDuplex_UnitID;
                                        #else
                    adControl.RefreshInterval = desc.WinRT_AdDuplex_RefreshRate;
                    adControl.AppKey          = desc.WinRT_AdDuplex_ApplicationKey;
                    adControl.AdUnitId        = desc.WinRT_AdDuplex_UnitID;
                    switch (desc.WinRT_AdDuplex_AdSize)
                    {
                    case WinRT_AdDuplex_AdSize.Tall_160x600:
                        adControl.Size = "160x600";
                        break;

                    case WinRT_AdDuplex_AdSize.Wide_250x125:
                        adControl.Size = "250x125";
                        break;

                    case WinRT_AdDuplex_AdSize.Wide_292x60:
                        adControl.Size = "292x60";
                        break;

                    case WinRT_AdDuplex_AdSize.Wide_300x250:
                        adControl.Size = "300x250";
                        break;

                    case WinRT_AdDuplex_AdSize.Wide_500x130:
                        adControl.Size = "500x130";
                        break;

                    case WinRT_AdDuplex_AdSize.Wide_728x90:
                        adControl.Size = "728x90";
                        break;

                    case WinRT_AdDuplex_AdSize.Square_250x250:
                        adControl.Size = "250x250";
                        break;

                    default:
                        Debug.LogError("AdPlugin: Unsuported Ad size");
                        break;
                    }
                                        #endif

                                        #if UNITY_WP_8_1
                    setGravity(desc.WP8_AdDuplex_AdGravity);
                                        #else
                    setGravity(desc.WinRT_AdDuplex_AdGravity);
                                        #endif

                    eventCallback = desc.EventCallback;
                    WinRTPlugin.AdGrid.Children.Add(adControl);
                    setVisible(desc.Visible);
                    Debug.Log("Created Ad of AppKey: " + adControl.AppKey + " AdUnitID" + adControl.AdUnitId);
                }
                catch (Exception e)
                {
                    adControl = null;
                    Debug.LogError(e.Message);
                }

                ReignServices.InvokeOnUnityThread(delegate
                {
                    if (createdCallback != null)
                    {
                        createdCallback(pass);
                    }
                });
            });
        }
		private async void init(AdDesc desc, AdCreatedCallbackMethod createdCallback)
		{
			if (WinRTPlugin.AdGrid == null)
			{
				if (createdCallback != null) createdCallback(false);
				return;
			}

			await WinRTPlugin.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, delegate()
			{
				bool pass = true;
				try
				{
					adControl = new AdControl();
					adControl.AdClick += adControl_Clicked;
					adControl.AdLoaded += adControl_AdRefreshed;
					adControl.AdLoadingError += adControl_ErrorOccurred;
					adControl.AdCovered += adControl_AdCovered;
					adControl.NoAd += adControl_NoAd;
					adControl.IsTest = desc.Testing;
					adControl.CollapseOnError = true;

					adControl.SetValue(Windows.UI.Xaml.Controls.Canvas.ZIndexProperty, 98);
			
					#if UNITY_WP_8_1
					adControl.RefreshInterval = desc.WP8_AdDuplex_RefreshRate;
					adControl.AppKey = desc.WP8_AdDuplex_ApplicationKey;
					adControl.AdUnitId = desc.WP8_AdDuplex_UnitID;
					#else
					adControl.RefreshInterval = desc.WinRT_AdDuplex_RefreshRate;
					adControl.AppKey = desc.WinRT_AdDuplex_ApplicationKey;
					adControl.AdUnitId = desc.WinRT_AdDuplex_UnitID;
					switch (desc.WinRT_AdDuplex_AdSize)
					{
						case WinRT_AdDuplex_AdSize.Tall_160x600:
							adControl.Size = "160x600";
							break;

						case WinRT_AdDuplex_AdSize.Wide_250x125:
							adControl.Size = "250x125";
							break;

						case WinRT_AdDuplex_AdSize.Wide_292x60:
							adControl.Size = "292x60";
							break;

						case WinRT_AdDuplex_AdSize.Wide_300x250:
							adControl.Size = "300x250";
							break;

						case WinRT_AdDuplex_AdSize.Wide_500x130:
							adControl.Size = "500x130";
							break;

						case WinRT_AdDuplex_AdSize.Wide_728x90:
							adControl.Size = "728x90";
							break;

						case WinRT_AdDuplex_AdSize.Square_250x250:
							adControl.Size = "250x250";
							break;

						default:
							Debug.LogError("AdPlugin: Unsuported Ad size");
							break;
					}
					#endif

					#if UNITY_WP_8_1
					setGravity(desc.WP8_AdDuplex_AdGravity);
					#else
					setGravity(desc.WinRT_AdDuplex_AdGravity);
					#endif
					
					eventCallback = desc.EventCallback;
					WinRTPlugin.AdGrid.Children.Add(adControl);
					setVisible(desc.Visible);
					Debug.Log("Created Ad of AppKey: " + adControl.AppKey + " AdUnitID" + adControl.AdUnitId);
				}
				catch (Exception e)
				{
					adControl = null;
					Debug.LogError(e.Message);
				}

				UnityEngine.WSA.Application.InvokeOnAppThread(()=>
				{
					if (createdCallback != null) createdCallback(pass);
				}, false);
			});
		}
        private async void init(AdDesc desc, AdCreatedCallbackMethod createdCallback)
                #endif
        {
            if (WinRTPlugin.AdGrid == null)
            {
                if (createdCallback != null)
                {
                    createdCallback(false);
                }
                return;
            }

                        #if WINDOWS_PHONE
            WinRTPlugin.Dispatcher.BeginInvoke(delegate()
                        #else
            await WinRTPlugin.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, delegate()
                        #endif
            {
                bool pass = true;
                try
                {
                    adControl = new AdControl();
                                        #if WINDOWS_PHONE || UNITY_WP_8_1
                    adControl.IsAutoRefreshEnabled = desc.WP8_MicrosoftAdvertising_UseBuiltInRefresh;
                    if (!desc.WP8_MicrosoftAdvertising_UseBuiltInRefresh)
                    {
                        manualRefreshTimer          = new DispatcherTimer();
                        manualRefreshTimer.Interval = TimeSpan.FromSeconds(desc.WP8_MicrosoftAdvertising_RefreshRate);
                        manualRefreshTimer.Tick    += timer_Tick;
                        manualRefreshTimer.Start();
                    }

                    adControl.IsEngagedChanged += adControl_IsEngagedChanged;
                    adControl.AdRefreshed      += adControl_AdRefreshed;
                                        #else
                    adControl.IsAutoRefreshEnabled = desc.WinRT_MicrosoftAdvertising_UseBuiltInRefresh;
                    if (!desc.WinRT_MicrosoftAdvertising_UseBuiltInRefresh)
                    {
                        manualRefreshTimer          = new DispatcherTimer();
                        manualRefreshTimer.Interval = TimeSpan.FromSeconds(desc.WinRT_MicrosoftAdvertising_RefreshRate);
                        manualRefreshTimer.Tick    += timer_Tick;
                        manualRefreshTimer.Start();
                    }

                    adControl.IsEngagedChanged += adControl_IsEngagedChanged;
                    adControl.AdRefreshed      += adControl_AdRefreshed;
                                        #endif

                    adControl.ErrorOccurred += adControl_ErrorOccurred;
                                        #if WINDOWS_PHONE
                    adControl.SetValue(System.Windows.Controls.Canvas.ZIndexProperty, 98);
                                        #else
                    adControl.SetValue(Windows.UI.Xaml.Controls.Canvas.ZIndexProperty, 98);
                                        #endif

                                        #if WINDOWS_PHONE || UNITY_WP_8_1
                    adControl.ApplicationId = desc.Testing ? "test_client" : desc.WP8_MicrosoftAdvertising_ApplicationID;
                    adControl.AdUnitId      = desc.WP8_MicrosoftAdvertising_UnitID;
                    switch (desc.WP8_MicrosoftAdvertising_AdSize)
                    {
                    case WP8_MicrosoftAdvertising_AdSize.Wide_640x100:
                        adControl.Width  = 640;
                        adControl.Height = 100;
                        if (desc.Testing)
                        {
                            adControl.AdUnitId = "Image640_100";
                        }
                        break;

                    case WP8_MicrosoftAdvertising_AdSize.Wide_480x80:
                        adControl.Width  = 480;
                        adControl.Height = 80;
                        if (desc.Testing)
                        {
                            adControl.AdUnitId = "Image480_80";
                        }
                        break;

                    case WP8_MicrosoftAdvertising_AdSize.Wide_320x50:
                        adControl.Width  = 320;
                        adControl.Height = 50;
                        if (desc.Testing)
                        {
                            adControl.AdUnitId = "Image320_50";
                        }
                        break;

                    case WP8_MicrosoftAdvertising_AdSize.Wide_300x50:
                        adControl.Width  = 300;
                        adControl.Height = 50;
                        if (desc.Testing)
                        {
                            adControl.AdUnitId = "Image300_50";
                        }
                        break;

                    default:
                        Debug.LogError("AdPlugin: Unsuported Ad size");
                        break;
                    }
                                        #elif UNITY_METRO
                    adControl.ApplicationId = desc.Testing ? "d25517cb-12d4-4699-8bdc-52040c712cab" : desc.WinRT_MicrosoftAdvertising_ApplicationID;
                    adControl.AdUnitId      = desc.WinRT_MicrosoftAdvertising_UnitID;
                    switch (desc.WinRT_MicrosoftAdvertising_AdSize)
                    {
                    case WinRT_MicrosoftAdvertising_AdSize.Tall_160x600:
                        adControl.Width  = 160;
                        adControl.Height = 600;
                        if (desc.Testing)
                        {
                            adControl.AdUnitId = "10043134";
                        }
                        break;

                    case WinRT_MicrosoftAdvertising_AdSize.Tall_300x600:
                        adControl.Width  = 300;
                        adControl.Height = 600;
                        if (desc.Testing)
                        {
                            adControl.AdUnitId = "10043030";
                        }
                        break;

                    case WinRT_MicrosoftAdvertising_AdSize.Wide_300x250:
                        adControl.Width  = 300;
                        adControl.Height = 250;
                        if (desc.Testing)
                        {
                            adControl.AdUnitId = "10043008";
                        }
                        break;

                    case WinRT_MicrosoftAdvertising_AdSize.Wide_728x90:
                        adControl.Width  = 728;
                        adControl.Height = 90;
                        if (desc.Testing)
                        {
                            adControl.AdUnitId = "10042998";
                        }
                        break;

                    case WinRT_MicrosoftAdvertising_AdSize.Square_250x250:
                        adControl.Width  = 250;
                        adControl.Height = 250;
                        if (desc.Testing)
                        {
                            adControl.AdUnitId = "10043105";
                        }
                        break;

                    default:
                        Debug.LogError("AdPlugin: Unsuported Ad size");
                        break;
                    }
                                        #endif

                                        #if WINDOWS_PHONE || UNITY_WP_8_1
                    setGravity(desc.WP8_MicrosoftAdvertising_AdGravity);
                                        #else
                    setGravity(desc.WinRT_MicrosoftAdvertising_AdGravity);
                                        #endif

                    eventCallback = desc.EventCallback;
                    WinRTPlugin.AdGrid.Children.Add(adControl);
                    setVisible(desc.Visible);
                    Debug.Log("Created Ad of ApplicationID: " + adControl.ApplicationId + " AdUnitID" + adControl.AdUnitId);
                }
                catch (Exception e)
                {
                    adControl = null;
                    Debug.LogError(e.Message);
                }

                ReignServices.InvokeOnUnityThread(delegate
                {
                    if (createdCallback != null)
                    {
                        createdCallback(pass);
                    }
                });
            });
        }
		public MM_AdPlugin(AdDesc desc, AdCreatedCallbackMethod createdCallback, MonoBehaviour service)
		{
			this.service = service;

			try
			{
				this.desc = desc;
				testing = desc.Testing;
				adEvent = desc.EventCallback;

				gravity = AdGravity.CenterScreen;
				#if !DISABLE_REIGN
				#if UNITY_EDITOR
				refreshRate = desc.Editor_MillennialMediaAdvertising_RefreshRate;
				apid = desc.Editor_MillennialMediaAdvertising_APID;
				userAgent = "";
				gravity = desc.Editor_MillennialMediaAdvertising_AdGravity;
				uiScale = desc.Editor_AdScale;
				#elif UNITY_BLACKBERRY
				refreshRate = desc.BB10_MillennialMediaAdvertising_RefreshRate;
				apid = desc.BB10_MillennialMediaAdvertising_APID;

				IntPtr handle = IntPtr.Zero;
				if (Common.deviceinfo_get_details(ref handle) != 0) throw new Exception("Failed: deviceinfo_get_details");
				string deviceType = Common.deviceinfo_details_get_keyboard(handle) == 0 ? "Touch" : "Kbd";
				Common.deviceinfo_free_details(ref handle);
				string osVersion = System.Text.RegularExpressions.Regex.Match(SystemInfo.operatingSystem, @"\d*\.\d*\.\d*\.\d*").Groups[0].Value;
				userAgent = WWW.EscapeURL("Mozilla/5.0 (BB10; " + deviceType + ") AppleWebKit/537.10+ (KHTML, like Gecko) Version/" + osVersion + " Mobile Safari/537.10+");

				gravity = desc.BB10_MillennialMediaAdvertising_AdGravity;
				uiScale = desc.BB10_AdScale;
				#elif UNITY_WP8
				refreshRate = desc.WP8_MillennialMediaAdvertising_RefreshRate;
				apid = desc.WP8_MillennialMediaAdvertising_APID;
				userAgent = "";
				gravity = desc.WP8_MillennialMediaAdvertising_AdGravity;
				uiScale = desc.WP8_AdScale;
				#elif UNITY_METRO
				refreshRate = desc.WinRT_MillennialMediaAdvertising_RefreshRate;
				apid = desc.WinRT_MillennialMediaAdvertising_APID;
				userAgent = "";
				gravity = desc.WinRT_MillennialMediaAdvertising_AdGravity;
				uiScale = desc.WinRT_AdScale;
				#elif UNITY_IOS
				refreshRate = desc.iOS_MillennialMediaAdvertising_RefreshRate;
				apid = desc.iOS_MillennialMediaAdvertising_APID;
				userAgent = "";
				gravity = desc.iOS_MillennialMediaAdvertising_AdGravity;
				uiScale = desc.iOS_AdScale;
				#elif UNITY_ANDROID
				refreshRate = desc.Android_MillennialMediaAdvertising_RefreshRate;
				apid = desc.Android_MillennialMediaAdvertising_APID;
				userAgent = "";
				gravity = desc.Android_MillennialMediaAdvertising_AdGravity;
				uiScale = desc.Android_AdScale;
				#elif UNITY_STANDALONE_WIN
				refreshRate = desc.Win32_MillennialMediaAdvertising_RefreshRate;
				apid = desc.Win32_MillennialMediaAdvertising_APID;
				userAgent = "";
				gravity = desc.Win32_MillennialMediaAdvertising_AdGravity;
				uiScale = desc.Win32_AdScale;
				#elif UNITY_STANDALONE_OSX
				refreshRate = desc.OSX_MillennialMediaAdvertising_RefreshRate;
				apid = desc.OSX_MillennialMediaAdvertising_APID;
				userAgent = "";
				gravity = desc.OSX_MillennialMediaAdvertising_AdGravity;
				uiScale = desc.OSX_AdScale;
				#elif UNITY_STANDALONE_LINUX
				refreshRate = desc.Linux_MillennialMediaAdvertising_RefreshRate;
				apid = desc.Linux_MillennialMediaAdvertising_APID;
				userAgent = "";
				gravity = desc.Linux_MillennialMediaAdvertising_AdGravity;
				uiScale = desc.Linux_AdScale;
				#endif
				#endif

				// make sure ad refresh rate doesn't go under 1 min
				if (refreshRate < 60) refreshRate = 60;

				// create or get device ID
				if (PlayerPrefs.HasKey("Reign_MMWebAds_DeviceID"))
				{
					deviceID = PlayerPrefs.GetString("Reign_MMWebAds_DeviceID");
				}
				else
				{
					#if UNITY_EDITOR || UNITY_STANDALONE
					var hash = new SHA1CryptoServiceProvider().ComputeHash(Guid.NewGuid().ToByteArray());
					deviceID = BitConverter.ToString(hash).ToLower();
					#else
					deviceID = Guid.NewGuid().ToString().Replace("-", "0").ToLower() + "0000";
					#endif

					PlayerPrefs.SetString("Reign_MMWebAds_DeviceID", deviceID);
				}

				if (desc.UseClassicGUI)
				{
					guiSytle = new GUIStyle()
					{
						stretchWidth = true,
						stretchHeight = true
					};
				}
				else
				{
					// Create Ad Canvas
					adCanvas = new GameObject("MM Ad");
					GameObject.DontDestroyOnLoad(adCanvas);
					adCanvas.AddComponent<RectTransform>();
					var canvas = adCanvas.AddComponent<Canvas>();
					canvas.renderMode = RenderMode.ScreenSpaceOverlay;
					canvas.sortingOrder = 1000;
					adCanvas.AddComponent<CanvasScaler>();
					adCanvas.AddComponent<GraphicRaycaster>();

					// Create ad
					var ad = new GameObject("AdButtonImage");
					ad.transform.parent = adCanvas.transform;
					adRect = ad.AddComponent<RectTransform>();
					adImage = ad.AddComponent<Image>();
					adImage.sprite = Resources.Load<Sprite>("Reign/Ads/AdLoading");
					adImage.preserveAspect = true;
					var button = ad.AddComponent<Button>();
					button.onClick.AddListener(adClicked);
				}

				// set default visible state
				Visible = desc.Visible;
				SetGravity(gravity);

				// load ad
				service.StartCoroutine(init(createdCallback));

				// set screen size changed callback
				ReignServices.ScreenSizeChangedCallback += ReignServices_ScreenSizeChangedCallback;
			}
			catch (Exception e)
			{
				Debug.LogError(e.Message);
				if (createdCallback != null) createdCallback(false);
			}
		}