Google Play games services, FINALLY!
This commit is contained in:
parent
247912cbc9
commit
459ab78bee
9 changed files with 65 additions and 30 deletions
|
@ -3,6 +3,8 @@ using Android.App;
|
||||||
using Android.Content;
|
using Android.Content;
|
||||||
using Android.Content.PM;
|
using Android.Content.PM;
|
||||||
using Android.Gms.Ads;
|
using Android.Gms.Ads;
|
||||||
|
using Android.Gms.Common;
|
||||||
|
using Android.Gms.Games;
|
||||||
using Android.OS;
|
using Android.OS;
|
||||||
using Android.Views;
|
using Android.Views;
|
||||||
using Android.Widget;
|
using Android.Widget;
|
||||||
|
@ -27,6 +29,7 @@ namespace Android {
|
||||||
public class Activity1 : AndroidGameActivity {
|
public class Activity1 : AndroidGameActivity {
|
||||||
|
|
||||||
private GameImpl game;
|
private GameImpl game;
|
||||||
|
private AndroidPlatform platform;
|
||||||
private LinearLayout mainView;
|
private LinearLayout mainView;
|
||||||
|
|
||||||
protected override void OnCreate(Bundle bundle) {
|
protected override void OnCreate(Bundle bundle) {
|
||||||
|
@ -38,7 +41,8 @@ namespace Android {
|
||||||
|
|
||||||
// set up the game
|
// set up the game
|
||||||
TextInputWrapper.Current = new TextInputWrapper.Mobile();
|
TextInputWrapper.Current = new TextInputWrapper.Mobile();
|
||||||
this.game = new GameImpl(new AndroidPlatform(this, adLayout));
|
this.platform = new AndroidPlatform(this, adLayout);
|
||||||
|
this.game = new GameImpl(this.platform);
|
||||||
this.game.GraphicsDeviceManager.ResetWidthAndHeight(this.game.Window);
|
this.game.GraphicsDeviceManager.ResetWidthAndHeight(this.game.Window);
|
||||||
this.game.GraphicsDeviceManager.IsFullScreen = true;
|
this.game.GraphicsDeviceManager.IsFullScreen = true;
|
||||||
this.game.OnLoadContent += game => {
|
this.game.OnLoadContent += game => {
|
||||||
|
@ -71,6 +75,13 @@ namespace Android {
|
||||||
this.game.Run();
|
this.game.Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnActivityResult(int requestCode, Result result, Intent data) {
|
||||||
|
base.OnActivityResult(requestCode, result, data);
|
||||||
|
// Connect again after logging in to Google Play game services, but only if we haven't tried yet
|
||||||
|
if (requestCode == AndroidPlatform.GooglePlayLoginRequest && (int) result != GamesActivityResultCodes.ResultSignInFailed)
|
||||||
|
this.platform.GoogleApi.Connect();
|
||||||
|
}
|
||||||
|
|
||||||
public override void OnWindowFocusChanged(bool hasFocus) {
|
public override void OnWindowFocusChanged(bool hasFocus) {
|
||||||
base.OnWindowFocusChanged(hasFocus);
|
base.OnWindowFocusChanged(hasFocus);
|
||||||
// hide the status bar
|
// hide the status bar
|
||||||
|
|
|
@ -82,6 +82,7 @@
|
||||||
<PackageReference Include="GameAnalytics.Xamarin.SDK" Version="4.1.1" />
|
<PackageReference Include="GameAnalytics.Xamarin.SDK" Version="4.1.1" />
|
||||||
<PackageReference Include="MonoGame.Content.Builder" Version="3.7.0.9" />
|
<PackageReference Include="MonoGame.Content.Builder" Version="3.7.0.9" />
|
||||||
<PackageReference Include="MonoGame.Framework.Android" Version="3.7.1.189" />
|
<PackageReference Include="MonoGame.Framework.Android" Version="3.7.1.189" />
|
||||||
|
<PackageReference Include="Xamarin.GooglePlayServices.Games" Version="29.0.0.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\TouchyTickets\TouchyTickets.csproj">
|
<ProjectReference Include="..\TouchyTickets\TouchyTickets.csproj">
|
||||||
|
|
|
@ -1,28 +1,42 @@
|
||||||
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Android.App;
|
using Android.App;
|
||||||
using Android.Content;
|
using Android.Content;
|
||||||
using Android.Gms.Ads;
|
using Android.Gms.Ads;
|
||||||
using Android.Net;
|
using Android.Gms.Common;
|
||||||
|
using Android.Gms.Common.Apis;
|
||||||
|
using Android.Gms.Extensions;
|
||||||
|
using Android.Gms.Games;
|
||||||
using Android.Runtime;
|
using Android.Runtime;
|
||||||
using Android.Views;
|
using Android.Views;
|
||||||
using Android.Widget;
|
using Android.Widget;
|
||||||
|
using Coroutine;
|
||||||
using GameAnalyticsSDK;
|
using GameAnalyticsSDK;
|
||||||
using GameAnalyticsSDK.Utilities;
|
using GameAnalyticsSDK.Utilities;
|
||||||
using TouchyTickets;
|
using TouchyTickets;
|
||||||
|
using Uri = Android.Net.Uri;
|
||||||
|
|
||||||
namespace Android {
|
namespace Android {
|
||||||
public class AndroidPlatform : Platform {
|
public class AndroidPlatform : Platform {
|
||||||
|
|
||||||
|
public const int GooglePlayLoginRequest = 9001;
|
||||||
private readonly Activity activity;
|
private readonly Activity activity;
|
||||||
private readonly LinearLayout adLayout;
|
private readonly LinearLayout adLayout;
|
||||||
|
public GoogleApiClient GoogleApi { get; private set; }
|
||||||
|
|
||||||
public AndroidPlatform(Activity activity, LinearLayout adLayout) {
|
public AndroidPlatform(Activity activity, LinearLayout adLayout) {
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
this.adLayout = adLayout;
|
this.adLayout = adLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetupAds() {
|
public override void SetupOnlineInteractions(Dictionary<string, object> analyticsJson) {
|
||||||
|
// Analytics
|
||||||
|
GameAnalytics.SetAutoDetectAppVersion(true);
|
||||||
|
GameAnalytics.Initialize(this.activity, GA_MiniJSON.JsonEncode(new Hashtable(analyticsJson)));
|
||||||
|
AndroidEnvironment.UnhandledExceptionRaiser += (o, args) => GameAnalytics.NewErrorEvent(GAErrorSeverity.Critical, args.Exception.ToString());
|
||||||
|
|
||||||
|
// Ads
|
||||||
var ad = new AdView(this.activity) {
|
var ad = new AdView(this.activity) {
|
||||||
AdUnitId = "ca-app-pub-5754829579653773/7841535920",
|
AdUnitId = "ca-app-pub-5754829579653773/7841535920",
|
||||||
AdSize = AdSize.SmartBanner
|
AdSize = AdSize.SmartBanner
|
||||||
|
@ -31,12 +45,20 @@ namespace Android {
|
||||||
.AddTestDevice("14B965C6457E17D2808061ADF7E34923")
|
.AddTestDevice("14B965C6457E17D2808061ADF7E34923")
|
||||||
.Build());
|
.Build());
|
||||||
this.adLayout.AddView(ad);
|
this.adLayout.AddView(ad);
|
||||||
}
|
|
||||||
|
|
||||||
public override void SetupAnalytics(Dictionary<string, object> json) {
|
// Google Play game services
|
||||||
GameAnalytics.SetAutoDetectAppVersion(true);
|
this.GoogleApi = new GoogleApiClient.Builder(this.activity)
|
||||||
GameAnalytics.Initialize(this.activity, GA_MiniJSON.JsonEncode(new Hashtable(json)));
|
.AddApi(GamesClass.API)
|
||||||
AndroidEnvironment.UnhandledExceptionRaiser += (o, args) => GameAnalytics.NewErrorEvent(GAErrorSeverity.Critical, args.Exception.ToString());
|
.AddScope(GamesClass.ScopeGames)
|
||||||
|
.AddOnConnectionFailedListener(res => {
|
||||||
|
if (res.HasResolution) {
|
||||||
|
res.StartResolutionForResult(this.activity, GooglePlayLoginRequest);
|
||||||
|
} else {
|
||||||
|
throw new GoogleApiClientConnectionException(res);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.Build();
|
||||||
|
this.GoogleApi.Connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void AddResourceEvent(bool sink, string currency, float amount, string itemType, string itemId) {
|
public override void AddResourceEvent(bool sink, string currency, float amount, string itemType, string itemId) {
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="de.ellpeck.touchytickets" android:installLocation="auto"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="de.ellpeck.touchytickets" android:installLocation="auto"
|
||||||
android:versionCode="110" android:versionName="1.1.0">
|
android:versionCode="110" android:versionName="1.1.0">
|
||||||
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28"/>
|
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28"/>
|
||||||
<application android:label="Touchy Tickets" android:resizeableActivity="true"/>
|
<application android:label="Touchy Tickets" android:resizeableActivity="true">
|
||||||
|
<meta-data android:name="com.google.android.gms.games.APP_ID" android:value="\u003169609944700" />
|
||||||
|
</application>
|
||||||
<permission android:name="ACCESS_NETWORK_STATE"/>
|
<permission android:name="ACCESS_NETWORK_STATE"/>
|
||||||
<permission android:name="INTERNET"/>
|
<permission android:name="INTERNET"/>
|
||||||
</manifest>
|
</manifest>
|
|
@ -112,3 +112,9 @@
|
||||||
/processor:FontDescriptionProcessor
|
/processor:FontDescriptionProcessor
|
||||||
/build:Fonts/Monospaced.spritefont
|
/build:Fonts/Monospaced.spritefont
|
||||||
|
|
||||||
|
#begin Localization/Localization.fr.json
|
||||||
|
/copy:Localization/Localization.fr.json
|
||||||
|
|
||||||
|
#begin Localization/News.fr.json
|
||||||
|
/copy:Localization/News.fr.json
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 8428712d0a64e36334908cd25bec7dddd9abd66d
|
Subproject commit 99a5dcc832a1f789a0ccf4fe660568360650596d
|
|
@ -42,17 +42,16 @@ namespace TouchyTickets {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadGame() {
|
private void LoadGame() {
|
||||||
// set up analytics
|
// set up online stuff
|
||||||
var settings = new Dictionary<string, object>();
|
var analytics = new Dictionary<string, object>();
|
||||||
settings["InfoLog"] = true;
|
analytics["InfoLog"] = true;
|
||||||
settings["VerboseLog"] = true;
|
analytics["VerboseLog"] = true;
|
||||||
settings["ResourceCurrencies"] = new[] {"Tickets", "Stars"};
|
analytics["ResourceCurrencies"] = new[] {"Tickets", "Stars"};
|
||||||
settings["ResourceItemTypes"] = new[] {"Attraction", "Restart", "Upgrade", "Modifier"};
|
analytics["ResourceItemTypes"] = new[] {"Attraction", "Restart", "Upgrade", "Modifier"};
|
||||||
// ios comes first, then android. For now they're the same
|
// ios comes first, then android. For now they're the same
|
||||||
settings["GameKey"] = new[] {"cc18de06eebbc5d5e987c384fcd28000", "cc18de06eebbc5d5e987c384fcd28000"};
|
analytics["GameKey"] = new[] {"cc18de06eebbc5d5e987c384fcd28000", "cc18de06eebbc5d5e987c384fcd28000"};
|
||||||
settings["SecretKey"] = new[] {"82ca1a930ee38e2383ffb02db7631e16033b511d", "82ca1a930ee38e2383ffb02db7631e16033b511d"};
|
analytics["SecretKey"] = new[] {"82ca1a930ee38e2383ffb02db7631e16033b511d", "82ca1a930ee38e2383ffb02db7631e16033b511d"};
|
||||||
this.Platform.SetupAnalytics(settings);
|
this.Platform.SetupOnlineInteractions(analytics);
|
||||||
this.Platform.SetupAds();
|
|
||||||
|
|
||||||
this.Tutorial = new Tutorial();
|
this.Tutorial = new Tutorial();
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,7 @@ using System.Collections.Generic;
|
||||||
namespace TouchyTickets {
|
namespace TouchyTickets {
|
||||||
public abstract class Platform {
|
public abstract class Platform {
|
||||||
|
|
||||||
public abstract void SetupAds();
|
public abstract void SetupOnlineInteractions(Dictionary<string, object> analyticsJson);
|
||||||
|
|
||||||
public abstract void SetupAnalytics(Dictionary<string, object> json);
|
|
||||||
|
|
||||||
public abstract void AddResourceEvent(bool sink, string currency, float amount, string itemType, string itemId);
|
public abstract void AddResourceEvent(bool sink, string currency, float amount, string itemType, string itemId);
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,7 @@ using TouchyTickets;
|
||||||
namespace iOS {
|
namespace iOS {
|
||||||
public class IosPlatform : Platform {
|
public class IosPlatform : Platform {
|
||||||
|
|
||||||
public override void SetupAds() {
|
public override void SetupOnlineInteractions(Dictionary<string, object> analyticsJson) {
|
||||||
throw new System.NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void SetupAnalytics(Dictionary<string, object> json) {
|
|
||||||
throw new System.NotImplementedException();
|
throw new System.NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue