internal void DoAuthenticate(SignInInteractivity interactivity, PlayGamesClientConfiguration configuration) { SetStandBy("Authenticating..."); ClientConfiguration = configuration; PlayGamesPlatform.InitializeInstance(ClientConfiguration); PlayGamesPlatform.Activate(); PlayGamesPlatform.Instance.Authenticate(interactivity, (code) => { EndStandBy(); if (code == SignInStatus.Success) { Status = "Authenticated. Hello, " + Social.localUser.userName + " (" + Social.localUser.id + ")"; } else { Status = "*** Failed to authenticate with " + code; } ShowEffect(code == SignInStatus.Success); }); }
public void Authenticate(SignInInteractivity signInInteractivity, Action <SignInStatus> callback) { if (mClient == null) { Debug.Log("Creating Bazaar Games client."); mClient = BazaarGamesClientFactory.GetPlatformBazaarGamesClient(mConfiguration); } if (callback == null) { callback = status => { }; } switch (signInInteractivity) { case SignInInteractivity.NoPrompt: mClient.Authenticate(true, code => { // SignInStatus.UiSignInRequired is returned when silent sign in fails or when there is no // internet connection. if (code == SignInStatus.UiSignInRequired && Application.internetReachability == NetworkReachability.NotReachable) { callback(SignInStatus.NetworkError); } else { callback(code); } }); break; case SignInInteractivity.CanPromptAlways: mClient.Authenticate(false, code => { // SignInStatus.Canceled is returned when interactive sign in fails or when there is no internet connection. if (code == SignInStatus.Canceled && Application.internetReachability == NetworkReachability.NotReachable) { callback(SignInStatus.NetworkError); } else { callback(code); } }); break; case SignInInteractivity.CanPromptOnce: // 1. Silent sign in first mClient.Authenticate(true, silentSignInResultCode => { if (silentSignInResultCode == SignInStatus.Success) { Debug.Log("Successful, triggering callback"); callback(silentSignInResultCode); return; } // 2. Check the shared pref and bail out if it's true. if (!SignInHelper.ShouldPromptUiSignIn()) { Debug.Log( "User cancelled sign in attempt in the previous attempt. Triggering callback with silentSignInResultCode"); callback(silentSignInResultCode); return; } // 3. Check internet connection if (Application.internetReachability == NetworkReachability.NotReachable) { Debug.Log("No internet connection"); callback(SignInStatus.NetworkError); return; } // 4. Interactive sign in mClient.Authenticate(false, interactiveSignInResultCode => { // 5. Save that the user has cancelled the interactive sign in. if (interactiveSignInResultCode == SignInStatus.Canceled) { Debug.Log("Cancelled, saving this to a shared pref"); SignInHelper.SetPromptUiSignIn(false); } callback(interactiveSignInResultCode); }); }); break; default: BazaarGamesHelperObject.RunOnGameThread(() => callback(SignInStatus.Failed)); break; } }