microsoft / unityplugins

Unity Plugins for Windows Store and Azure related functions.
Other
81 stars 40 forks source link

Issue getting VideoAdsSample to display ads when built as Windows Store App #21

Open scotthavird opened 9 years ago

scotthavird commented 9 years ago

Issue: I am not able to see Video Ads when I deploy the Unity VideoAdsSample project as a Windows Store App. Below are the steps I am taking and the results.

  1. Ran the PowerShell script successfully.
  2. Opened the Unity Video Ad Sample project unityplugins-master\Samples\Advertising\VideoAdsSample
  3. Imported unityplugins-master\UnityPackages\Microsoft.UnityPlugins.Advertising
  4. I attempted to build the project as Window Store app and received the attached error unitybuilderror
  5. I was able to resolve the issue by changing the platforms for plugins from "Any Platform" to "Editor" on Assets/Plugins/Microsoft.UnityPlugins.Advertising advertisingdllplugin_editor
  6. I was then able to build for the Window Store
  7. I added Microsoft.UnityPlugins.Utils.Initialize((action) => AppCallbacks.Instance.InvokeOnAppThread(new AppCallbackItem(() => action()), false)) after Window.Current.Activate() within App.xaml.cs
  8. I rebuilt the solution for Release x86 and received the following error message. I have attached a screenshot and the output for Build and Debug. windows10applicationerror

\ BEGIN Output_Build.txt ***** 1>------ Build started: Project: VideoAdsSample, Configuration: Release x86 ------ 1> UnityInstallationDir "C:\Program Files\Unity\Editor". 1> UnityWSAPlayerDir "C:\Program Files\Unity\Editor\Data\PlaybackEngines\metrosupport". 1> UnityProjectDir "C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample". 1> Copying unprocessed assemblies... 1> Running AssemblyConverter... 1> AssemblyConverter done. 1> VideoAdsSample -> C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\VideoAdsSample.exe 1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\AppxPackage\Microsoft.AppXPackage.Targets(1778,5): warning APPX1707: No implementation file was provided for the .winmd file 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\Microsoft.Advertising.winmd'. To generate registration information in the app manifest, specify the 'Implementation' metadata on the .winmd reference item in the project file. 2>------ Deploy started: Project: VideoAdsSample, Configuration: Release x86 ------ 2>Updating the layout... 2>Copying files: Total 4 mb to layout... 2>Checking whether required frameworks are installed... 2>Registering the application to run from layout... 2>Deployment complete (913ms). Full package name: "VideoAdsSample_1.0.0.0_x86__pzq3xp76mxafg" ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ========== ========== Deploy: 1 succeeded, 0 failed, 0 skipped ========== ** END Output_Build.txt *****

**** BEGIN Output_Debug.txt ***** 'VideoAdsSample.exe' (CoreCLR: DefaultDomain): Loaded 'C:\Program Files\WindowsApps\Microsoft.NET.CoreRuntime.1.0_1.0.23302.0_x86__8wekyb3d8bbwe\mscorlib.ni.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\entrypoint\VideoAdsSample.exe'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Symbols for the module 'VideoAdsSample.exe' were not loaded.

  1. Use a debug build configuration or disable the debug option 'Enable Just My Code'.
  2. Check the 'Symbols' settings under debugging options.'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\System.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\WinMetadata\Windows.winmd'. Module was built without symbols. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\System.Runtime.InteropServices.WindowsRuntime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\UnityPlayer.winmd'. Module was built without symbols. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\System.Runtime.WindowsRuntime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\System.Runtime.WindowsRuntime.UI.Xaml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\Microsoft.UnityPlugins.Common.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\System.Collections.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\WinRTBridge.winmd'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\BridgeInterface.winmd'. Module was built without symbols. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\System.Private.Uri.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\System.Threading.Tasks.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\UnityEngine.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\Assembly-CSharp-firstpass.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\Assembly-CSharp.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\UnityEngine.Networking.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\UnityEngine.UI.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\System.IO.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\System.Net.Primitives.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\System.Private.Networking.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\System.Reflection.Primitives.dll'. Module was built without symbols. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\System.Reflection.dll'. Module was built without symbols. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\System.Text.Encoding.dll'. Module was built without symbols. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\System.Runtime.InteropServices.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\System.Threading.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\System.Runtime.Extensions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\System.Diagnostics.Debug.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Module information: Built with Compiler Ver '190023026' Built from '5.2/release' branch Version is '5.2.2f1 (3757309da7e7)' Release build Application type 'XAML' Used 'UWP'

