public void RegisterMatchDelegate(MatchDelegate deleg)
 {
     Logger.d("AndroidTbmpClient.RegisterMatchDelegate");
     if (deleg == null)
     {
         Logger.w("Can't register a null match delegate.");
         return;
     }
     this.mMatchDelegate = deleg;
     if (this.mMatchFromNotification != null)
     {
         Logger.d("Delivering pending match to the newly registered delegate.");
         TurnBasedMatch match = this.mMatchFromNotification;
         this.mMatchFromNotification = null;
         PlayGamesHelperObject.RunOnGameThread(delegate
         {
             deleg(match, true);
         });
     }
 }
        internal static void InitializeFactory()
        {
            // initialize the callback thread processing
            PlayGamesHelperObject.CreateObject();

            //Read the Service ID
            NearbyConnectionsManager.ReadServiceId();

            NearbyConnectionsManagerBuilder sBuilder = new NearbyConnectionsManagerBuilder();

            // The connection manager needs to be initialized before using it, so
            // wait for initialization.
            sBuilder.SetOnInitializationFinished(OnManagerInitialized);
            PlatformConfiguration cfg = new AndroidClient().CreatePlatformConfiguration();

#if BUILD_TYPE_DEBUG
            Debug.Log("Building manager Now");
#endif
            sManager = sBuilder.Build(cfg);
        }
示例#3
0
        PlatformConfiguration CreatePlatformConfiguration(GameServicesBuilder builder)
        {
        #if UNITY_ANDROID
            var config = AndroidPlatformConfiguration.Create();
            config.EnableAppState();
            using (var activity = GetActivity()) {
                config.SetActivity(activity.GetRawObject());
                config.SetOptionalIntentHandlerForUI((intent) => {
                    // Capture a global reference to the intent we are to show. This is required
                    // since we are launching the intent from the game thread, and this callback
                    // will return before this happens. If we do not hold onto a durable reference,
                    // the code calling us will clean up the intent before we have a chance to display
                    // it.
                    IntPtr intentRef = AndroidJNI.NewGlobalRef(intent);

                    PlayGamesHelperObject.RunOnGameThread(() => {
                        try {
                            LaunchBridgeIntent(intentRef);
                        } finally {
                            // Now that we've launched the intent, release the global reference.
                            AndroidJNI.DeleteGlobalRef(intentRef);
                        }
                    });
                });
            }

            return(config);
        #endif

        #if UNITY_IPHONE
            if (!GameInfo.IosClientIdInitialized())
            {
                throw new System.InvalidOperationException("Could not locate the OAuth Client ID, " +
                                                           "provide this by navigating to Google Play Games > iOS Setup");
            }

            var config = IosPlatformConfiguration.Create();
            config.SetClientId(GameInfo.IosClientId);
            return(config);
        #endif
        }
示例#4
0
 public void LoadFriends(Action <bool> callback)
 {
     if (!IsAuthenticated())
     {
         Logger.d("Cannot loadFriends when not authenticated");
         PlayGamesHelperObject.RunOnGameThread(delegate
         {
             callback(false);
         });
     }
     else if (mFriends != null)
     {
         PlayGamesHelperObject.RunOnGameThread(delegate
         {
             callback(true);
         });
     }
     else
     {
         mServices.PlayerManager().FetchFriends(delegate(ResponseStatus status, List <GooglePlayGames.BasicApi.Multiplayer.Player> players)
         {
             if (status == ResponseStatus.Success || status == ResponseStatus.SuccessWithStale)
             {
                 mFriends = players;
                 PlayGamesHelperObject.RunOnGameThread(delegate
                 {
                     callback(true);
                 });
             }
             else
             {
                 mFriends = new List <GooglePlayGames.BasicApi.Multiplayer.Player>();
                 Logger.e("Got " + status + " loading friends");
                 PlayGamesHelperObject.RunOnGameThread(delegate
                 {
                     callback(false);
                 });
             }
         });
     }
 }
