示例#1
0
        public static void ShowSelectSnapshotUI(bool showCreateSaveUI, bool showDeleteSaveUI,
                                                int maxDisplayedSavedGames, string uiTitle, Action <SelectUIStatus, ISavedGameMetadata> cb)
        {
            using (var helperFragment = new AndroidJavaClass(HelperFragmentClass))
                using (var task = helperFragment.CallStatic <AndroidJavaObject>("showSelectSnapshotUi",
                                                                                AndroidHelperFragment.GetActivity(), uiTitle, showCreateSaveUI, showDeleteSaveUI,
                                                                                maxDisplayedSavedGames))
                {
                    AndroidTaskUtils.AddOnSuccessListener <AndroidJavaObject>(
                        task,
                        result =>
                    {
                        SelectUIStatus status = (SelectUIStatus)result.Get <int>("status");
                        Debug.Log("ShowSelectSnapshotUI result " + status);

                        AndroidJavaObject javaMetadata   = result.Get <AndroidJavaObject>("metadata");
                        AndroidSnapshotMetadata metadata =
                            javaMetadata == null
                                ? null
                                : new AndroidSnapshotMetadata(javaMetadata, /* contents= */ null);

                        cb.Invoke(status, metadata);
                    });

                    AndroidTaskUtils.AddOnFailureListener(
                        task,
                        exception =>
                    {
                        Debug.Log("ShowSelectSnapshotUI failed with exception");
                        cb.Invoke(SelectUIStatus.InternalError, null);
                    });
                }
        }
示例#2
0
 public static void ShowCaptureOverlayUI()
 {
     using (var helperFragment = new AndroidJavaClass(HelperFragmentClass))
     {
         helperFragment.CallStatic("showCaptureOverlayUi", AndroidHelperFragment.GetActivity());
     }
 }
示例#3
0
        public void ShowWaitingRoomUI()
        {
            var roomStatus = GetRoomStatus();

            if (roomStatus != RoomStatus.Connecting && roomStatus != RoomStatus.AutoMatching &&
                roomStatus != RoomStatus.Inviting)
            {
                return;
            }

            AndroidHelperFragment.ShowWaitingRoomUI(mRoom, mMinPlayersToStart, (response, room) =>
            {
                if (response == AndroidHelperFragment.WaitingRoomUIStatus.Valid)
                {
                    mRoom = room;
                    if (GetRoomStatus() == RoomStatus.Active)
                    {
                        mListener.OnRoomConnected(true);
                    }
                }
                else if (response == AndroidHelperFragment.WaitingRoomUIStatus.LeftRoom)
                {
                    LeaveRoom();
                }
                else
                {
                    mListener.OnRoomSetupProgress(GetPercentComplete());
                }
            });
        }
示例#4
0
        public void AcceptFromInbox(RealTimeMultiplayerListener listener)
        {
            var listenerOnGameThread = new OnGameThreadForwardingListener(listener);

            lock (mSessionLock)
            {
                if (GetRoomStatus() == RoomStatus.Active)
                {
                    OurUtils.Logger.e("Received attempt to accept invitation without cleaning up " +
                                      "active session.");
                    listenerOnGameThread.OnRoomConnected(false);
                    return;
                }

                AndroidHelperFragment.ShowInvitationInboxUI((status, invitation) =>
                {
                    if (status == UIStatus.NotAuthorized)
                    {
                        mAndroidClient.SignOut((() => listenerOnGameThread.OnRoomConnected(false)));
                        return;
                    }

                    if (status != UIStatus.Valid)
                    {
                        OurUtils.Logger.d("User did not complete invitation screen.");
                        listenerOnGameThread.OnRoomConnected(false);
                        return;
                    }

                    mInvitation = invitation;

                    AcceptInvitation(mInvitation.InvitationId, listener);
                });
            }
        }
 public string GetAppBundleId()
 {
     using (var activity = AndroidHelperFragment.GetActivity())
     {
         return(activity.Call <string>("getPackageName"));
     }
 }
