Showing posts with label VMware Fusion. Show all posts
Showing posts with label VMware Fusion. Show all posts

Unity3d : How to integrate AdMob - Interstitial for Windows Phone 8 (Not Unity-Plugin)

Unity3d : How to integrate AdMob - Interstitial for Windows Phone 8 (Not Unity-Plugin)

Test on:
- Mac OSX Yosemite
- MS Lumia 535 Dual Sim
- Windows 10 Preview
- Unity3d 32-bit 5.1.0f3 (For Windows)

[ Free source code]
Unity project: http://sh.st/PCLxx
Visual Studio 2013 project: http://sh.st/PCLTP

Pre-require:
- VMware Fusion (For Mac)
- Visual Studio 2013 or Above (For Windows)
- Windows Phone SDK (For Windows)
- Unity3d 32-bit/64-bit 5.1.0f3 (For Windows)
- Authenticator (For Windows Phone)
- AdMob (For Windows Phone 8) - download: https://developers.google.com/mobile-ads-sdk/download

*This tutorial for advance user that's already has all pre-require software installed properly. If you were not Mac User just focus ONLY windows software and windows os.


**Not included how to Visual Studio and Windows Phone SDK installation and setup

[Build for Windows Phone 8]
1. Open your project on windows os then goto File > Build Settings...


2. Choose "Windows Phone 8" and click "Build"


3. I'm create folder named "ExportWP8" and click "Select Folder"


4. waiting until build process successful.



5. Open "ExportWP8" folder, the .sln file ready for use in Visual Studio.



[Integrate AdMob]

1. Download AdMob (For Windows Phone 8) - here: https://developers.google.com/mobile-ads-sdk/download then extract and you should have be like this.


2. from [Build for Windows Phone 8] step 5. Open yourProjectName.sln with Visual Studio.

3. Under "Solution Explorer", right-click and choose "Add References..."


4. Click "Extension" and choose "Browse..."


5. Goto "GoogleMobileAdsSdkWindowsPhone8-6.5.13/lib/windowsphone8/" and select "GoogleAds.dll" then click "Add"


6. You should see result as below and then click "OK".


7. Now your project has GoogleAds integrated.



[AdMob Implement]
1. Next step, you need to modify and implement AdMob in your project, Open "MainPage.xaml.cs" and add 3 lines of code as below image.

using GoogleAds;
using UnityAdMobWP8.Resources; // [yourNamespace].Resources;
using System.Diagnostics; // For print debugging


2. Create variable for InterstitialAd, AdRequest, AdView, AdUnitID. You still need AdView although you not use Banner because of AdView use to represent Ads overlay on screen.


3. Under constructor "MainPage()" add many lines of code for implement AdMob type Interstitial and AdView for display as below image.


4. Add AdMob Listener for any event like below.


5. Under "Properties" section open "WMAppManifest.xml", click "Capabilities" and check all of list like this.
[/] ID_CAP_IDENTITY_DEVICE
[/] ID_CAP_IDENTITY_USER
[/] ID_CAP_MEDIALIB_AUDIO
[/] ID_CAP_MEDIALIB_PHOTO
[/] ID_CAP_MEDIALIB_PLAYBACK
[/] ID_CAP_SENSORS
[/] ID_CAP_WEBBROWSERCOMPONENT


6. Build your project by choose menu "BUILD > Build Solution".


7. Your result should be "1 succeeded" as below image, You're completed implement AdMob.



[Admob Testing]
1. Connect your "WindowsPhone" to Windows Desktop / Laptop or Mac (Choose connect Windows), Please make sure your WP connect to Windows 10 by goto Run > All apps > Windows Phone SDK 8.0/8.1 > Windows Phone Developer Registration


2. Click [>] "Green Arrow" icon and on the right side leave 3 fields as [ Device ][ Debug ][ ARM ].
[ Device ][ Debug ][ ARM ]. << For print ads debug log in console
[ Device ][ Master ][ ARM ]. << For publish to store
[ Device ][ Release ][ ARM ].  << For test ads without log in console


3. If anything goes well you should see unity logo when app launch then Ads Interstitial will appear.



[ Free source code]
Unity project: http://sh.st/PCLxx
Visual Studio 2013 project: http://sh.st/PCLTP

It's work. ;)

Unity3d : How to Control Show and Hide AdMob for Windows Phone 8 (Not Unity-Plugin)

Unity3d : How to Control Show and Hide AdMob for Windows Phone 8 (Not Unity-Plugin)

Test on:
- Mac OSX Yosemite
- MS Lumia 535 Dual Sim
- Windows 10 Preview
- Unity3d 64-bit 5.1.2 (For Windows)

[Free source code]
Unity project: http://sh.st/AWmIO
Visual Studio 2013 project: http://sh.st/AWmJQ