示例#5
0
        ///<summary></summary>
        /// <seealso cref="GooglePlayGames.BasicApi.IPlayGamesClient.GetPlayerStats"/>
        public void GetPlayerStats(Action <CommonStatusCodes, PlayerStats> callback)
        {
#if UNITY_ANDROID
            // Temporary fix to get SpendProbability until the
            // C++ SDK supports it.
            PlayGamesHelperObject.RunOnGameThread(() =>
                                                  clientImpl.GetPlayerStats(GetApiClient(), callback));
#else
            mServices.StatsManager().FetchForPlayer((playerStatsResponse) => {
                // Translate native errors into CommonStatusCodes.
                CommonStatusCodes responseCode =
                    ConversionUtils.ConvertResponseStatusToCommonStatus(playerStatsResponse.Status());
                // Log errors.
                if (responseCode != CommonStatusCodes.Success &&
                    responseCode != CommonStatusCodes.SuccessCached)
                {
                    GooglePlayGames.OurUtils.Logger.e("Error loading PlayerStats: " + playerStatsResponse.Status().ToString());
                }
                // Fill in the stats & call the callback.
                if (callback != null)
                {
                    if (playerStatsResponse.PlayerStats() != null)
                    {
                        // Copy the object out of the native interface so
                        // it will not be deleted before the callback is
                        // executed on the UI thread.
                        PlayerStats stats =
                            playerStatsResponse.PlayerStats().AsPlayerStats();
                        PlayGamesHelperObject.RunOnGameThread(() =>
                                                              callback(responseCode, stats));
                    }
                    else
                    {
                        PlayGamesHelperObject.RunOnGameThread(() =>
                                                              callback(responseCode, new PlayerStats()));
                    }
                }
            });
#endif
        }
示例#6
0
        private void OnInvitationReceived(AndroidJavaObject invitationObj)
        {
            Logger.d("AndroidClient.OnInvitationReceived. Converting invitation...");
            Invitation inv = this.ConvertInvitation(invitationObj);

            Logger.d("Invitation: " + inv.ToString());
            if (this.mInvitationDelegate != null)
            {
                Logger.d("Delivering invitation to invitation received delegate.");
                PlayGamesHelperObject.RunOnGameThread(delegate
                {
                    if (this.mInvitationDelegate != null)
                    {
                        this.mInvitationDelegate(inv, false);
                    }
                });
            }
            else
            {
                Logger.w("AndroidClient.OnInvitationReceived discarding invitation because  delegate is null.");
            }
        }
        public void onResult(AndroidJavaObject result)
        {
            Logger.d("OnCommitResultProxy.onResult, result=" + result);

            if (result == null)
            {
                Logger.e("OnCommitResultProxy: result is null.");
                return;
            }

            int statusCode = JavaUtil.GetStatusCode(result);

            Logger.d("OnCommitResultProxy: status code is " + statusCode);

            if (mListener != null)
            {
                Logger.d("OnCommitResultProxy.onResult invoke callback.");
                PlayGamesHelperObject.RunOnGameThread(() => {
                    mListener.OnSnapshotCommitted(statusCode);
                });
            }
        }
        public void RegisterMatchDelegate(MatchDelegate deleg)
        {
            Logger.d("AndroidTbmpClient.RegisterMatchDelegate");
            if (deleg == null)
            {
                Logger.w("Can't register a null match delegate.");
                return;
            }

            mMatchDelegate = deleg;

            // if we have a pending match to deliver, deliver it now
            if (mMatchFromNotification != null)
            {
                Logger.d("Delivering pending match to the newly registered delegate.");
                TurnBasedMatch match = mMatchFromNotification;
                mMatchFromNotification = null;
                PlayGamesHelperObject.RunOnGameThread(() => {
                    deleg.Invoke(match, true);
                });
            }
        }