示例#6
0
        public void AcceptFromInbox(RealTimeMultiplayerListener listener)
        {
            lock (mSessionLock)
            {
                if (GetRoomStatus() == RoomStatus.Active)
                {
                    OurUtils.Logger.e("Received attempt to accept invitation without cleaning up " +
                                      "active session.");
                    listener.OnRoomConnected(false);
                    return;
                }

                AndroidHelperFragment.ShowInvitationInboxUI((status, invitation) =>
                {
                    if (status != UIStatus.Valid)
                    {
                        OurUtils.Logger.d("User did not complete invitation screen.");
                        listener.OnRoomConnected(false);
                        return;
                    }

                    mInvitation = invitation;

                    AcceptInvitation(mInvitation.InvitationId, listener);
                });
            }
        }
        public void RequestPermissions(string[] scopes, Action <SignInStatus> callback)
        {
            using (var bridgeClass = new AndroidJavaClass(HelperFragmentClass))
                using (var currentActivity = AndroidHelperFragment.GetActivity())
                    using (var task =
                               bridgeClass.CallStatic <AndroidJavaObject>("showRequestPermissionsUi", currentActivity,
                                                                          oauthScopes.Union(scopes).ToArray()))
                    {
                        AndroidTaskUtils.AddOnSuccessListener <AndroidJavaObject>(task, /* disposeResult= */ false,
                                                                                  accountWithNewScopes =>
                        {
                            if (accountWithNewScopes == null)
                            {
                                callback(SignInStatus.InternalError);
                                return;
                            }

                            account     = accountWithNewScopes;
                            email       = account.Call <string>("getEmail");
                            idToken     = account.Call <string>("getIdToken");
                            authCode    = account.Call <string>("getServerAuthCode");
                            oauthScopes = oauthScopes.Union(scopes).ToList();
                            callback(SignInStatus.Success);
                        });

                        AndroidTaskUtils.AddOnFailureListener(task, e =>
                        {
                            var failCode = SignInHelper.ToSignInStatus(e.Call <int>("getStatusCode"));
                            OurUtils.Logger.e("Exception requesting new permissions: " + failCode);
                            callback(failCode);
                        });
                    }
        }
示例#8
0
        public static void ShowInvitationInboxUI(Action <UIStatus, Invitation> cb)
        {
            using (var helperFragment = new AndroidJavaClass(HelperFragmentClass))
                using (var task = helperFragment.CallStatic <AndroidJavaObject>("showInvitationInboxUI",
                                                                                AndroidHelperFragment.GetActivity()))
                {
                    AndroidTaskUtils.AddOnSuccessListener <AndroidJavaObject>(
                        task,
                        result =>
                    {
                        int status = result.Get <int>("status");
                        if ((UIStatus)status != UIStatus.Valid)
                        {
                            cb.Invoke((UIStatus)status, null);
                            return;
                        }

                        using (var invitation = result.Get <AndroidJavaObject>("invitation"))
                        {
                            cb.Invoke((UIStatus)status, AndroidJavaConverter.ToInvitation(invitation));
                        }
                    });

                    AndroidTaskUtils.AddOnFailureListener(
                        task,
                        exception =>
                    {
                        Debug.Log("ShowInvitationInboxUI failed with exception");
                        cb.Invoke(UIStatus.InternalError, null);
                    });
                }
        }
示例#9
0
 private void DoGetAnotherServerAuthCode(bool reAuthenticateIfNeeded, Action <string> callback)
 {
     try
     {
         using (var bridgeClass = new AndroidJavaClass(HelperFragmentClass))
             using (var currentActivity = AndroidHelperFragment.GetActivity())
                 using (var pendingResult = bridgeClass.CallStatic <AndroidJavaObject>(
                            "fetchToken",
                            currentActivity,
                            /* silent= */ reAuthenticateIfNeeded,
                            /* requestAuthCode= */ true,
                            /* requestEmail= */ false,
                            /* requestIdToken= */ false,
                            webClientId,
                            /* forceRefresh= */ false,
                            oauthScopes.ToArray(),
                            /* hidePopups= */ true,
                            /* accountName= */ ""))
                 {
                     pendingResult.Call("setResultCallback", new ResultCallbackProxy(
                                            tokenResult => { callback(tokenResult.Call <string>("getAuthCode")); }));
                 }
     }
     catch (Exception e)
     {
         OurUtils.Logger.e("Exception launching token request: " + e.Message);
         OurUtils.Logger.e(e.ToString());
     }
 }