PlayerConnection initialized from C:/Users/scott.havird/Downloads/unityplugins-master_1.0/unityplugins-master/Samples/Advertising/VideoAdsSample/out_2015.11.02_pm/VideoAdsSample/bin/x86/Release/AppX/Data (debug = 0)

PlayerConnection initialized network socket : 0.0.0.0 55179

Multi-casting "[IP] 10.0.1.6 [Port] 55179 [Flags] 2 [Guid] 1889589057 [EditorId] 4294967295 [Version] 1048832 [Id] MetroPlayerX86(DESKTOP-F93AH1S) [Debug] 0" to [225.0.0.222:54997]...

GfxDevice: creating device client; threaded=1

Disabling Low Latency presentation API.

Direct3D:

Version:  Direct3D 11.0 [level 11.0]

Renderer: NVIDIA GeForce GT 750M    (ID=0xfe9)

Vendor:   NVIDIA

VRAM:     1990 MB

Initialize engine version: 5.2.2f1 (3757309da7e7)

Disabling independent input source.

Logical Screen DPI is 144.00.

'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\UnityEngineProxy.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\Microsoft.UnityPlugins.Advertising.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\System.Linq.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\System.Text.RegularExpressions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'VideoAdsSample.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\bin\x86\Release\AppX\System.Globalization.dll'. Module was built without symbols. Start-ad initiation

(Filename: C:/buildslave/unity/build/artifacts/generated/Metro/runtime/UnityEngineDebugBindings.gen.cpp Line: 70)

Exception: Object reference not set to an instance of an object. Type: System.NullReferenceException Module: Assembly-CSharp InnerException: AdditionalInfo: at mainSceneManager.Start() at mainSceneManager.$Invoke7(Int64 instance, Int64* args) at UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method)

(Filename: Line: 0)

NullReferenceException: Object reference not set to an instance of an object. at mainSceneManager.Start() at mainSceneManager.$Invoke7(Int64 instance, Int64* args) at UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method) (Filename: Line: 0)

NullReferenceException: Object reference not set to an instance of an object. at mainSceneManager.RequestAd() at UnityEngine.Events.InvokableCall.Invoke(Object[] args) at UnityEngine.Events.InvokableCallList.Invoke(Object[] parameters) at UnityEngine.UI.Button.Press() at UnityEngine.UI.Button.OnPointerClick(PointerEventData eventData) at UnityEngine.EventSystems.ExecuteEvents.Execute(IPointerClickHandler handler, BaseEventData eventData) at UnityEngine.EventSystems.ExecuteEvents.Execute[T](GameObject target, BaseEventData eventData, EventFunction`1 functor) (Filename: Line: 0)

NullReferenceException: Object reference not set to an instance of an object. at mainSceneManager.ShowAd() at UnityEngine.Events.InvokableCall.Invoke(Object[] args) at UnityEngine.Events.InvokableCallList.Invoke(Object[] parameters) at UnityEngine.UI.Button.Press() at UnityEngine.UI.Button.OnPointerClick(PointerEventData eventData) at UnityEngine.EventSystems.ExecuteEvents.Execute(IPointerClickHandler handler, BaseEventData eventData) at UnityEngine.EventSystems.ExecuteEvents.Execute[T](GameObject target, BaseEventData eventData, EventFunction`1 functor) (Filename: Line: 0)

Trimming D3D resources.