Pre-require:
- VMware Fusion (For Mac)
- Visual Studio 2013 or Above (For Windows)
- Windows Phone SDK (For Windows)
- Unity3d 32-bit/64-bit 5.1.2 (For Windows)
- Authenticator (For Windows Phone)
- AdMob (For Windows Phone 8) - download: https://developers.google.com/mobile-ads-sdk/download

[Create Unity project]
1. Create new unity project, then create Game Object > 3D Object > 3D Text and input any detail refer to below image.



[Unity : Create Button for Control Ads]
1. Goto Assets > create > C# script name "CallAdmobVS", then implement ads event handler and ads state for both Banner and Interstitial, see below image.


2. See in function Start() we need to implement more a bit to check Main Camera object existed.


3. Create function "FixedUpdate" for handling object event relate to ads state use for Banner only.


4. Create button for control ads state from unity process and more code to change flag update ads state to show or hide for Banner but for Interstitial just only show flag because it's can be close by self close button not unity button.


4. Add component "CallAdmobVS" to object "New Text" and drag "Main Camera" under "Hierarchy" to inspector at "Game Camera".

[ Attach script CallAdmobVS to New Text inspector

[Drag Main Camera and drop in field of CallAdmobVS]

5. Export your project for Windows Phone 8 click Build.


[Visual Studio : Add GoogleAds library]
1. Open your exported project in Visual Studio by click yourProject.sln


2. Right-click on References > Add Reference...


3. Browse... > GoogleAds.dll then checked box and click OK. Now you're ready to begin implement.


[Visual Studio : Create Ads state UI View]
Open "MainPage.xaml" and add code <TextBlock/> as below image for show Ads state on Visual Studio UI when receive update from Unity button.


[Visual Studio : Config GoogleAds requirement]
Open WMAppManifest.xml, goto capabilities then checked box like below list.
[/] ID_CAP_IDENTITY_DEVICE
[/] ID_CAP_IDENTITY_USER
[/] ID_CAP_MEDIALIB_AUDIO
[/] ID_CAP_MEDIALIB_PHOTO
[/] ID_CAP_MEDIALIB_PLAYBACK
[/] ID_CAP_NETWORKING
[/] ID_CAP_SENSORS
[/] ID_CAP_WEBBROWSERCOMPONENT


[Visual Studio : GoogleAds implement]
1. You need to include GoogleAds, Resources and Debugging for develop, debugging and publish. By then Open "MainPage.xaml.cs" follow add their lines of code like below image.



2. Begin declare variable for banner and interstitial, i just place dummy id for both of them like a "ca-app-pub-xxx/xxx" you need to replace with your real AdUnitID, for interstitial you need more variable as isCached for check already ads ready and AdView because of InterstitialAd not implement by AdView but it's need AdView to show overlay of interstitial.



3. Inside MainPage() function after line of bridge.Control, let's implement BannerAds by create AdView use for banner only, set your ads alignment, create callback ads event of received and fail to received. After that create AdRequest for load ads. The last thing you need is add banner object to drawing surface object to show on screen and Don't forget to call function to request interstitialAd.


4. On previous step we call function "RequestNewInterstitial()" on the last line, so this step we need to create that function. Set cache flag as false and create new interstitial object with adunitid parameter. For interstitial we need more callback event because it's can be close by itself and cover fullscreen, after that create adrequest and load ads. Do you remember we need drawing surface object and AdView to display ads but it's not need inside this function.


5. Take a break about AdView and drawing surface for interstitial. Start create implement callback function for Banner simple receive and fail to receive but two of them just only print debug log in console.


6. Back to Interstitial to create callback function and lack about cache flag and drawing surface. Inside receive function we need to set "cache as true", On dismiss overlay we change "cache to false" and "remove adview object from drawing surface" because dismiss overlay callback done by interstitial closed or remove from screen by click ads close button. Then call "RequestNewInterstitial()" function again for prepare next interstitial to show on next time.


7. Inside function "DrawingSurfaceBackground_Loaded" we need to reimplement from comment out of code to check callback event between Unity and Visual Studio.


8. From previous step we create callback Unity_Loaded() event then we need to create function of it to get object from "CallAdmobVS" and create callback event for Ads flag changed.


9. Create new function "AdmobStateChanged" to determine show or hide Banner by flag changed.


10. Next create function "InterStateChanged" to create AdView and add interstitial object to drawing surface and then call ShowAd() method. For interstitial we need to detect flag only true event for show because it's close and set flag false by dismiss overlay callback function.


Now you finish control ads from Unity.

[AdMob Control Testing]
1. Connect your "WindowsPhone" to Windows Desktop / Laptop or Mac (Choose connect Windows), Make sure your WP connect to VS and registered for test via usb cable. Goto start > All apps > Windows Phone SDK 8.0/8.1 > Windows Phone Developer > Registration (8.0/8.1).


2. Click [>] "Green Arrow" icon and on the right side leave 3 fields as [ Device ][ Debug ][ ARM ]. your app will launch automatically.
[ Device ][ Debug ][ ARM ] << For testing and debugging in console log
[ Device ][ Master ][ ARM ] << For publish to store
[ Device ][ Release ][ ARM ] << For testing without log

3. After Unity process finish loaded, you should see two button for test show/hide banner and show for interstitial, let's test by yourself.


[Free source code]
Unity project: http://sh.st/AWmIO
Visual Studio 2013 project: http://sh.st/AWmJQ

It's work. ;)

Unity3d : How to integrate AdMob - Banner for Windows Phone 8 (Not Unity-Plugin)

Unity3d : How to integrate AdMob - Banner for Windows Phone 8 (Not Unity-Plugin)

Test on:
- Mac OSX Yosemite
- MS Lumia 535 Dual Sim
- Windows 10 Preview
- Unity3d 32-bit 5.1.0f3 (For Windows)

[ Free source code ]
Unity3d project: http://sh.st/PZHtq
Visual Studio 2013 project: http://sh.st/PZHdn

Pre-require:
- VMware Fusion (For Mac)
- Visual Studio Community 2015 or Above (For Windows)
https://www.visualstudio.com/en-us/products/visual-studio-express-vs.aspx
- Windows Phone SDK (For Windows)
- Unity3d 32-bit/64-bit 5.1.0f3 (For Windows)
- Authenticator (For Windows Phone)
- AdMob (For Windows Phone 8) - download: https://developers.google.com/mobile-ads-sdk/download

*This tutorial for advance user that's already has all pre-require software installed properly. If you were not Mac User just focus ONLY windows software and windows os.

**Not included how to Visual Studio and Windows Phone SDK installation and setup

[Build for Windows Phone 8]
1. Open your project on windows os then goto File > Build Settings...


2. Choose "Windows Phone 8" and click "Build"


3. I'm create folder named "ExportWP8" and click "Select Folder"


4. waiting until build process successful.



5. Open "ExportWP8" folder, the .sln file ready for use in Visual Studio.



[Integrate AdMob]

1. Download AdMob (For Windows Phone 8) - here: https://developers.google.com/mobile-ads-sdk/download then extract and you should have be like this.


2. from [Build for Windows Phone 8] step 5. Open yourProjectName.sln with Visual Studio.

3. Under "Solution Explorer", right-click and choose "Add References..."


4. Click "Extension" and choose "Browse..."


5. Goto "GoogleMobileAdsSdkWindowsPhone8-6.5.13/lib/windowsphone8/" and select "GoogleAds.dll" then click "Add"


6. You should see result as below and then click "OK".


7. Now your project has GoogleAds integrated.



[AdMob Implement]
1. Next step, you need to modify and implement AdMob in your project, Open "MainPage.xaml.cs" and add 3 lines of code as below image.

using GoogleAds;
using UnityWP8AdMobBanner.Resources; // [your namespace].Resources;
using System.Diagnostics; // for print debug log in console


2. Create variable for AdRequest and AdView, this AdView for banner object that contain adUnitID and Format.


3. Under constructor "MainPage()" add many lines of code for implement AdMob type Banner as below image.


4. Add AdMob Listener for any event like below.


5. Under "Properties" section open "WMAppManifest.xml", click "Capabilities" and check all of list like this.
[/] ID_CAP_IDENTITY_DEVICE
[/] ID_CAP_IDENTITY_USER
[/] ID_CAP_MEDIALIB_AUDIO
[/] ID_CAP_MEDIALIB_PHOTO
[/] ID_CAP_MEDIALIB_PLAYBACK
[/] ID_CAP_SENSORS
[/] ID_CAP_WEBBROWSERCOMPONENT


6. Build your project by choose menu "BUILD > Build Solution".


7. Your result should be "1 succeeded" as below image, You're completed implement AdMob.



[AdMob Testing]
1. Connect your "WindowsPhone" to Windows Desktop / Laptop or Mac (Choose connect Windows), you must check the connection between WP and Windows 10 by goto run > All apps > Windows Phone SDK 8.0/8.1 > Windows Phone Developer Registration. If you seen like below image it's sure your phone already connected. If not and button show "retry" then try to reconnect your WP via usb again or "register" mean you need to register before test this app.


2. Click [>] "Green Arrow" icon and on the right side leave 3 fields as [ Device ][ Debug ][ ARM ]. This mode you can check log in console what happen to your app. Then you should check all 3 modes make sure your app work 100%.
[ Device ][ Debug ][ ARM ] << check app working log with this mode
[ Device ][ Master ][ ARM ] << for publish app to store
[ Device ][ Release ][ ARM ] << check app working without log

3. After app launch it's take a while to receive ads and callback to listener. Then you'll see banner ads.


[ Free source code ]
Unity3d project: http://sh.st/PZHtq
Visual Studio 2013 project: http://sh.st/PZHdn

It's work. ;)