示例#10
0
        public void CreateWithInvitationScreen(uint minOpponents, uint maxOpponents, uint variant,
                                               Action <UIStatus, TurnBasedMatch> callback)
        {
            callback = ToOnGameThread(callback);

            AndroidHelperFragment.ShowTbmpSelectOpponentsUI(minOpponents, maxOpponents,
                                                            (status, result) =>
            {
                if (status != UIStatus.Valid)
                {
                    callback(status, null);
                    return;
                }

                using (var matchConfigClass =
                           new AndroidJavaClass("com.google.android.gms.games.multiplayer.turnbased.TurnBasedMatchConfig"))
                    using (var matchConfigBuilder = matchConfigClass.CallStatic <AndroidJavaObject>("builder"))
                    {
                        if (result.MinAutomatchingPlayers > 0)
                        {
                            using (var autoMatchCriteria = matchConfigClass.CallStatic <AndroidJavaObject>(
                                       "createAutoMatchCriteria", result.MinAutomatchingPlayers,
                                       result.MaxAutomatchingPlayers, /* exclusiveBitMask= */ (long)0))
                                using (matchConfigBuilder.Call <AndroidJavaObject>("setAutoMatchCriteria",
                                                                                   autoMatchCriteria))
                                    ;
                        }

                        if (variant != 0)
                        {
                            using (matchConfigBuilder.Call <AndroidJavaObject>("setVariant", (int)variant));
                        }

                        using (var invitedPlayersObject = new AndroidJavaObject("java.util.ArrayList"))
                        {
                            for (int i = 0; i < result.PlayerIdsToInvite.Count; ++i)
                            {
                                invitedPlayersObject.Call <bool>("add", result.PlayerIdsToInvite[i]);
                            }

                            using (matchConfigBuilder.Call <AndroidJavaObject>("addInvitedPlayers", invitedPlayersObject)
                                   );
                        }

                        using (var matchConfig = matchConfigBuilder.Call <AndroidJavaObject>("build"))
                            using (var task = mClient.Call <AndroidJavaObject>("createMatch", matchConfig))
                            {
                                AndroidTaskUtils.AddOnSuccessListener <AndroidJavaObject>(
                                    task,
                                    turnBasedMatch =>
                                    callback(UIStatus.Valid, AndroidJavaConverter.ToTurnBasedMatch(turnBasedMatch)));

                                AndroidTaskUtils.AddOnFailureListener(
                                    task,
                                    exception => callback(UIStatus.InternalError, null));
                            }
                    }
            });
        }
示例#11
0
 public AndroidEventsClient(AndroidJavaObject account)
 {
     using (var gamesClass = new AndroidJavaClass("com.google.android.gms.games.Games"))
     {
         mEventsClient = gamesClass.CallStatic <AndroidJavaObject>("getEventsClient",
                                                                   AndroidHelperFragment.GetActivity(), account);
     }
 }
示例#12
0
 /// <summary>Returns whether or not user has given permissions for given scopes.</summary>
 /// <param name="scopes">array of scopes</param>
 /// <returns><c>true</c>, if given, <c>false</c> otherwise.</returns>
 public bool HasPermissions(string[] scopes)
 {
     using (var bridgeClass = new AndroidJavaClass(HelperFragmentClass))
         using (var currentActivity = AndroidHelperFragment.GetActivity())
         {
             return(bridgeClass.CallStatic <bool>("hasPermissions", currentActivity, scopes));
         }
 }
示例#13
0
 public static AndroidJavaObject GetDefaultPopupView()
 {
     using (var helperFragment = new AndroidJavaClass(HelperFragmentClass))
         using (var activity = AndroidHelperFragment.GetActivity())
         {
             return(helperFragment.CallStatic <AndroidJavaObject>("getDecorView", activity));
         }
 }
示例#14
0
 public AndroidVideoClient(bool isCaptureSupported, AndroidJavaObject account)
 {
     mIsCaptureSupported = isCaptureSupported;
     using (var gamesClass = new AndroidJavaClass("com.google.android.gms.games.Games"))
     {
         mVideosClient = gamesClass.CallStatic <AndroidJavaObject>("getVideosClient",
                                                                   AndroidHelperFragment.GetActivity(), account);
     }
 }