The program '[14168] VideoAdsSample.exe: Program Trace' has exited with code 0 (0x0). The program '[14168] VideoAdsSample.exe' has exited with code 1 (0x1). **** END Output_Debug.txt *****

The output for the build shows some interesting information, line 9 from Output_Build.txt"C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\AppxPackage\Microsoft.AppXPackage.Targets(1778,5): warning APPX1707: No implementation file was provided for the .winmd file 'C:\Users\scott.havird\Downloads\unityplugins-master_1.0\unityplugins-master\Samples\Advertising\VideoAdsSample\out_2015.11.02_pm\VideoAdsSample\Microsoft.Advertising.winmd'. To generate registration information in the app manifest, specify the 'Implementation' metadata on the .winmd reference item in the project file." Could this be why I am recieving the null reference exception?

Setup: unityplugins version 1.0 Visual Studio Enterpirse 2015 Version 14.0.23107.0 D14REL .NET Framework Version 4.6.00079

Thanks, Scott

sanjeevdwivedi commented 9 years ago

Assigned to Kevin for further investigation

CesarSilvaCP commented 8 years ago

some solution to this problem?

khmaies5 commented 8 years ago

this is how i integrated microsoft video ads to my unity game, maybe it will work for you too just add IMicrosoftAdsBridge.cs and MicrsoftAdsEditor.cs to your unity project then add this to your script

using Microsoft.UnityPlugins;
private IInterstittialAd ad;
private const string appId = "YourAppID";
private string adUnitId = "YourAdunitID";
private static int count = 0;

void Start()
    {

        ad = MicrosoftAdsBridge.InterstitialAdFactory.CreateAd(OnAdReady, OnAdCompleted, OnAdCancelled, OnAdError);
    }

  public void ShowAd()
    {

        ad.Show();

    }

    public void RequestAd()
    {

        ad.Request(appId, nextAd, AdType.Video);

    }

    protected string nextAd
    {
        get
        {

            string[] adUnitIds = new string[] { "AdunitID", "AdUnitID", "0" };
            return adUnitIds[count % adUnitIds.Length];
        }
    }

    void OnAdReady(object unused)
    {
        //status.text = ad.State.ToString();
    }

    void OnAdCompleted(object unused)
    {
       // status.text = ad.State.ToString();
    }
    void OnAdCancelled(object unused)
    {
        //status.text = ad.State.ToString();
    }
    void OnAdError(object param)
    {
         AdErrorEventArgs args = param as AdErrorEventArgs;
         if (args != null)
             //status.text = "Error: " + args.ErrorMessage;
         System.Diagnostics.Debug.WriteLine(args);
        Interop.ShowInterstitialAd();

    }

then call RequestAd() before ShowAd(). for exemple call RequestAd() when your level start and ShowAd() when the player dies.

and on visual studio windows phone or windows project you must add this script MicrosoftAdsBridge.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using UnityPlayer;
namespace Microsoft.UnityPlugins
{
    internal class InterstitialAd : IInterstittialAd
    {

        private Microsoft.Advertising.WinRT.UI.InterstitialAd _ad;
        private Action<object> readyCallback;
        private Action<object> completedCallback;
        private Action<object> errorCallback;
        private Action<object> cancelledCallback;
        private bool showWhenReady = false;
        private bool hasPendingAdRequest = false;

        public InterstitialAd()  
        {
            _ad = new Microsoft.Advertising.WinRT.UI.InterstitialAd();
            _ad.AdReady += _ad_AdReady;
            _ad.Completed += _ad_Completed;
            _ad.Cancelled += _ad_Cancelled;
            _ad.ErrorOccurred += _ad_ErrorOccurred; 

        }

        public InterstitialAd(
            Action<object> readyCallback, Action<object> completedCallback,
            Action<object> cancelledCallback,
            Action<object> errorCallback)  : this( )
        {
            this.readyCallback = readyCallback;
            this.completedCallback = completedCallback;
            this.errorCallback = errorCallback;
            this.cancelledCallback = cancelledCallback; 

        }

        public InterstitialAdState State
        {
            get
            {
                return (InterstitialAdState) _ad.State;                
            }
        }

