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

来源:互联网 发布:大数据系统架构图 编辑:程序博客网 时间:2024/06/10 00:54

之前在弄unity时在蛮牛找到了wp8加广告的方法,然后自己改进了一下,wp8.1下可用,以下是关键代码

<span style="white-space:pre"></span>private void creatAD(){            DispatcherTimer _dispatcherTimer = new DispatcherTimer();            _dispatcherTimer.Interval = TimeSpan.FromSeconds(0.1); //延时添加广告控件            _dispatcherTimer.Tick += (sender, e) =>            {                _dispatcherTimer.Stop();                if (adControl == null){                    adControl = new Microsoft.Advertising.Mobile.UI.AdControl()                    {                        AutoRefreshIntervalInSeconds = 60,                        ApplicationId = "test_client",                        AdUnitId = "Image320_50",                        VerticalAlignment = VerticalAlignment.Bottom,                        HorizontalAlignment = HorizontalAlignment.Left,                    IsBackgroundTransparent = true,                    };    adControl.Height = 80;                    adControl.Width = 480;                    adControl.IsAutoRefreshEnabled = true;                    adControl.Margin = new Thickness(0, 0, 0, 0);                }            };            _dispatcherTimer.Start();        }private async void showAD(){            await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>            {                if (adControl != null)                {                    DXSwapChainPanel.Children.Add(adControl);                    adControl.Margin = new Thickness(0, 0, 0, 0);                    adControl.Height = 80;                    adControl.Width = 480;                }            });}private async void HideAD(){await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>{if (DXSwapChainPanel.Children.Contains(adControl)){DXSwapChainPanel.Children.Remove(adControl);}});}


0 0
原创粉丝点击