示例#15
0
 public AndroidSavedGameClient(AndroidClient androidClient, AndroidJavaObject account)
 {
     mAndroidClient = androidClient;
     using (var gamesClass = new AndroidJavaClass("com.google.android.gms.games.Games"))
     {
         mSnapshotsClient = gamesClass.CallStatic <AndroidJavaObject>("getSnapshotsClient",
                                                                      AndroidHelperFragment.GetActivity(), account);
     }
 }
 public AndroidTurnBasedMultiplayerClient(AndroidClient androidClient, AndroidJavaObject account)
 {
     mAndroidClient = androidClient;
     using (var gamesClass = new AndroidJavaClass("com.google.android.gms.games.Games"))
     {
         mClient = gamesClass.CallStatic <AndroidJavaObject>("getTurnBasedMultiplayerClient",
                                                             AndroidHelperFragment.GetActivity(), account);
     }
 }
示例#17
0
        ///<summary></summary>
        /// <seealso cref="GooglePlayGames.BasicApi.IPlayGamesClient.ShowAchievementsUI"/>
        public void ShowAchievementsUI(Action <UIStatus> callback)
        {
            if (!IsAuthenticated())
            {
                InvokeCallbackOnGameThread(callback, UIStatus.NotAuthorized);
                return;
            }

            AndroidHelperFragment.ShowAchievementsUI(GetUiSignOutCallbackOnGameThread(callback));
        }
 public AndroidNearbyConnectionClient()
 {
     PlayGamesHelperObject.CreateObject();
     NearbyHelperObject.CreateObject(this);
     using (var nearbyClass = new AndroidJavaClass("com.google.android.gms.nearby.Nearby"))
     {
         mClient = nearbyClass.CallStatic <AndroidJavaObject>("getConnectionsClient",
                                                              AndroidHelperFragment.GetActivity());
     }
 }
示例#19
0
 public AndroidRealTimeMultiplayerClient(AndroidClient androidClient, AndroidJavaObject account)
 {
     mAndroidClient = androidClient;
     using (var gamesClass = new AndroidJavaClass("com.google.android.gms.games.Games"))
     {
         mRtmpClient = gamesClass.CallStatic <AndroidJavaObject>("getRealTimeMultiplayerClient",
                                                                 AndroidHelperFragment.GetActivity(), account);
         mInvitationsClient = gamesClass.CallStatic <AndroidJavaObject>("getInvitationsClient",
                                                                        AndroidHelperFragment.GetActivity(), account);
     }
 }
示例#20
0
 public void Signout()
 {
     account  = null;
     authCode = null;
     email    = null;
     idToken  = null;
     PlayGamesHelperObject.RunOnGameThread(() =>
     {
         Debug.Log("Calling Signout in token client");
         AndroidJavaClass cls = new AndroidJavaClass(HelperFragmentClass);
         cls.CallStatic("signOut", AndroidHelperFragment.GetActivity());
     });
 }
示例#21
0
        public void AcceptFromInbox(Action <bool, TurnBasedMatch> callback)
        {
            callback = ToOnGameThread(callback);

            AndroidHelperFragment.ShowInboxUI((status, turnBasedMatch) =>
            {
                if (status != UIStatus.Valid)
                {
                    callback(false, null);
                    return;
                }

                OurUtils.Logger.d("Passing converted match to user callback:" + turnBasedMatch);
                callback(true, turnBasedMatch);
            });
        }
 private static string ReadServiceId()
 {
     using (var activity = AndroidHelperFragment.GetActivity())
     {
         string packageName = activity.Call <string>("getPackageName");
         using (var pm = activity.Call <AndroidJavaObject>("getPackageManager"))
             using (var appInfo =
                        pm.Call <AndroidJavaObject>("getApplicationInfo", packageName, ApplicationInfoFlags))
                 using (var bundle = appInfo.Get <AndroidJavaObject>("metaData"))
                 {
                     string sysId = bundle.Call <string>("getString",
                                                         "com.google.android.gms.nearby.connection.SERVICE_ID");
                     Debug.Log("SystemId from Manifest: " + sysId);
                     return(sysId);
                 }
     }
 }