        public void AddCallback(AdCallback type, Action<object> cb)
        {
            if (_ad == null ) 
                throw new InvalidOperationException("No ad");

            switch (type)
            {
                case AdCallback.Cancelled:
                    cancelledCallback = cb; 
                    break; 
                case AdCallback.Completed:
                    completedCallback = cb; 
                    break; 
                case AdCallback.Error:
                    errorCallback = cb; 
                    break ; 
                case AdCallback.Ready:
                    readyCallback = cb; 
                   break ;                      
            }
        }

        private void _ad_AdReady(object sender, object e)
        {
            hasPendingAdRequest = false; 
            Marshal(this.readyCallback, e);
            if (showWhenReady)
                Show(); 
        }

        private void _ad_ErrorOccurred(object sender, Microsoft.Advertising.WinRT.UI.AdErrorEventArgs e)
        {
            Microsoft.UnityPlugins.AdErrorEventArgs arg = new Microsoft.UnityPlugins.AdErrorEventArgs( 
                (Microsoft.UnityPlugins.ErrorCode)e.ErrorCode, e.ErrorMessage);
            Marshal(this.errorCallback, arg);
        }

        private void _ad_Completed(object sender, object e)
        {
            Marshal(this.completedCallback, e); 
        }

        private void _ad_Cancelled(object sender, object e)
        {
            Marshal(this.cancelledCallback, e); 
        }

        void Marshal(Action<object> cb, object e)
        {
            if ( cb != null )
            {  
                AppCallbacks.Instance.InvokeOnAppThread( () => { cb(e);  } , true );
            }
        }
        public void ClearCallback(AdCallback type)
        {
            switch (type)
            {
                case AdCallback.Cancelled:
                    cancelledCallback = null;  
                    break;
                case AdCallback.Completed:
                    completedCallback = null; 
                    break;
                case AdCallback.Error:
                    errorCallback = null; 
                    break;
                case AdCallback.Ready:
                    readyCallback = null; 
                    break;
            }
        }

        public void Dispose()
        {
            ClearCallback(AdCallback.Cancelled);
            ClearCallback(AdCallback.Error); 
            ClearCallback(AdCallback.Completed);
            ClearCallback(AdCallback.Ready);
            this._ad = null; 
        }

        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); 
        }

        public void RequestAndShow(string appId, string adUnitId)
        {
            showWhenReady = true; 
            Request( appId, adUnitId, AdType.Video);
        }

        public void Show()
        {
            if (_ad.State == Microsoft.Advertising.WinRT.UI.InterstitialAdState.Ready)
            {
                showWhenReady = false;
                AppCallbacks.Instance.InvokeOnUIThread(() =>
                {
                    //TODO: this try/catch does not get c++ unhandled exceptions that ad sdk throws 
                    try
                    {
                        _ad.Show();
                    }
                    catch (Exception ex)
                    {
                        Marshal(this.errorCallback, new Microsoft.UnityPlugins.AdErrorEventArgs(
                         Microsoft.UnityPlugins.ErrorCode.Other, ex.Message));
                        Marshal(this.completedCallback, null); 
                    }
                }, true );                  
            } 
            else if (_ad.State == Microsoft.Advertising.WinRT.UI.InterstitialAdState.NotReady &&
                     hasPendingAdRequest)
            {
                showWhenReady = true; 
            }  
        }
    }

    internal class MicrosoftAdsFactory : Microsoft.UnityPlugins.IInterstitialAdFactory
    {
        public IInterstittialAd CreateAd()
        {
            return new InterstitialAd(); 
        }

        public IInterstittialAd CreateAd( Action<object> readyCallback, Action<object> completedCallback, Action<object> cancelledCallback, Action<object> errorCallback)
        {
            InterstitialAd ad = new InterstitialAd ( readyCallback, completedCallback,  cancelledCallback , errorCallback );

            return ad;  
        }
    }
}

and finally add this code to app.xaml.cs before Window.Current.Activate();