示例#9
0
        internal void HandleInvitation(Types.MultiplayerEvent eventType, string invitationId, GooglePlayGames.Native.PInvoke.MultiplayerInvitation invitation)
        {
            Action <Invitation, bool> currentHandler = mInvitationDelegate;

            if (currentHandler == null)
            {
                Logger.d("Received " + eventType + " for invitation " + invitationId + " but no handler was registered.");
            }
            else if (eventType == Types.MultiplayerEvent.REMOVED)
            {
                Logger.d("Ignoring REMOVED for invitation " + invitationId);
            }
            else
            {
                bool       shouldAutolaunch = eventType == Types.MultiplayerEvent.UPDATED_FROM_APP_LAUNCH;
                Invitation invite           = invitation.AsInvitation();
                PlayGamesHelperObject.RunOnGameThread(delegate
                {
                    currentHandler(invite, shouldAutolaunch);
                });
            }
        }
            private void OnStateConflict(int stateKey, string resolvedVersion,
                                         byte[] localData, byte[] serverData)
            {
                GooglePlayGames.OurUtils.Logger.d("OnStateResultProxy.onStateConflict called, stateKey=" + stateKey +
                                                  ", resolvedVersion=" + resolvedVersion);

                debugLogData("localData", localData);
                debugLogData("serverData", serverData);

                if (mListener != null)
                {
                    GooglePlayGames.OurUtils.Logger.d("OnStateResultProxy.onStateConflict invoking conflict callback.");
                    PlayGamesHelperObject.RunOnGameThread(() => {
                        byte[] resolvedData =
                            mListener.OnStateConflict(stateKey, localData, serverData);
                        ResolveState(stateKey, resolvedVersion, resolvedData, mListener);
                    });
                }
                else
                {
                    GooglePlayGames.OurUtils.Logger.w("No conflict callback specified! Cannot resolve cloud save conflict.");
                }
            }
        private void OnInvitationInboxResult(bool success, string invitationId,
                                             Action <bool, TurnBasedMatch> callback)
        {
            Logger.d("AndroidTbmpClient.OnInvitationInboxResult, success=" + success + ", " +
                     "invitationId=" + invitationId);

            if (!success)
            {
                Logger.w("Tbmp invitation inbox returned failure result.");
                if (callback != null)
                {
                    Logger.d("Reporting tbmp invitation inbox failure to callback.");
                    PlayGamesHelperObject.RunOnGameThread(() => {
                        callback.Invoke(false, null);
                    });
                }
                return;
            }

            Logger.d("Accepting invite received from inbox: " + invitationId);
            TbmpApiCall("accept invite returned from inbox", "acceptInvitation",
                        null, callback, invitationId);
        }
示例#12
0
 /// <summary>
 /// Asynchronously retrieves the server auth code for this client.
 /// </summary>
 /// <remarks>Note: This function is currently only implemented for Android.</remarks>
 /// <param name="serverClientId">The Client ID.</param>
 /// <param name="callback">Callback for response.</param>
 public void GetServerAuthCode(string serverClientId, Action <CommonStatusCodes, string> callback)
 {
     mServices.FetchServerAuthCode(serverClientId, (serverAuthCodeResponse) => {
         // Translate native errors into CommonStatusCodes.
         CommonStatusCodes responseCode =
             ConversionUtils.ConvertResponseStatusToCommonStatus(serverAuthCodeResponse.Status());
         // Log errors.
         if (responseCode != CommonStatusCodes.Success &&
             responseCode != CommonStatusCodes.SuccessCached)
         {
             OurUtils.Logger.e("Error loading server auth code: " + serverAuthCodeResponse.Status().ToString());
         }
         // Fill in the code & call the callback.
         if (callback != null)
         {
             // copy the auth code into managed memory before posting
             // the callback.
             string authCode = serverAuthCodeResponse.Code();
             PlayGamesHelperObject.RunOnGameThread(() =>
                                                   callback(responseCode, authCode));
         }
     });
 }
示例#13
0
        public void LoadFriends(Action <bool> callback)
        {
            if (!IsAuthenticated())
            {
                GooglePlayGames.OurUtils.Logger.d("Cannot loadFriends when not authenticated");
                PlayGamesHelperObject.RunOnGameThread(() =>
                                                      callback(false));
                return;
            }

            // avoid calling excessively
            if (mFriends != null)
            {
                PlayGamesHelperObject.RunOnGameThread(() =>
                                                      callback(true));
                return;
            }

            mServices.PlayerManager().FetchFriends((status, players) =>
            {
                if (status == ResponseStatus.Success ||
                    status == ResponseStatus.SuccessWithStale)
                {
                    mFriends = players;
                    PlayGamesHelperObject.RunOnGameThread(() =>
                                                          callback(true));
                }
                else
                {
                    mFriends = new List <Player>();
                    GooglePlayGames.OurUtils.Logger.e(
                        "Got " + status + " loading friends");
                    PlayGamesHelperObject.RunOnGameThread(() =>
                                                          callback(false));
                }
            });
        }