示例#23
0
        ///<summary></summary>
        /// <seealso cref="GooglePlayGames.BasicApi.IPlayGamesClient.ShowLeaderboardUI"/>
        public void ShowLeaderboardUI(string leaderboardId, LeaderboardTimeSpan span, Action <UIStatus> callback)
        {
            if (!IsAuthenticated())
            {
                InvokeCallbackOnGameThread(callback, UIStatus.NotAuthorized);
                return;
            }

            if (leaderboardId == null)
            {
                AndroidHelperFragment.ShowAllLeaderboardsUI(AsOnGameThreadCallback(callback));
            }
            else
            {
                AndroidHelperFragment.ShowLeaderboardUI(leaderboardId, span, AsOnGameThreadCallback(callback));
            }
        }
示例#24
0
        public void ShowSelectSavedGameUI(string uiTitle, uint maxDisplayedSavedGames, bool showCreateSaveUI,
                                          bool showDeleteSaveUI, Action <SelectUIStatus, ISavedGameMetadata> callback)
        {
            Misc.CheckNotNull(uiTitle);
            Misc.CheckNotNull(callback);

            callback = ToOnGameThread(callback);

            if (!(maxDisplayedSavedGames > 0))
            {
                OurUtils.Logger.e("maxDisplayedSavedGames must be greater than 0");
                callback(SelectUIStatus.BadInputError, null);
                return;
            }

            AndroidHelperFragment.ShowSelectSnapshotUI(
                showCreateSaveUI, showDeleteSaveUI, (int)maxDisplayedSavedGames, uiTitle, callback);
        }
示例#25
0
        private static void ShowSelectOpponentsUI(uint minOpponents, uint maxOpponents, bool isRealTime,
                                                  Action <UIStatus, InvitationResultHolder> cb)
        {
            string methodName = isRealTime ? "showRtmpSelectOpponentsUi" : "showTbmpSelectOpponentsUi";

            using (var helperFragment = new AndroidJavaClass(HelperFragmentClass))
                using (var task = helperFragment.CallStatic <AndroidJavaObject>(methodName,
                                                                                AndroidHelperFragment.GetActivity(), (int)minOpponents, (int)maxOpponents))
                {
                    AndroidTaskUtils.AddOnSuccessListener <AndroidJavaObject>(
                        task,
                        result =>
                    {
                        int status = result.Get <int>("status");
                        if ((UIStatus)status != UIStatus.Valid)
                        {
                            cb.Invoke((UIStatus)status, null);
                            return;
                        }

                        List <string> playerIdsToInvite;
                        using (var ids = result.Get <AndroidJavaObject>("playerIdsToInvite"))
                        {
                            playerIdsToInvite = CreatePlayerIdsToInvite(ids);
                        }

                        InvitationResultHolder resultHolder = new InvitationResultHolder(
                            result.Get <int>("minAutomatchingPlayers"),
                            result.Get <int>("maxAutomatchingPlayers"),
                            playerIdsToInvite
                            );

                        cb.Invoke((UIStatus)status, resultHolder);
                    });

                    AndroidTaskUtils.AddOnFailureListener(
                        task,
                        exception =>
                    {
                        Debug.Log("showSelectOpponentsUi failed with exception");
                        cb.Invoke(UIStatus.InternalError, null);
                    });
                }
        }
示例#26
0
 private void DoGetAnotherServerAuthCode(bool reAuthenticateIfNeeded, Action <string> callback)
 {
     try
     {
         using (var bridgeClass = new AndroidJavaClass(HelperFragmentClass))
             using (var currentActivity = AndroidHelperFragment.GetActivity())
                 using (var pendingResult = bridgeClass.CallStatic <AndroidJavaObject>(
                            "getAnotherAuthCode", currentActivity, reAuthenticateIfNeeded, webClientId))
                 {
                     pendingResult.Call("setResultCallback", new ResultCallbackProxy(
                                            tokenResult => { callback(tokenResult.Call <string>("getAuthCode")); }));
                 }
     }
     catch (Exception e)
     {
         OurUtils.Logger.e("Exception launching token request: " + e.Message);
         OurUtils.Logger.e(e.ToString());
     }
 }