Microsoft.UnityPlugins.MicrosoftAdsBridge.InterstitialAdFactory = new Microsoft.UnityPlugins.MicrosoftAdsFactory();
CesarSilvaCP commented 8 years ago

Hi khmaies5 ! Thanks a lot for the help ! The error is gone, now is working right. Only the video that is not displayed, but the script is running fine, I think the problem now should be in my app setting in Windows Dev.

Again, thank you for the help!

khmaies5 commented 8 years ago

You are welcome Make sure to test it with test Ad Unit

Video Interstitial ad unit test value

AdUnitId 11389925 AppId d25517cb-12d4-4699-8bdc-52040c712cab

TG-one commented 8 years ago

Hi khmaies5, I am also trying your suggested fix and it is not working. I have created a test project in Unity that uses a button to cycle between 3 scenes. Using monoDevelop as the external scripting editor tool. When the button is pressed I want to show an Interstitial Ad and when the Ad is done then the next scene will be displayed and so on.

I have added "IMicrosoftAdsBridge.cs" and "MicrsoftAdsEditor.cs" to my project. I have added the script you mentioned (the script that containing private IInterstittialAd ad; private const string appId = "YourAppID"; private string adUnitId = "YourAdunitID"; private static int count = 0; the functions ShowAd(), RequestAd(), nextAd etc.) to my code.

Button press script is simply this void Start() { ad = MicrosoftAdsBridge.InterstitialAdFactory.CreateAd(OnAdReady, OnAdCompleted, OnAdCancelled, OnAdError); RequestAd(); } public void LoadScene (int level) { ShowAd(); SceneManager.LoadScene(level); }

I get an error in the OnAdError function at the last line Interop.ShowInterstitialAd(); Error is: The name "Interop" does not exist in the current context.

Your help on this error is appreciated.

khmaies5 commented 8 years ago

Oh sorry the Interop.ShowInterstitialAd(); belong to Adduplex not Microsoft ads you can delete it

TG-one commented 8 years ago

Okay, thank you. I will delete Interop.ShowInterstitialAd();

What about the code you suggest to add called "MicrosoftAdsBridge.cs"

and on visual studio windows phone or windows project you must add this script MicrosoftAdsBridge.cs

`using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using UnityPlayer; namespace Microsoft.UnityPlugins { internal class InterstitialAd : IInterstittialAd {

    private Microsoft.Advertising.WinRT.UI.InterstitialAd _ad;
    private Action<object> readyCallback;
    private Action<object> completedCallback; `

etc etc ... Do I need that code?

khmaies5 commented 8 years ago

yes you must add that script as i said and don't forget to add

Microsoft.UnityPlugins.MicrosoftAdsBridge.InterstitialAdFactory = new Microsoft.UnityPlugins.MicrosoftAdsFactory();

to app.xaml.cs before Window.Current.Activate();

and to test it put the test unit id not your adunit id

TG-one commented 8 years ago

Okay, I created a new script called "MicrosoftAdsBridge.cs" (different from "IMicrosoftAdsBridge.cs") and added all of that code. I now get a number of errors: The first is on the line "using System.Threading.Tasks;" The error is : Assets/Plugins/MicrosoftAdsBridge.cs(7,24): error CS0234: The type or namespace name Tasks' does not exist in the namespaceSystem.Threading'. Are you missing an assembly reference?

Suggestions?

khmaies5 commented 8 years ago

no you put MicrosoftAdsBridge.cs in the generated windows phone project not in unity microsoft

TG-one commented 8 years ago

Okay, I will do that

Please also confirm that I Do Not need to import the "Microsoft.UnityPlugins.Advertising.unityPackage" into my Unity project.

khmaies5 commented 8 years ago

No you dont need to

CesarSilvaCPS commented 8 years ago

Hi khmaies5 ! Sorry about the delay to return the results. I used the "Video Interstitial ad unit test value" and worked well ! But when I try with my Video Interstitial ad unit value, he output the following error: XML Invalid. This has happened to you?

