Skip to content

Commit

Permalink
Move Sample to unity folder
Browse files Browse the repository at this point in the history
Simplify helper method
  • Loading branch information
Thaina committed Jun 23, 2024
1 parent d5537a9 commit aeb2787
Show file tree
Hide file tree
Showing 20 changed files with 226 additions and 293 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,43 @@ namespace GooglePlayGames.Android
{
using UnityEngine;
using System;
using System.Threading.Tasks;

class AndroidTaskUtils
static class AndroidTaskUtils
{
private AndroidTaskUtils()
/** <returns> self </returns> */
public static AndroidJavaObject AddOnCanceledListener(this AndroidJavaObject task, Action callback)
{
using (task.Call<AndroidJavaObject>("addOnCanceledListener",new TaskOnCanceledProxy(callback))) ;
return task;
}

public static void AddOnSuccessListener<T>(AndroidJavaObject task, Action<T> callback)
/** <returns> self </returns> */
public static AndroidJavaObject AddOnSuccessListener<T>(this AndroidJavaObject task, Action<T> callback)
{
using (task.Call<AndroidJavaObject>("addOnSuccessListener",
new TaskOnSuccessProxy<T>(callback, /* disposeResult= */ true))) ;
using (task.Call<AndroidJavaObject>("addOnSuccessListener",new TaskOnSuccessProxy<T>(callback, /* disposeResult= */ true))) ;
return task;
}

public static void AddOnSuccessListener<T>(AndroidJavaObject task, bool disposeResult, Action<T> callback)
/** <returns> self </returns> */
public static AndroidJavaObject AddOnSuccessListener<T>(this AndroidJavaObject task, bool disposeResult, Action<T> callback)
{
using (task.Call<AndroidJavaObject>("addOnSuccessListener",
new TaskOnSuccessProxy<T>(callback, disposeResult))) ;
using (task.Call<AndroidJavaObject>("addOnSuccessListener",new TaskOnSuccessProxy<T>(callback, disposeResult))) ;
return task;
}

public static void AddOnFailureListener(AndroidJavaObject task, Action<AndroidJavaObject> callback)
/** <returns> self </returns> */
public static AndroidJavaObject AddOnFailureListener(this AndroidJavaObject task, Action<AndroidJavaObject> callback)
{
using (task.Call<AndroidJavaObject>("addOnFailureListener", new TaskOnFailedProxy(callback))) ;
return task;
}

public static void AddOnCompleteListener<T>(AndroidJavaObject task, Action<T> callback)
/** <returns> self </returns> */
public static AndroidJavaObject AddOnCompleteListener<T>(this AndroidJavaObject task, Action<T> callback)
{
using (task.Call<AndroidJavaObject>("addOnCompleteListener", new TaskOnCompleteProxy<T>(callback))) ;
return task;
}

private class TaskOnCompleteProxy<T> : AndroidJavaProxy
Expand Down Expand Up @@ -65,8 +75,7 @@ private class TaskOnSuccessProxy<T> : AndroidJavaProxy
private Action<T> mCallback;
private bool mDisposeResult;

public TaskOnSuccessProxy(Action<T> callback, bool disposeResult)
: base("com/google/android/gms/tasks/OnSuccessListener")
public TaskOnSuccessProxy(Action<T> callback, bool disposeResult) : base("com/google/android/gms/tasks/OnSuccessListener")
{
mCallback = callback;
mDisposeResult = disposeResult;
Expand All @@ -92,8 +101,7 @@ private class TaskOnFailedProxy : AndroidJavaProxy
{
private Action<AndroidJavaObject> mCallback;

public TaskOnFailedProxy(Action<AndroidJavaObject> callback)
: base("com/google/android/gms/tasks/OnFailureListener")
public TaskOnFailedProxy(Action<AndroidJavaObject> callback) : base("com/google/android/gms/tasks/OnFailureListener")
{
mCallback = callback;
}
Expand All @@ -106,6 +114,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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -72,7 +72,7 @@ internal NearbyGUI(MainGui owner)
mMessageLog = new List<string>();
mKnownEndpoints = new HashSet<string>();

#if UNITY_ANDROID && UNITY_2019
#if UNITY_ANDROID && UNITY_2018_3_OR_NEWER
Permission.RequestUserPermission(Permission.FineLocation);
Permission.RequestUserPermission(Permission.CoarseLocation);
#endif
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}

0 comments on commit aeb2787

Please sign in to comment.