示例#14
0
        public PlatformConfiguration CreatePlatformConfiguration(PlayGamesClientConfiguration clientConfig)
        {
            var config = AndroidPlatformConfiguration.Create();

            using (var activity = AndroidTokenClient.GetActivity())
            {
                config.SetActivity(activity.GetRawObject());
                config.SetOptionalIntentHandlerForUI((intent) =>
                {
                    // Capture a global reference to the intent we are to show. This is required
                    // since we are launching the intent from the game thread, and this callback
                    // will return before this happens. If we do not hold onto a durable reference,
                    // the code calling us will clean up the intent before we have a chance to display
                    // it.
                    IntPtr intentRef = AndroidJNI.NewGlobalRef(intent);

                    PlayGamesHelperObject.RunOnGameThread(() =>
                    {
                        try
                        {
                            LaunchBridgeIntent(intentRef);
                        }
                        finally
                        {
                            // Now that we've launched the intent, release the global reference.
                            AndroidJNI.DeleteGlobalRef(intentRef);
                        }
                    });
                });
                if (clientConfig.IsHidingPopups)
                {
                    config.SetOptionalViewForPopups(AndroidTokenClient.CreateInvisibleView().GetRawObject());
                }
            }
            return(config);
        }
 private static Action <T1, T2> ToOnGameThread <T1, T2>(Action <T1, T2> toConvert)
 {
     return((val1, val2) => PlayGamesHelperObject.RunOnGameThread(() => toConvert(val1, val2)));
 }
 public void OnEndpointLost(string lostEndpointId)
 {
     PlayGamesHelperObject.RunOnGameThread(() => mListener.OnEndpointLost(lostEndpointId));
 }
 public void OnEndpointFound(EndpointDetails discoveredEndpoint)
 {
     PlayGamesHelperObject.RunOnGameThread(() => mListener.OnEndpointFound(discoveredEndpoint));
 }
 public void OnRemoteEndpointDisconnected(string remoteEndpointId)
 {
     PlayGamesHelperObject.RunOnGameThread(
         () => mListener.OnRemoteEndpointDisconnected(remoteEndpointId));
 }
示例#19
0
 public void OnLeftRoom()
 {
     PlayGamesHelperObject.RunOnGameThread(() => mListener.OnLeftRoom());
 }
示例#20
0
 /// <summary>
 /// Gets another server auth code.
 /// </summary>
 /// <remarks>This method should be called after authenticating, and exchanging
 /// the initial server auth code for a token.  This is implemented by signing in
 /// silently, which if successful returns almost immediately and with a new
 /// server auth code.
 /// </remarks>
 /// <param name="reAuthenticateIfNeeded">Calls Authenticate if needed when
 /// retrieving another auth code. </param>
 /// <param name="callback">Callback.</param>
 public void GetAnotherServerAuthCode(bool reAuthenticateIfNeeded, Action <string> callback)
 {
     PlayGamesHelperObject.RunOnGameThread(() => DoGetAnotherServerAuthCode(reAuthenticateIfNeeded, callback));
 }
示例#21
0
 public void FetchTokens(bool silent, Action <int> callback)
 {
     PlayGamesHelperObject.RunOnGameThread(() => DoFetchToken(silent, callback));
 }
 public NativeClient(PlayGamesClientConfiguration configuration)
 {
     PlayGamesHelperObject.CreateObject();
     this.mConfiguration = Misc.CheckNotNull(configuration);
 }
示例#23
0
 public void OnRoomSetupProgress(float percent)
 {
     PlayGamesHelperObject.RunOnGameThread(() => mListener.OnRoomSetupProgress(percent));
 }
示例#24
0
 public void OnRealTimeMessageReceived(bool isReliable, string senderId, byte[] data)
 {
     PlayGamesHelperObject.RunOnGameThread(
         () => mListener.OnRealTimeMessageReceived(isReliable, senderId, data));
 }
示例#25
0
 public void OnPeersDisconnected(string[] participantIds)
 {
     PlayGamesHelperObject.RunOnGameThread(
         () => mListener.OnPeersDisconnected(participantIds));
 }
示例#26
0
 public void SetGravityForPopups(Gravity gravity)
 {
     PlayGamesHelperObject.RunOnGameThread(() =>
                                           clientImpl.SetGravityForPopups(GetApiClient(), gravity));
 }
示例#27
0
        private readonly int mLeaderboardMaxResults = 25; // can be from 1 to 25

        internal AndroidClient(PlayGamesClientConfiguration configuration)
        {
            PlayGamesHelperObject.CreateObject();
            this.mConfiguration = Misc.CheckNotNull(configuration);
            RegisterInvitationDelegate(configuration.InvitationDelegate);
        }
 public void OnMessageReceived(string remoteEndpointId, byte[] data,
                               bool isReliableMessage)
 {
     PlayGamesHelperObject.RunOnGameThread(() => mListener.OnMessageReceived(
                                               remoteEndpointId, data, isReliableMessage));
 }
示例#29
0
 public void OnParticipantLeft(Participant participant)
 {
     PlayGamesHelperObject.RunOnGameThread(
         () => mListener.OnParticipantLeft(participant));
 }
示例#30
0
 public void OnRoomConnected(bool success)
 {
     PlayGamesHelperObject.RunOnGameThread(() => mListener.OnRoomConnected(success));
 }