diff --git a/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/ISocialPlatform/PlayGamesUserProfile.cs b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/ISocialPlatform/PlayGamesUserProfile.cs index dc4b415fe..0bfe18291 100644 --- a/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/ISocialPlatform/PlayGamesUserProfile.cs +++ b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/ISocialPlatform/PlayGamesUserProfile.cs @@ -19,9 +19,11 @@ namespace GooglePlayGames { using System; - using System.Threading.Tasks; using UnityEngine; + + using GooglePlayGames.OurUtils; + #if UNITY_2017_2_OR_NEWER using UnityEngine.Networking; #endif @@ -107,48 +109,37 @@ public Texture2D image mImage = new Texture2D(96,96); - var scheduler = TaskScheduler.FromCurrentSynchronizationContext(); - using(var currentActivity = Android.AndroidHelperFragment.GetActivity()) { currentActivity.Call("runOnUiThread", new AndroidJavaRunnable(() => { - var listener = new OnLoadImageListener(); - using(var currentActivity = Android.AndroidHelperFragment.GetActivity()) using(var ImageManager = new AndroidJavaClass("com.google.android.gms.common.images.ImageManager")) using(var imageManager = ImageManager.CallStatic("create",currentActivity)) using(var Uri = new AndroidJavaClass("android.net.Uri")) using(var uri = Uri.CallStatic("parse",AvatarURL)) { - imageManager.Call("loadImage",listener,uri); + imageManager.Call("loadImage",new OnLoadImageListener((result) => { + PlayGamesHelperObject.RunOnGameThread(() => { + var (uri,drawable,isRequestedDrawable) = result; + + using(var CompressFormat = new AndroidJavaClass("android.graphics.Bitmap$CompressFormat")) + using(var format = CompressFormat.GetStatic("PNG")) + using(var outputStream = new AndroidJavaObject("java.io.ByteArrayOutputStream")) + using(var bitmap = drawable.Call("getBitmap")) + { + mImage.Reinitialize(bitmap.Call("getWidth"),bitmap.Call("getHeight")); + + bitmap.Call("compress",format,100,outputStream); + var data = outputStream.Call("toByteArray"); + + mImage.LoadImage(System.Runtime.InteropServices.MemoryMarshal.Cast(data).ToArray()); + } + + drawable?.Dispose(); + uri?.Dispose(); + }); + }),uri); } - - listener.AsTask.ContinueWith((task) => { - Debug.LogFormat("task : {0}",task); - if(!task.IsCompletedSuccessfully) - { - Debug.LogException(task.Exception); - return; - } - - var (uri,drawable,_) = task.Result; - - using(var CompressFormat = new AndroidJavaClass("android.graphics.Bitmap$CompressFormat")) - using(var format = CompressFormat.GetStatic("PNG")) - using(var outputStream = new AndroidJavaObject("java.io.ByteArrayOutputStream")) - using(var bitmap = drawable.Call("getBitmap")) - { - mImage.Reinitialize(bitmap.Call("getWidth"),bitmap.Call("getHeight")); - - bitmap.Call("compress",format,100,outputStream); - var data = outputStream.Call("toByteArray"); - - mImage.LoadImage(System.Runtime.InteropServices.MemoryMarshal.Cast(data).ToArray()); - } - - drawable?.Dispose(); - uri?.Dispose(); - },scheduler); })); } } @@ -166,16 +157,15 @@ public string AvatarURL class OnLoadImageListener : AndroidJavaProxy { - public Task<(AndroidJavaObject uri,AndroidJavaObject drawable,bool isRequestedDrawable)> AsTask => source.Task; - TaskCompletionSource<(AndroidJavaObject uri,AndroidJavaObject drawable,bool isRequestedDrawable)> source = new TaskCompletionSource<(AndroidJavaObject uri, AndroidJavaObject drawable, bool isRequestedDrawable)>(); - - public OnLoadImageListener() : base("com.google.android.gms.common.images.ImageManager$OnImageLoadedListener") { } + private Action<(AndroidJavaObject uri, AndroidJavaObject drawable, bool isRequestedDrawable)> mAction; + public OnLoadImageListener(Action<(AndroidJavaObject uri, AndroidJavaObject drawable, bool isRequestedDrawable)> action) : base("com.google.android.gms.common.images.ImageManager$OnImageLoadedListener") + { + mAction = action; + } public void onImageLoaded(AndroidJavaObject uri, AndroidJavaObject drawable, bool isRequestedDrawable) { - Debug.Log((uri,drawable,isRequestedDrawable)); - Debug.Log(source); - source.TrySetResult((uri,drawable,isRequestedDrawable)); + mAction((uri,drawable,isRequestedDrawable)); } } diff --git a/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/Platforms/Android/AndroidClient.cs b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/Platforms/Android/AndroidClient.cs index 6276b31fc..5d968ba03 100644 --- a/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/Platforms/Android/AndroidClient.cs +++ b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/Platforms/Android/AndroidClient.cs @@ -84,7 +84,7 @@ private void Authenticate(bool isAutoSignIn, Action callback) { // If the user is already authenticated, just fire the callback, we don't need // any additional work. - if (mAuthState == AuthState.Authenticated) + if (isAutoSignIn && mAuthState == AuthState.Authenticated) { OurUtils.Logger.d("Already authenticated."); InvokeCallbackOnGameThread(callback, SignInStatus.Success); @@ -98,82 +98,44 @@ private void Authenticate(bool isAutoSignIn, Action callback) using (var client = getGamesSignInClient()) using (var task = client.Call(methodName)) { - AndroidTaskUtils.AddOnSuccessListener(task, authenticationResult => - { + task.AddOnSuccessListener(authenticationResult => { bool isAuthenticated = authenticationResult.Call("isAuthenticated"); - SignInOnResult(isAuthenticated, callback); - }); - - AndroidTaskUtils.AddOnFailureListener(task, exception => - { - OurUtils.Logger.e("Authentication failed - " + exception.Call("toString")); - callback(SignInStatus.InternalError); - }); - } - } - - private void SignInOnResult(bool isAuthenticated, Action callback) - { - if (isAuthenticated) - { - using (var signInTasks = new AndroidJavaObject("java.util.ArrayList")) - { - AndroidJavaObject taskGetPlayer = - getPlayersClient().Call("getCurrentPlayer"); - signInTasks.Call("add", taskGetPlayer); - - using (var tasks = new AndroidJavaClass(TasksClassName)) - using (var allTask = tasks.CallStatic("whenAll", signInTasks)) + if (!isAuthenticated) { - AndroidTaskUtils.AddOnCompleteListener( - allTask, - completeTask => - { - if (completeTask.Call("isSuccessful")) - { - using (var resultObject = taskGetPlayer.Call("getResult")) - { - mUser = AndroidJavaConverter.ToPlayer(resultObject); - } + lock (AuthStateLock) + { + OurUtils.Logger.e("Not authenticated"); + callback(SignInStatus.Canceled); + return; + } + } - lock (GameServicesLock) - { - mSavedGameClient = new AndroidSavedGameClient(this); - mEventsClient = new AndroidEventsClient(); - } + using (var client = getPlayersClient()) + using (client.Call("getCurrentPlayer").AddOnSuccessListener((AndroidJavaObject resultObject) => { + mUser = AndroidJavaConverter.ToPlayer(resultObject); - mAuthState = AuthState.Authenticated; - InvokeCallbackOnGameThread(callback, SignInStatus.Success); - OurUtils.Logger.d("Authentication succeeded"); - LoadAchievements(ignore => { }); - } - else - { - if (completeTask.Call("isCanceled")) - { - InvokeCallbackOnGameThread(callback, SignInStatus.Canceled); - return; - } + lock (GameServicesLock) + { + mSavedGameClient = new AndroidSavedGameClient(this); + mEventsClient = new AndroidEventsClient(); + } - using (var exception = completeTask.Call("getException")) - { - OurUtils.Logger.e( - "Authentication failed - " + exception.Call("toString")); - InvokeCallbackOnGameThread(callback, SignInStatus.InternalError); - } - } - } - ); - } - } - } - else - { - lock (AuthStateLock) - { - OurUtils.Logger.e("Returning an error code."); - InvokeCallbackOnGameThread(callback, SignInStatus.Canceled); - } + mAuthState = AuthState.Authenticated; + InvokeCallbackOnGameThread(callback, SignInStatus.Success); + OurUtils.Logger.d("Authentication succeeded"); + LoadAchievements(ignore => { }); + }).AddOnFailureListener((exception) => { + OurUtils.Logger.e("GetCurrentPlayer failed - " + exception.Call("toString")); + callback(SignInStatus.InternalError); + }).AddOnCanceledListener(() => { + callback(SignInStatus.Canceled); + })); + }).AddOnFailureListener(exception => { + OurUtils.Logger.e("Authentication failed - " + exception.Call("toString")); + callback(SignInStatus.InternalError); + }).AddOnCanceledListener(() => { + callback(SignInStatus.Canceled); + }); } } @@ -211,15 +173,8 @@ public void RequestServerSideAccess(bool forceRefreshToken, Action callb using (var client = getGamesSignInClient()) using (var task = client.Call("requestServerSideAccess", WebClientId, forceRefreshToken)) { - AndroidTaskUtils.AddOnSuccessListener( - task, - authCode => callback(authCode) - ); - - AndroidTaskUtils.AddOnFailureListener(task, exception => - { - OurUtils.Logger.e("Requesting server side access task failed - " + - exception.Call("toString")); + task.AddOnSuccessListener(authCode => callback(authCode)).AddOnFailureListener((exception) => { + OurUtils.Logger.e("Requesting server side access task failed - " + exception.Call("toString")); callback(null); }); } @@ -256,8 +211,7 @@ private static void InvokeCallbackOnGameThread(Action callback, T data) } - private static Action AsOnGameThreadCallback( - Action toInvokeOnGameThread) + private static Action AsOnGameThreadCallback(Action toInvokeOnGameThread) { return (result1, result2) => { @@ -337,27 +291,22 @@ private void LoadFriendsPaginated(int pageSize, bool isLoadMore, bool forceReloa using (var playersClient = getPlayersClient()) using (var task = isLoadMore ? playersClient.Call("loadMoreFriends", pageSize) - : playersClient.Call("loadFriends", pageSize, - forceReload)) + : playersClient.Call("loadFriends", pageSize, forceReload)) { - AndroidTaskUtils.AddOnSuccessListener( - task, annotatedData => + task.AddOnSuccessListener(annotatedData => { + using (var playersBuffer = annotatedData.Call("get")) { - using (var playersBuffer = annotatedData.Call("get")) - { - AndroidJavaObject metadata = playersBuffer.Call("getMetadata"); - var areMoreFriendsToLoad = metadata != null && - metadata.Call("getString", - "next_page_token") != null; - mFriends = AndroidJavaConverter.playersBufferToArray(playersBuffer); - mLastLoadFriendsStatus = areMoreFriendsToLoad - ? LoadFriendsStatus.LoadMore - : LoadFriendsStatus.Completed; - InvokeCallbackOnGameThread(callback, mLastLoadFriendsStatus); - } - }); - AndroidTaskUtils.AddOnFailureListener(task, exception => - { + AndroidJavaObject metadata = playersBuffer.Call("getMetadata"); + var areMoreFriendsToLoad = metadata != null && + metadata.Call("getString", + "next_page_token") != null; + mFriends = AndroidJavaConverter.playersBufferToArray(playersBuffer); + mLastLoadFriendsStatus = areMoreFriendsToLoad + ? LoadFriendsStatus.LoadMore + : LoadFriendsStatus.Completed; + InvokeCallbackOnGameThread(callback, mLastLoadFriendsStatus); + } + }).AddOnFailureListener(exception => { AndroidHelperFragment.IsResolutionRequired(exception, resolutionRequired => { if (resolutionRequired) @@ -394,8 +343,7 @@ private void LoadFriendsPaginated(int pageSize, bool isLoadMore, bool forceReloa } private static bool IsApiException(AndroidJavaObject exception) { - var exceptionClassName = exception.Call("getClass") - .Call("getName"); + var exceptionClassName = exception.Call("getClass").Call("getName"); return exceptionClassName == "com.google.android.gms.common.api.ApiException"; } @@ -414,10 +362,9 @@ public void AskForLoadFriendsResolution(Action callback) using (var playersClient = getPlayersClient()) using (var task = playersClient.Call("loadFriends", /* pageSize= */ 1, /* forceReload= */ false)) { - AndroidTaskUtils.AddOnSuccessListener( - task, annotatedData => { InvokeCallbackOnGameThread(callback, UIStatus.Valid); }); - AndroidTaskUtils.AddOnFailureListener(task, exception => - { + task.AddOnSuccessListener(annotatedData => { + InvokeCallbackOnGameThread(callback, UIStatus.Valid); + }).AddOnFailureListener(exception => { AndroidHelperFragment.IsResolutionRequired(exception, resolutionRequired => { if (resolutionRequired) @@ -467,8 +414,7 @@ public void GetFriendsListVisibility(bool forceReload, Action("getCurrentPlayer", forceReload)) { - AndroidTaskUtils.AddOnSuccessListener(task, annotatedData => - { + task.AddOnSuccessListener(annotatedData => { AndroidJavaObject currentPlayerInfo = annotatedData.Call("get").Call( "getCurrentPlayerInfo"); @@ -476,11 +422,8 @@ public void GetFriendsListVisibility(bool forceReload, Action("getFriendsListVisibilityStatus"); InvokeCallbackOnGameThread(callback, AndroidJavaConverter.ToFriendsListVisibilityStatus(playerListVisibility)); - }); - AndroidTaskUtils.AddOnFailureListener(task, exception => - { + }).AddOnFailureListener(exception => { InvokeCallbackOnGameThread(callback, FriendsListVisibilityStatus.NetworkError); - return; }); } } @@ -525,41 +468,35 @@ public void GetPlayerStats(Action callback) using (var playerStatsClient = getPlayerStatsClient()) using (var task = playerStatsClient.Call("loadPlayerStats", /* forceReload= */ false)) { - AndroidTaskUtils.AddOnSuccessListener( - task, - annotatedData => + task.AddOnSuccessListener(annotatedData => { + using (var playerStatsJava = annotatedData.Call("get")) { - using (var playerStatsJava = annotatedData.Call("get")) - { - int numberOfPurchases = playerStatsJava.Call("getNumberOfPurchases"); - float avgSessionLength = playerStatsJava.Call("getAverageSessionLength"); - int daysSinceLastPlayed = playerStatsJava.Call("getDaysSinceLastPlayed"); - int numberOfSessions = playerStatsJava.Call("getNumberOfSessions"); - float sessionPercentile = playerStatsJava.Call("getSessionPercentile"); - float spendPercentile = playerStatsJava.Call("getSpendPercentile"); - float spendProbability = playerStatsJava.Call("getSpendProbability"); - float churnProbability = playerStatsJava.Call("getChurnProbability"); - float highSpenderProbability = playerStatsJava.Call("getHighSpenderProbability"); - float totalSpendNext28Days = playerStatsJava.Call("getTotalSpendNext28Days"); - - PlayerStats result = new PlayerStats( - numberOfPurchases, - avgSessionLength, - daysSinceLastPlayed, - numberOfSessions, - sessionPercentile, - spendPercentile, - spendProbability, - churnProbability, - highSpenderProbability, - totalSpendNext28Days); - - InvokeCallbackOnGameThread(callback, CommonStatusCodes.Success, result); - } - }); - - AndroidTaskUtils.AddOnFailureListener(task, exception => - { + int numberOfPurchases = playerStatsJava.Call("getNumberOfPurchases"); + float avgSessionLength = playerStatsJava.Call("getAverageSessionLength"); + int daysSinceLastPlayed = playerStatsJava.Call("getDaysSinceLastPlayed"); + int numberOfSessions = playerStatsJava.Call("getNumberOfSessions"); + float sessionPercentile = playerStatsJava.Call("getSessionPercentile"); + float spendPercentile = playerStatsJava.Call("getSpendPercentile"); + float spendProbability = playerStatsJava.Call("getSpendProbability"); + float churnProbability = playerStatsJava.Call("getChurnProbability"); + float highSpenderProbability = playerStatsJava.Call("getHighSpenderProbability"); + float totalSpendNext28Days = playerStatsJava.Call("getTotalSpendNext28Days"); + + PlayerStats result = new PlayerStats( + numberOfPurchases, + avgSessionLength, + daysSinceLastPlayed, + numberOfSessions, + sessionPercentile, + spendPercentile, + spendProbability, + churnProbability, + highSpenderProbability, + totalSpendNext28Days); + + InvokeCallbackOnGameThread(callback, CommonStatusCodes.Success, result); + } + }).AddOnFailureListener(exception => { OurUtils.Logger.e("GetPlayerStats failed: " + exception.Call("toString")); var statusCode = IsAuthenticated() ? CommonStatusCodes.InternalError @@ -587,35 +524,29 @@ public void LoadUsers(string[] userIds, Action callback) { using (var task = playersClient.Call("loadPlayer", userIds[i])) { - AndroidTaskUtils.AddOnSuccessListener( - task, - annotatedData => + task.AddOnSuccessListener(annotatedData => { + using (var player = annotatedData.Call("get")) { - using (var player = annotatedData.Call("get")) + string playerId = player.Call("getPlayerId"); + for (int j = 0; j < count; ++j) { - string playerId = player.Call("getPlayerId"); - for (int j = 0; j < count; ++j) + if (playerId == userIds[j]) { - if (playerId == userIds[j]) - { - users[j] = AndroidJavaConverter.ToPlayer(player); - break; - } + users[j] = AndroidJavaConverter.ToPlayer(player); + break; } + } - lock (countLock) + lock (countLock) + { + ++resultCount; + if (resultCount == count) { - ++resultCount; - if (resultCount == count) - { - InvokeCallbackOnGameThread(callback, users); - } + InvokeCallbackOnGameThread(callback, users); } } - }); - - AndroidTaskUtils.AddOnFailureListener(task, exception => - { + } + }).AddOnFailureListener(exception => { OurUtils.Logger.e("LoadUsers failed for index " + i + " with: " + exception.Call("toString")); lock (countLock) @@ -637,52 +568,46 @@ public void LoadAchievements(Action callback) using (var achievementsClient = getAchievementsClient()) using (var task = achievementsClient.Call("load", /* forceReload= */ false)) { - AndroidTaskUtils.AddOnSuccessListener( - task, - annotatedData => + task.AddOnSuccessListener(annotatedData => { + using (var achievementBuffer = annotatedData.Call("get")) { - using (var achievementBuffer = annotatedData.Call("get")) + int count = achievementBuffer.Call("getCount"); + Achievement[] result = new Achievement[count]; + for (int i = 0; i < count; ++i) { - int count = achievementBuffer.Call("getCount"); - Achievement[] result = new Achievement[count]; - for (int i = 0; i < count; ++i) + Achievement achievement = new Achievement(); + using (var javaAchievement = achievementBuffer.Call("get", i)) { - Achievement achievement = new Achievement(); - using (var javaAchievement = achievementBuffer.Call("get", i)) + achievement.Id = javaAchievement.Call("getAchievementId"); + achievement.Description = javaAchievement.Call("getDescription"); + achievement.Name = javaAchievement.Call("getName"); + achievement.Points = javaAchievement.Call("getXpValue"); + + long timestamp = javaAchievement.Call("getLastUpdatedTimestamp"); + achievement.LastModifiedTime = AndroidJavaConverter.ToDateTime(timestamp); + + achievement.RevealedImageUrl = javaAchievement.Call("getRevealedImageUrl"); + achievement.UnlockedImageUrl = javaAchievement.Call("getUnlockedImageUrl"); + achievement.IsIncremental = + javaAchievement.Call("getType") == 1 /* TYPE_INCREMENTAL */; + if (achievement.IsIncremental) { - achievement.Id = javaAchievement.Call("getAchievementId"); - achievement.Description = javaAchievement.Call("getDescription"); - achievement.Name = javaAchievement.Call("getName"); - achievement.Points = javaAchievement.Call("getXpValue"); - - long timestamp = javaAchievement.Call("getLastUpdatedTimestamp"); - achievement.LastModifiedTime = AndroidJavaConverter.ToDateTime(timestamp); - - achievement.RevealedImageUrl = javaAchievement.Call("getRevealedImageUrl"); - achievement.UnlockedImageUrl = javaAchievement.Call("getUnlockedImageUrl"); - achievement.IsIncremental = - javaAchievement.Call("getType") == 1 /* TYPE_INCREMENTAL */; - if (achievement.IsIncremental) - { - achievement.CurrentSteps = javaAchievement.Call("getCurrentSteps"); - achievement.TotalSteps = javaAchievement.Call("getTotalSteps"); - } - - int state = javaAchievement.Call("getState"); - achievement.IsUnlocked = state == 0 /* STATE_UNLOCKED */; - achievement.IsRevealed = state == 1 /* STATE_REVEALED */; + achievement.CurrentSteps = javaAchievement.Call("getCurrentSteps"); + achievement.TotalSteps = javaAchievement.Call("getTotalSteps"); } - result[i] = achievement; + int state = javaAchievement.Call("getState"); + achievement.IsUnlocked = state == 0 /* STATE_UNLOCKED */; + achievement.IsRevealed = state == 1 /* STATE_REVEALED */; } - achievementBuffer.Call("release"); - InvokeCallbackOnGameThread(callback, result); + result[i] = achievement; } - }); - AndroidTaskUtils.AddOnFailureListener(task, exception => - { + achievementBuffer.Call("release"); + InvokeCallbackOnGameThread(callback, result); + } + }).AddOnFailureListener(exception => { OurUtils.Logger.e("LoadAchievements failed: " + exception.Call("toString")); InvokeCallbackOnGameThread(callback, new Achievement[0]); }); @@ -790,58 +715,43 @@ public void LoadScores(string leaderboardId, LeaderboardStart start, Action callback) { using (var client = getLeaderboardsClient()) - { - string loadScoresMethod = - start == LeaderboardStart.TopScores ? "loadTopScores" : "loadPlayerCenteredScores"; - using (var task = client.Call( - loadScoresMethod, - leaderboardId, - AndroidJavaConverter.ToLeaderboardVariantTimeSpan(timeSpan), - AndroidJavaConverter.ToLeaderboardVariantCollection(collection), - rowCount)) - { - AndroidTaskUtils.AddOnSuccessListener( - task, - annotatedData => - { - using (var leaderboardScores = annotatedData.Call("get")) - { - InvokeCallbackOnGameThread(callback, CreateLeaderboardScoreData( - leaderboardId, - collection, - timeSpan, - annotatedData.Call("isStale") - ? ResponseStatus.SuccessWithStale - : ResponseStatus.Success, - leaderboardScores)); - leaderboardScores.Call("release"); - } - }); - - AndroidTaskUtils.AddOnFailureListener(task, exception => + using (var task = client.Call( + start == LeaderboardStart.TopScores ? "loadTopScores" : "loadPlayerCenteredScores", + leaderboardId, + AndroidJavaConverter.ToLeaderboardVariantTimeSpan(timeSpan), + AndroidJavaConverter.ToLeaderboardVariantCollection(collection), + rowCount)) + { + task.AddOnSuccessListener(annotatedData => { + using (var leaderboardScores = annotatedData.Call("get")) { - AndroidHelperFragment.IsResolutionRequired( - exception, resolutionRequired => - { - if (resolutionRequired) - { - mFriendsResolutionException = exception.Call( - "getResolution"); - InvokeCallbackOnGameThread( - callback, new LeaderboardScoreData(leaderboardId, - ResponseStatus.ResolutionRequired)); - } - else - { - mFriendsResolutionException = null; - } - }); - OurUtils.Logger.e("LoadScores failed: " + exception.Call("toString")); - InvokeCallbackOnGameThread( - callback, new LeaderboardScoreData(leaderboardId, - ResponseStatus.InternalError)); + InvokeCallbackOnGameThread(callback, CreateLeaderboardScoreData( + leaderboardId, + collection, + timeSpan, + annotatedData.Call("isStale") + ? ResponseStatus.SuccessWithStale + : ResponseStatus.Success, + leaderboardScores)); + leaderboardScores.Call("release"); + } + }).AddOnFailureListener(exception => { + AndroidHelperFragment.IsResolutionRequired(exception, resolutionRequired => { + if (resolutionRequired) + { + mFriendsResolutionException = exception.Call("getResolution"); + InvokeCallbackOnGameThread( + callback, new LeaderboardScoreData(leaderboardId,ResponseStatus.ResolutionRequired)); + } + else + { + mFriendsResolutionException = null; + } }); - } + + OurUtils.Logger.e("LoadScores failed: " + exception.Call("toString")); + InvokeCallbackOnGameThread(callback, new LeaderboardScoreData(leaderboardId,ResponseStatus.InternalError)); + }); } } @@ -851,28 +761,21 @@ public void LoadMoreScores(ScorePageToken token, int rowCount, Action("loadMoreScores", token.InternalObject, rowCount, AndroidJavaConverter.ToPageDirection(token.Direction))) { - AndroidTaskUtils.AddOnSuccessListener( - task, - annotatedData => - { - using (var leaderboardScores = annotatedData.Call("get")) - { - InvokeCallbackOnGameThread(callback, CreateLeaderboardScoreData( - token.LeaderboardId, - token.Collection, - token.TimeSpan, - annotatedData.Call("isStale") - ? ResponseStatus.SuccessWithStale - : ResponseStatus.Success, - leaderboardScores)); - leaderboardScores.Call("release"); - } - }); - - AndroidTaskUtils.AddOnFailureListener(task, exception => - { - AndroidHelperFragment.IsResolutionRequired(exception, resolutionRequired => + task.AddOnSuccessListener(annotatedData => { + using (var leaderboardScores = annotatedData.Call("get")) { + InvokeCallbackOnGameThread(callback, CreateLeaderboardScoreData( + token.LeaderboardId, + token.Collection, + token.TimeSpan, + annotatedData.Call("isStale") + ? ResponseStatus.SuccessWithStale + : ResponseStatus.Success, + leaderboardScores)); + leaderboardScores.Call("release"); + } + }).AddOnFailureListener(exception => { + AndroidHelperFragment.IsResolutionRequired(exception, resolutionRequired => { if (resolutionRequired) { mFriendsResolutionException = diff --git a/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/Platforms/Android/AndroidTaskUtils.cs b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/Platforms/Android/AndroidTaskUtils.cs index 4740cae82..8313442fd 100644 --- a/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/Platforms/Android/AndroidTaskUtils.cs +++ b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/Platforms/Android/AndroidTaskUtils.cs @@ -6,32 +6,37 @@ namespace GooglePlayGames.Android using UnityEngine; using System; - class AndroidTaskUtils + static class AndroidTaskUtils { - private AndroidTaskUtils() + /** self */ + public static AndroidJavaObject AddOnCanceledListener(this AndroidJavaObject task, Action callback) { + using (task.Call("addOnCanceledListener",new TaskOnCanceledProxy(callback))) ; + return task; } - public static void AddOnSuccessListener(AndroidJavaObject task, Action callback) - { - using (task.Call("addOnSuccessListener", - new TaskOnSuccessProxy(callback, /* disposeResult= */ true))) ; - } + /** self */ + public static AndroidJavaObject AddOnSuccessListener(this AndroidJavaObject task, Action callback) => task.AddOnSuccessListener(true,callback); - public static void AddOnSuccessListener(AndroidJavaObject task, bool disposeResult, Action callback) + /** self */ + public static AndroidJavaObject AddOnSuccessListener(this AndroidJavaObject task, bool disposeResult, Action callback) { - using (task.Call("addOnSuccessListener", - new TaskOnSuccessProxy(callback, disposeResult))) ; + using (task.Call("addOnSuccessListener",new TaskOnSuccessProxy(callback, disposeResult))) ; + return task; } - public static void AddOnFailureListener(AndroidJavaObject task, Action callback) + /** self */ + public static AndroidJavaObject AddOnFailureListener(this AndroidJavaObject task, Action callback) { using (task.Call("addOnFailureListener", new TaskOnFailedProxy(callback))) ; + return task; } - public static void AddOnCompleteListener(AndroidJavaObject task, Action callback) + /** self */ + public static AndroidJavaObject AddOnCompleteListener(this AndroidJavaObject task, Action callback) { using (task.Call("addOnCompleteListener", new TaskOnCompleteProxy(callback))) ; + return task; } private class TaskOnCompleteProxy : AndroidJavaProxy @@ -65,8 +70,7 @@ private class TaskOnSuccessProxy : AndroidJavaProxy private Action mCallback; private bool mDisposeResult; - public TaskOnSuccessProxy(Action callback, bool disposeResult) - : base("com/google/android/gms/tasks/OnSuccessListener") + public TaskOnSuccessProxy(Action callback, bool disposeResult) : base("com/google/android/gms/tasks/OnSuccessListener") { mCallback = callback; mDisposeResult = disposeResult; @@ -92,8 +96,7 @@ private class TaskOnFailedProxy : AndroidJavaProxy { private Action mCallback; - public TaskOnFailedProxy(Action callback) - : base("com/google/android/gms/tasks/OnFailureListener") + public TaskOnFailedProxy(Action callback) : base("com/google/android/gms/tasks/OnFailureListener") { mCallback = callback; } @@ -106,6 +109,21 @@ public void onFailure(AndroidJavaObject exception) } } } + + private class TaskOnCanceledProxy : AndroidJavaProxy + { + private Action mCallback; + + public TaskOnCanceledProxy(Action callback) : base("com/google/android/gms/tasks/OnCanceledListener") + { + mCallback = callback; + } + + public void onCanceled() + { + mCallback(); + } + } } } #endif diff --git a/Samples/SmokeTest/Scenes/TestScene.unity b/Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scenes/TestScene.unity similarity index 100% rename from Samples/SmokeTest/Scenes/TestScene.unity rename to Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scenes/TestScene.unity diff --git a/Samples/SmokeTest/Scenes/TestScene.unity.meta b/Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scenes/TestScene.unity.meta similarity index 100% rename from Samples/SmokeTest/Scenes/TestScene.unity.meta rename to Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scenes/TestScene.unity.meta diff --git a/Samples/SmokeTest/Scripts/AchievementGUI.cs b/Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/AchievementGUI.cs similarity index 100% rename from Samples/SmokeTest/Scripts/AchievementGUI.cs rename to Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/AchievementGUI.cs diff --git a/Samples/SmokeTest/Scripts/AchievementGUI.cs.meta b/Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/AchievementGUI.cs.meta similarity index 100% rename from Samples/SmokeTest/Scripts/AchievementGUI.cs.meta rename to Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/AchievementGUI.cs.meta diff --git a/Samples/SmokeTest/Scripts/AssemblyInfo.cs b/Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/AssemblyInfo.cs similarity index 100% rename from Samples/SmokeTest/Scripts/AssemblyInfo.cs rename to Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/AssemblyInfo.cs diff --git a/Samples/SmokeTest/Scripts/AssemblyInfo.cs.meta b/Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/AssemblyInfo.cs.meta similarity index 100% rename from Samples/SmokeTest/Scripts/AssemblyInfo.cs.meta rename to Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/AssemblyInfo.cs.meta diff --git a/Samples/SmokeTest/Scripts/FriendsGUI.cs b/Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/FriendsGUI.cs similarity index 100% rename from Samples/SmokeTest/Scripts/FriendsGUI.cs rename to Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/FriendsGUI.cs diff --git a/Samples/SmokeTest/Scripts/GPGSIds.cs b/Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/GPGSIds.cs similarity index 100% rename from Samples/SmokeTest/Scripts/GPGSIds.cs rename to Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/GPGSIds.cs diff --git a/Samples/SmokeTest/Scripts/GPGSIds.cs.meta b/Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/GPGSIds.cs.meta similarity index 100% rename from Samples/SmokeTest/Scripts/GPGSIds.cs.meta rename to Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/GPGSIds.cs.meta diff --git a/Samples/SmokeTest/Scripts/LeaderboardGUI.cs b/Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/LeaderboardGUI.cs similarity index 100% rename from Samples/SmokeTest/Scripts/LeaderboardGUI.cs rename to Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/LeaderboardGUI.cs diff --git a/Samples/SmokeTest/Scripts/LeaderboardGUI.cs.meta b/Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/LeaderboardGUI.cs.meta similarity index 100% rename from Samples/SmokeTest/Scripts/LeaderboardGUI.cs.meta rename to Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/LeaderboardGUI.cs.meta diff --git a/Samples/SmokeTest/Scripts/MainGui.cs b/Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/MainGui.cs similarity index 100% rename from Samples/SmokeTest/Scripts/MainGui.cs rename to Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/MainGui.cs diff --git a/Samples/SmokeTest/Scripts/MainGui.cs.meta b/Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/MainGui.cs.meta similarity index 100% rename from Samples/SmokeTest/Scripts/MainGui.cs.meta rename to Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/MainGui.cs.meta diff --git a/Samples/SmokeTest/Scripts/MyGUISkin.guiskin b/Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/MyGUISkin.guiskin similarity index 100% rename from Samples/SmokeTest/Scripts/MyGUISkin.guiskin rename to Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/MyGUISkin.guiskin diff --git a/Samples/SmokeTest/Scripts/MyGUISkin.guiskin.meta b/Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/MyGUISkin.guiskin.meta similarity index 100% rename from Samples/SmokeTest/Scripts/MyGUISkin.guiskin.meta rename to Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/MyGUISkin.guiskin.meta diff --git a/Samples/SmokeTest/Scripts/NearbyGUI.cs b/Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/NearbyGUI.cs similarity index 99% rename from Samples/SmokeTest/Scripts/NearbyGUI.cs rename to Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/NearbyGUI.cs index 8f9f6ca4f..f5abc80ee 100644 --- a/Samples/SmokeTest/Scripts/NearbyGUI.cs +++ b/Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/NearbyGUI.cs @@ -21,7 +21,7 @@ namespace SmokeTest using GooglePlayGames; using GooglePlayGames.BasicApi.Nearby; using UnityEngine; -#if UNITY_ANDROID && UNITY_2019 +#if UNITY_ANDROID && UNITY_2018_3_OR_NEWER using UnityEngine.Android; #endif @@ -72,7 +72,7 @@ internal NearbyGUI(MainGui owner) mMessageLog = new List(); mKnownEndpoints = new HashSet(); -#if UNITY_ANDROID && UNITY_2019 +#if UNITY_ANDROID && UNITY_2018_3_OR_NEWER Permission.RequestUserPermission(Permission.FineLocation); Permission.RequestUserPermission(Permission.CoarseLocation); #endif diff --git a/Samples/SmokeTest/Scripts/NearbyGUI.cs.meta b/Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/NearbyGUI.cs.meta similarity index 100% rename from Samples/SmokeTest/Scripts/NearbyGUI.cs.meta rename to Assets/Public/GooglePlayGames/com.google.play.games/Samples~/SmokeTest/Scripts/NearbyGUI.cs.meta diff --git a/Assets/Public/GooglePlayGames/com.google.play.games/package.json b/Assets/Public/GooglePlayGames/com.google.play.games/package.json index e86273682..917b6cfb2 100644 --- a/Assets/Public/GooglePlayGames/com.google.play.games/package.json +++ b/Assets/Public/GooglePlayGames/com.google.play.games/package.json @@ -9,5 +9,12 @@ }, "dependencies": { "com.google.external-dependency-manager": "1.2.170" - } + }, + "samples": [ + { + "displayName": "SmokeTest", + "description": "Google Play Games Service Samples", + "path": "Samples~/SmokeTest" + } + ] }