示例#27
0
        public static void AskForLoadFriendsResolution(
            AndroidJavaObject friendsSharingConsentException, Action <UIStatus> cb)
        {
            using (var helperFragment = new AndroidJavaClass(HelperFragmentClass))
                using (
                    var task = helperFragment.CallStatic <AndroidJavaObject>(
                        "askForLoadFriendsResolution", AndroidHelperFragment.GetActivity(),
                        friendsSharingConsentException))
                {
                    AndroidTaskUtils.AddOnSuccessListener <int>(task, uiCode =>
                    {
                        Debug.Log("AskForLoadFriendsResolution result " + uiCode);
                        cb.Invoke((UIStatus)uiCode);
                    });

                    AndroidTaskUtils.AddOnFailureListener(task, exception =>
                    {
                        Debug.Log("AskForLoadFriendsResolution failed with exception");
                        cb.Invoke(UIStatus.InternalError);
                    });
                }
        }
        public static void ShowAchievementsUI(Action<UIStatus> cb)
        {
            using (var helperFragment = new AndroidJavaClass(HelperFragmentClass))
            using (var task =
                helperFragment.CallStatic<AndroidJavaObject>("showAchievementUi", AndroidHelperFragment.GetActivity()))
            {
                AndroidTaskUtils.AddOnSuccessListener<int>(
                    task,
                    uiCode =>
                    {
                        OurUtils.Logger.d("ShowAchievementsUI result " + uiCode);
                        cb.Invoke((UIStatus) uiCode);
                    });

                AndroidTaskUtils.AddOnFailureListener(
                    task,
                    exception =>
                    {
                        OurUtils.Logger.e("ShowAchievementsUI failed with exception");
                        cb.Invoke(UIStatus.InternalError);
                    });
            }
        }
示例#29
0
 public static void ShowCompareProfileWithAlternativeNameHintsUI(
     string playerId, string otherPlayerInGameName, string currentPlayerInGameName,
     Action <UIStatus> cb)
 {
     using (var helperFragment = new AndroidJavaClass(HelperFragmentClass))
         using (
             var task = helperFragment.CallStatic <AndroidJavaObject>(
                 "showCompareProfileWithAlternativeNameHintsUI",
                 AndroidHelperFragment.GetActivity(), playerId, otherPlayerInGameName,
                 currentPlayerInGameName))
         {
             AndroidTaskUtils.AddOnSuccessListener <int>(task, uiCode =>
             {
                 Debug.Log("ShowCompareProfileWithAlternativeNameHintsUI result " + uiCode);
                 cb.Invoke((UIStatus)uiCode);
             });
             AndroidTaskUtils.AddOnFailureListener(task, exception =>
             {
                 Debug.Log("ShowCompareProfileWithAlternativeNameHintsUI failed with exception");
                 cb.Invoke(UIStatus.InternalError);
             });
         }
 }
示例#30
0
 private void DoFetchToken(bool silent, Action <int> callback)
 {
     try
     {
         using (var bridgeClass = new AndroidJavaClass(HelperFragmentClass))
             using (var currentActivity = AndroidHelperFragment.GetActivity())
                 using (var pendingResult = bridgeClass.CallStatic <AndroidJavaObject>(
                            "fetchToken",
                            currentActivity,
                            silent,
                            requestAuthCode,
                            requestEmail,
                            requestIdToken,
                            webClientId,
                            forceRefresh,
                            oauthScopes.ToArray(),
                            hidePopups,
                            accountName))
                 {
                     pendingResult.Call("setResultCallback", new ResultCallbackProxy(
                                            tokenResult =>
                     {
                         account  = tokenResult.Call <AndroidJavaObject>("getAccount");
                         authCode = tokenResult.Call <string>("getAuthCode");
                         email    = tokenResult.Call <string>("getEmail");
                         idToken  = tokenResult.Call <string>("getIdToken");
                         callback(tokenResult.Call <int>("getStatusCode"));
                     }));
                 }
     }
     catch (Exception e)
     {
         OurUtils.Logger.e("Exception launching token request: " + e.Message);
         OurUtils.Logger.e(e.ToString());
     }
 }