error_invalidxml

CesarSilvaCPS commented 8 years ago

To understand the problem (see the output message ) I used the example: Video Ads Sample

khmaies5 commented 8 years ago

if it worked with the test AdId that mean the code is working but maybe with your id there is no ads to show

TG-one commented 8 years ago

I have added the new class MicrosoftAdsBridge.cs and also added a refrence called "Microsoft Advertising Universal SDK" to the references section of Solution Explorer.

There are two spots in App.xaml.cs that have Windows.Current.Activate(); I have added the new line as follows:

`if (rootFrame == null && !appCallbacks.IsInitialized()) { rootFrame = new Frame(); Window.Current.Content = rootFrame; Window.Current.Activate();

            rootFrame.Navigate(typeof(MainPage));
        }

        Microsoft.UnityPlugins.MicrosoftAdsBridge.InterstitialAdFactory = new Microsoft.UnityPlugins.MicrosoftAdsFactory();
        Window.Current.Activate();
    }`

Please confirm that this is the correct spot.

TG-one commented 8 years ago

When I try to test (using the test appId = "d25517cb-12d4-4699-8bdc-52040c712cab" and adUnitId = "11389925") I do not get a test Ad during the RequestAd() call and I get a similar error to CesarSilvaCPS. "Error: Invalid XML" windows ads error

The VS output is Module information: Built with Compiler Ver '190023026' Built from '5.3/patch-release' branch Version is '5.3.3p2 (86ede31d5f8d)' Debug build Application type 'XAML' Used 'UWP'

PlayerConnection initialized from C:/Users/T/Documents/Unity Projects/AdvertisingTestv5.3.3/Build_uni10_withAds3/AdvertisingTestv5.3.3/bin/x86/Debug/AppX/Data (debug = 0)

PlayerConnection initialized network socket : 0.0.0.0 55008

Multi-casting "[IP] 192.168.1.74 [Port] 55008 [Flags] 2 [Guid] 2358763800 [EditorId] 4294967295 [Version] 1048832 [Id] MetroPlayerX86(T-Laptop) [Debug] 0" to [225.0.0.222:54997]...

Exception thrown: 'System.FormatException' in mscorlib.ni.dll GfxDevice: creating device client; threaded=1

Disabling Low Latency presentation API.

Direct3D:

Version:  Direct3D 11.0 [level 11.0]

Renderer: AMD Mobility Radeon HD 5000 Series (ID=0x68e0)

Vendor:   ATI

VRAM:     1398 MB

Initialize engine version: 5.3.3p2 (86ede31d5f8d)

Disabling independent input source.

Logical Screen DPI is 96.00.

