unity在wp8平台下添加微软广告

转自蛮牛

之前在弄unity时找到的,以下是关键代码

System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                DispatcherTimer _dispatcherTimer = new DispatcherTimer();
                _dispatcherTimer.Interval = TimeSpan.FromSeconds(5);    //延时添加广告控件
                _dispatcherTimer.Tick += (sender, e) =>
                {
                    _dispatcherTimer.Stop();

                    if (adControl == null)
                    {
                        adControl = new Microsoft.Advertising.Mobile.UI.AdControl("test_client", "Image320_50", true);
                        adControl.Width = 480;
                        adControl.Height = 80;
                        //adControl.AdRefreshed += adControl_AdRefreshed;       //广告成功
                        //adControl.ErrorOccurred += adControl_ErrorOccurred;   //广告错误
                        adControl.Margin = new Thickness(0, 720, 0, 0);

                        //添加广告控件
                        DrawingSurfaceBackground.Children.Add(adControl);
                    }
                };
                _dispatcherTimer.Start();
            });

            System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                if (adControl != null)
                {
                    adControl.Margin = new Thickness(10, 10, 0, 0);
                    adControl.Visibility = Visibility.Visible;
                }
            });


你可能感兴趣的:(wp,unity)