Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

AdDuplex on Windows Universal

Discussion in 'Windows' started by dudedude123, Mar 9, 2015.

  1. dudedude123

    dudedude123

    Joined:
    Aug 24, 2013
    Posts:
    128
    I'm using Adduplex to put on my Windows Universal game but whenever I set up this code
    <Page
    x:Class="Template.MainPage"
    IsTabStop="false"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Template"
    xmlns:adduplex="clr-namespace:AdDuplex;assembly=AdDuplex.WindowsPhone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    <SwapChainPanel x:Name="DXSwapChainPanel">
    <Grid x:Name="ExtendedSplashGrid">
    <Image x:Name="ExtendedSplashImage" Source="Assets/SplashScreen.png" VerticalAlignment="Center" HorizontalAlignment="Center"/>
    <adduplex:AdControl x:Name="adDuplexAd" AppId="YOUR_AppId_HERE"/>
    </Grid>
    </SwapChainPanel>
    </Page>

    And this code

    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using System.IO;
    4. using System.Linq;
    5. using UnityEngine.Windows;
    6. using Windows.ApplicationModel.Activation;
    7. using Windows.Foundation;
    8. using Windows.Foundation.Collections;
    9. using Windows.Management.Deployment;
    10. using Windows.Storage;
    11. using Windows.UI;
    12. using Windows.UI.Core;
    13. using Windows.UI.Xaml;
    14. using Windows.UI.Xaml.Controls;
    15. using Windows.UI.Xaml.Controls.Primitives;
    16. using Windows.UI.Xaml.Data;
    17. using Windows.UI.Xaml.Input;
    18. using Windows.UI.Xaml.Media;
    19. using Windows.UI.Xaml.Navigation;
    20. using Windows.UI.Xaml.Interop;
    21.  
    22. // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
    23.  
    24. namespace Template
    25. {
    26.     /// <summary>
    27.     /// An empty page that can be used on its own or navigated to within a Frame.
    28.     /// </summary>
    29.     public sealed partial class MainPage : Page
    30.     {
    31.         private SplashScreen splash;
    32.         private Rect splashImageRect;
    33.         private WindowSizeChangedEventHandler onResizeHandler;
    34.  
    35.         public MainPage(SplashScreen splashScreen)
    36.         {
    37.             this.InitializeComponent();
    38.  
    39.             splash = splashScreen;
    40.             GetSplashBackgroundColor();
    41.             OnResize();
    42.             onResizeHandler = new WindowSizeChangedEventHandler((o, e) => OnResize());
    43.             Window.Current.SizeChanged += onResizeHandler;
    44.             Interop.AdDuplexDisabled += Interop_AdDuplexDisabled;
    45.  
    46.             Interop.AdDuplexEnabled += Interop_AdDuplexEnabled;
    47.  
    48.         }
    49.  
    50.         void Interop_AdDuplexEnabled(object sender, EventArgs e)
    51.         {
    52.  
    53.             Deployment.Current.Dispatcher.BeginInvoke(() =>
    54.             {
    55.  
    56.                 adDuplexAd.Visibility = System.Windows.Visibility.Visible;
    57.  
    58.             });
    59.  
    60.         }
    61.  
    62.  
    63.  
    64.         void Interop_AdDuplexDisabled(object sender, EventArgs e)
    65.         {
    66.  
    67.             Deployment.Current.Dispatcher.BeginInvoke(() =>
    68.             {
    69.  
    70.                 adDuplexAd.Visibility = System.Windows.Visibility.Collapsed;
    71.  
    72.             });
    73.  
    74.         }
    75.  
    76.  
    77.         /// <summary>
    78.         /// Invoked when this page is about to be displayed in a Frame.
    79.         /// </summary>
    80.         /// <param name="e">Event data that describes how this page was reached.  The Parameter
    81.         /// property is typically used to configure the page.</param>
    82.         protected override void OnNavigatedTo(NavigationEventArgs e)
    83.         {
    84.             splash = (SplashScreen)e.Parameter;
    85.             OnResize();
    86.         }
    87.  
    88.         private void OnResize()
    89.         {
    90.             if (splash != null)
    91.             {
    92.                 splashImageRect = splash.ImageLocation;
    93.                 PositionImage();
    94.             }
    95.         }
    96.  
    97.         private void PositionImage()
    98.         {
    99.             var inverseScaleX = 1.0f / DXSwapChainPanel.CompositionScaleX;
    100.             var inverseScaleY = 1.0f / DXSwapChainPanel.CompositionScaleY;
    101.  
    102.             ExtendedSplashImage.SetValue(Canvas.LeftProperty, splashImageRect.X * inverseScaleX);
    103.             ExtendedSplashImage.SetValue(Canvas.TopProperty, splashImageRect.Y * inverseScaleY);
    104.             ExtendedSplashImage.Height = splashImageRect.Height * inverseScaleY;
    105.             ExtendedSplashImage.Width = splashImageRect.Width * inverseScaleX;
    106.         }
    107.  
    108.         private async void GetSplashBackgroundColor()
    109.         {
    110.             try
    111.             {
    112.                 StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///AppxManifest.xml"));
    113.                 string manifest = await FileIO.ReadTextAsync(file);
    114.                 int idx = manifest.IndexOf("SplashScreen");
    115.                 manifest = manifest.Substring(idx);
    116.                 idx = manifest.IndexOf("BackgroundColor");
    117.                 if (idx < 0)  // background is optional
    118.                     return;
    119.                 manifest = manifest.Substring(idx);
    120.                 idx = manifest.IndexOf("\"");
    121.                 manifest = manifest.Substring(idx + 2); // also remove quote and # char after it
    122.                 idx = manifest.IndexOf("\"");
    123.                 manifest = manifest.Substring(0, idx);
    124.                 int value = Convert.ToInt32(manifest, 16) & 0x00FFFFFF;
    125.                 byte r = (byte)(value >> 16);
    126.                 byte g = (byte)((value & 0x0000FF00) >> 8);
    127.                 byte b = (byte)(value & 0x000000FF);
    128.  
    129.                 await CoreWindow.GetForCurrentThread().Dispatcher.RunAsync(CoreDispatcherPriority.High, delegate()
    130.                     {
    131.                         ExtendedSplashGrid.Background = new SolidColorBrush(Color.FromArgb(0xFF, r, g, b));
    132.                     });
    133.             }
    134.             catch (Exception)
    135.             { }
    136.         }
    137.  
    138.         public SwapChainPanel GetSwapChainPanel()
    139.         {
    140.             return DXSwapChainPanel;
    141.         }
    142.  
    143.         public void RemoveSplashScreen()
    144.         {
    145.             DXSwapChainPanel.Children.Remove(ExtendedSplashGrid);
    146.             if (onResizeHandler != null)
    147.             {
    148.                 Window.Current.SizeChanged -= onResizeHandler;
    149.                 onResizeHandler = null;
    150.             }
    151.         }
    152.  
    153. #if !UNITY_WP_8_1
    154.         protected override Windows.UI.Xaml.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
    155.         {
    156.             return new UnityPlayer.XamlPageAutomationPeer(this);
    157.         }
    158. #endif
    159.     }
    160. }
    161.  

    Bit I ran across these errors


    Error 9 The command "echo UnityInstallationDir 'C:\Program Files (x86)\Unity\Editor'
    echo UnityProjectDir 'C:\Users\Gary\Desktop\Beatdown'
    echo Copying assemblies...
    copy /Y "C:\Users\Gary\Desktop\Beatdown\Build\Windows 81\Beatdown\Beatdown.Windows\Unprocessed\*" "C:\Users\Gary\Desktop\Beatdown\Build\Windows 81\Beatdown\Beatdown.Windows\"
    echo Running AssemblyConverter...
    "C:\Program Files (x86)\Unity\Editor\Data\PlaybackEngines\metrosupport\Tools\AssemblyConverter.exe" -platform=wsa81 "C:\Users\Gary\Desktop\Beatdown\Build\Windows 81\Beatdown\Beatdown.Windows\\Assembly-CSharp-firstpass.dll" "C:\Users\Gary\Desktop\Beatdown\Build\Windows 81\Beatdown\Beatdown.Windows\\Assembly-CSharp.dll" "C:\Users\Gary\Desktop\Beatdown\Build\Windows 81\Beatdown\Beatdown.Windows\\Assembly-UnityScript.dll" "C:\Users\Gary\Desktop\Beatdown\Build\Windows 81\Beatdown\Beatdown.Windows\\Boo.Lang.dll" "C:\Users\Gary\Desktop\Beatdown\Build\Windows 81\Beatdown\Beatdown.Windows\\UnityEngine.dll" "C:\Users\Gary\Desktop\Beatdown\Build\Windows 81\Beatdown\Beatdown.Windows\\UnityEngine.UI.dll" "C:\Users\Gary\Desktop\Beatdown\Build\Windows 81\Beatdown\Beatdown.Windows\\WinControls.dll" "C:\Users\Gary\Desktop\Beatdown\Build\Windows 81\Beatdown\Beatdown.Windows\\WinRTLegacy.dll"
    echo AssemblyConverter done.
    " exited with code 3. Beatdown.Windows

    Error 7 The command "echo UnityInstallationDir 'C:\Program Files (x86)\Unity\Editor'
    echo UnityProjectDir 'C:\Users\Gary\Desktop\Beatdown'
    echo Copying assemblies...
    copy /Y "C:\Users\Gary\Desktop\Beatdown\Build\Windows 81\Beatdown\Beatdown.WindowsPhone\Unprocessed\*" "C:\Users\Gary\Desktop\Beatdown\Build\Windows 81\Beatdown\Beatdown.WindowsPhone\"
    echo Running AssemblyConverter...
    "C:\Program Files (x86)\Unity\Editor\Data\PlaybackEngines\metrosupport\Tools\AssemblyConverter.exe" -platform=wp81 "C:\Users\Gary\Desktop\Beatdown\Build\Windows 81\Beatdown\Beatdown.WindowsPhone\\Assembly-CSharp-firstpass.dll" "C:\Users\Gary\Desktop\Beatdown\Build\Windows 81\Beatdown\Beatdown.WindowsPhone\\Assembly-CSharp.dll" "C:\Users\Gary\Desktop\Beatdown\Build\Windows 81\Beatdown\Beatdown.WindowsPhone\\Assembly-UnityScript.dll" "C:\Users\Gary\Desktop\Beatdown\Build\Windows 81\Beatdown\Beatdown.WindowsPhone\\Boo.Lang.dll" "C:\Users\Gary\Desktop\Beatdown\Build\Windows 81\Beatdown\Beatdown.WindowsPhone\\UnityEngine.dll" "C:\Users\Gary\Desktop\Beatdown\Build\Windows 81\Beatdown\Beatdown.WindowsPhone\\UnityEngine.UI.dll" "C:\Users\Gary\Desktop\Beatdown\Build\Windows 81\Beatdown\Beatdown.WindowsPhone\\WinControls.dll" "C:\Users\Gary\Desktop\Beatdown\Build\Windows 81\Beatdown\Beatdown.WindowsPhone\\WinRTLegacy.dll"
    echo AssemblyConverter done.
    " exited with code 3. Beatdown.WindowsPhone

    Error 5 The name "AdControl" does not exist in the namespace "clr-namespace:AdDuplex;assembly=AdDuplex.WindowsPhone". C:\Users\Gary\Desktop\Beatdown\Build\Windows 81\Beatdown\Beatdown.Shared\MainPage.xaml 15 13 Beatdown.Windows

    Error 6 The type 'adduplex:AdControl' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built. C:\Users\Gary\Desktop\Beatdown\Build\Windows 81\Beatdown\Beatdown.Shared\MainPage.xaml 15 14 Beatdown.Windows


    I appreciate it if I can get this fixed
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,703
    Have you added a reference in Visual Studio solution?
     
  3. dudedude123

    dudedude123

    Joined:
    Aug 24, 2013
    Posts:
    128
    How I do that?
     
  4. DariusV

    DariusV

    Joined:
    Aug 26, 2014
    Posts:
    4