The following GlobalManagers were stripped from the build (Either because they're not used or not supported on this platform): NetworkManager MasterServerInterface UnityAdsSettings ClusterInputManager CloudWebServicesManager UnityAnalyticsManager UnityConnectSettings

UnloadTime: 979.610474 ms

Unloading 4 Unused Serialized files (Serialized files now loaded: 0)

UnloadTime: 126.115379 ms

Unloading 0 Unused Serialized files (Serialized files now loaded: 0)

Unloading 3 unused Assets to reduce memory usage. Loaded Objects now: 164. Operation took 474.374908 ms.

System memory in use: 16.3 MB.

Any suggestions??? Thank you again for answering all of these questions

khmaies5 commented 8 years ago

the placement of the code in app.xaml.cs is correct @CesarSilvaCPS try to create new unity project and don't test with video ad sample project @CesarSilvaCPS & @TG-one check the Internet(client server) capability maybe its not enable capturehh

TG-one commented 8 years ago

I have Internet (Client) checked. Should it be Internet(Client & Server)? I will test

TG-one commented 8 years ago

I still get the same Error: Invalid XML with Internet (Client & Server) checked

TG-one commented 8 years ago

I have been able to get the VideoAd Samples project to display the test Ads properly ?? So I know I must be very close to getting this to work on my own test project.

khmaies5 commented 8 years ago

@TG-one so you fixed the problem ?

TG-one commented 8 years ago

No. I cannot make it work with my own test project.

What about the statement "using System.Net;" should I have that in my project code?

khmaies5 commented 8 years ago

i created a working test project i am uploading it, my internet speed is not good so that will take some time

TG-one commented 8 years ago

I am going thru my code line by line comparing to yours and I just noticed in the line `protected string nextAd { get {

        string[] adUnitIds = new string[] { "AdunitID", "AdUnitID", "0" };
        return adUnitIds[count % adUnitIds.Length];
    }
}`

that I never changed the "AdunitID" to test values.

I will now test and see if that fixed it.

khmaies5 commented 8 years ago

here is a unity project build it to windows 10 and then ad the internet capability and the MicrosoftAdsBridge.cs class then add the code that i told you to app.xaml.cs and test it i am sure that it will work MicrosoftAdsTest.zip

TG-one commented 8 years ago

What about "using System.net;"

Do I need that?

TG-one commented 8 years ago

I now have it working in my test project and am confident that I can successfully make this work in my actual game. Thank you, thank you, thank you for all of your help.

If you would be so kind to answer a few more questions. I have a few questions about your code and your answers would increase my knowledge up a notch.

I see that you have a couple of time delay variables in the MicrosoftAdsEditor.cs code. private IEnumerator PrepareError() {
fireError = false; yield return new WaitForSeconds(1f);

private IEnumerator PrepareRequest() { yield return new WaitForSeconds(1f);

public void Show() {... if (state == InterstitialAdState.Ready ) { state = InterstitialAdState.Showing; StartCoroutine(DoShow(10f));

Why?

khmaies5 commented 8 years ago

to learn about it and increase your knowledge take a look to this links http://csharpindepth.com/Articles/Chapter11/StreamingAndIterators.aspx http://docs.unity3d.com/ScriptReference/WaitForSeconds.html

TG-one commented 8 years ago

Thank you for those links.

Another question, the MSDN website indicates that Interstitial Ads here should use event code.

// wire up all 4 events, see below for function templates MyVideoAd.AdReady += MyVideoAd_AdReady; MyVideoAd.ErrorOccurred += MyVideoAd_ErrorOccurred; MyVideoAd.Completed += MyVideoAd_Completed; MyVideoAd.Cancelled += MyVideoAd_Cancelled;

if ((InterstitialAdState.Ready) == (MyVideoAd.State)) { MyVideoAd.Show(); }

void MyVideoAd_AdReady(object sender, object e) { // code }

void MyVideoAd_ErrorOccurred(object sender, AdErrorEventArgs e) { // code }

void MyVideoAd_Completed(object sender, object e) {
// code }

void MyVideoAd_Cancelled(object sender, object e) { // code }

I have not compared your code to this is in detail, but how similar is your code to the MSDN event code?

khmaies5 commented 8 years ago

In the test project i added all this events you can check it out

TG-one commented 8 years ago

Yes, I see all of that now. Thank you

This procedure says it only works for Windows 10.

Is there a different procedure or any recommended changes to target Windows 8 / 8.1 devices?

khmaies5 commented 8 years ago

you can use it on wp8.1 too i didn't try it on 8

mrpacogp commented 8 years ago

Well, i just found this thread. Looking so many time for a step by step guide to get video ads on my project. This is working for microsoft ads on any windows device?

khmaies5 commented 8 years ago

@mrpacogp as i mentioned above i tested it on UWP and Win/WP 8.1 and its working

mrpacogp commented 8 years ago

Thank you very much. I just have finished to compile with powershell without any errors. Have opened the videoad sample and imported the asset of unity ads. Now i get an error, microsoft.unitypluggins.advertising.dll is used from several locations. Should i removed from all folder or specify in each folder like /plugins/wsa/x86 to each platform? p.d. I just have read your answer on another thread. I got Microsoft.UnityPlugins.Advertisiing on /plugins/wsa/arm and x64 and x86, all of 3 with wsaplayer checked.

khmaies5 commented 8 years ago

just add IMicrosoftAdsBridge.cs and MicrsoftAdsEditor.cs not the plugin go up and read my first reply and follow what i said or download this test project but you must read my reply first https://github.com/Microsoft/unityplugins/files/180485/MicrosoftAdsTest.zip

mrpacogp commented 8 years ago

well, thank you very much for your answer, just found this thread http://forum.unity3d.com/threads/microsoft-unityplugins-advertising.389379/ Ok, i stop here. Delete all of this plugins and only use your two files. let me see.. 404 on your link, but got this two files.

khmaies5 commented 8 years ago

go through the replies and you will find the working link

mrpacogp commented 8 years ago

Well, let me tell you. I have followed all the steps, using your test id for app. I have make it a file on visual studio, but dont where to put in. I show you on picture. After that, on references added ad mediator sdk. Next modify app.xaml.cs with your code also. But i have missed something because its compile but do not show any video. videora While debugging i get this error: "Microsoft.UnityPlugins.AdErrorEventArgs" And how to do that step: I have added the new class MicrosoftAdsBridge.cs and also added a refrence called "Microsoft Advertising Universal SDK" to the references section of Solution Explorer.

mrpacogp commented 8 years ago

well, i think my problem its because i compiled for phone 8.1 and i cant fint to reference universal ads sdk. Could be this the problem? I onliy got a wp8.1 device to testing... Now with your zip, i have added MicrosoftAdsBridge and the other line to xmalp.cs but when i compile still the same problem, i click on request ad and see requesting... wait a few seconds but do not show when i click show ad

sanjeevdwivedi commented 8 years ago

AFAIK, the Ads SDK is only available for Win10 (phone and tablet), and we have not tested it with 8.1 so not sure you can get it to work with 8.1

On Mon, Mar 21, 2016 at 10:41 AM, Francisco gimenez < notifications@github.com> wrote:

well, i think my problem its because i compiled for phone 8.1 and i cant fint to reference universal ads sdk. Could be this the problem? I onliy got a wp8.1 device to testing...

— You are receiving this because you were assigned. Reply to this email directly or view it on GitHub https://github.com/Microsoft/unityplugins/issues/21#issuecomment-199396181

http://satkriti.com 404-513-2954 (cell)

mrpacogp commented 8 years ago

WOW!!!! Wait a moment!!! After a few seconds its showing!!!!!! Working on windows phone 8.1 also!! Well! I love you all!!! I got a project with 1k download each day and with vungle ads only working for wp10! Well, now its recommended to compile for phone 8.1 , universal10? , i only got one device. What you could recommended me?

sanjeevdwivedi commented 8 years ago

Great to know and Kudos for your persistence in getting it working!!

On Mon, Mar 21, 2016 at 10:43 AM, Francisco gimenez < notifications@github.com> wrote:

WOW!!!! Wait a moment!!! After a few seconds its showing!!!!!! Working on windows phone 8.1 also!!

— You are receiving this because you were assigned. Reply to this email directly or view it on GitHub https://github.com/Microsoft/unityplugins/issues/21#issuecomment-199397579

http://satkriti.com 404-513-2954 (cell)

khmaies5 commented 8 years ago

For win/wp 8.1 you need to add refrence to admediator sdk instead of universal ads sdk

khmaies5 commented 8 years ago

Make your app available for windows 10 and 8.1 because 50% of windows phone devices will not get windows 10 that what i am doing

mrpacogp commented 8 years ago

Thank you !! My question its, its ok if i compile for phone8.1? I got published my app and got 85% users from wp8.1 and a few users with wp10

mrpacogp commented 8 years ago

I have downloaded my app just published, and with my appid and addunitid i cant watch any ad. Only if use test id, this is because my device is recognized as developer device and cant watch ads? Should i rate my app for +12 age to get ads?

mrpacogp commented 8 years ago

adsa I just have published another version with rate +12 and this permission. Downloaded Admediator config and put the setup on visual studio asacaptura What more i need? Blood of an Unicorn?