Beispiel #1
0
        //private void LogToDebugOutput(string msg)
        //{
        //    _txtDebugOutput.text += Environment.NewLine;
        //    _txtDebugOutput.text += msg;
        //}

        private void InitGooglePlayServices()
        {
            //todo: make this compatible with iOS too
            if (!_isGooglePlayGamesInitialized)
            {
                var config = new GooglePlayGames.BasicApi.PlayGamesClientConfiguration.Builder().Build();
                GooglePlayGames.PlayGamesPlatform.InitializeInstance(config);
                GooglePlayGames.PlayGamesPlatform.Activate();
                Social.localUser.Authenticate(GooglePlayGames_OnAuthenticationComplete); //todo: handle success and failure cases
            }
        }
Beispiel #2
0
 public static void SignIn()
 {
     if (signedIn)
     {
         return;
     }
     GooglePlayGames.BasicApi.PlayGamesClientConfiguration config =
         new GooglePlayGames.BasicApi.PlayGamesClientConfiguration.Builder().Build();
     GooglePlayGames.PlayGamesPlatform.InitializeInstance(config);
     GooglePlayGames.PlayGamesPlatform.Activate();
     Social.localUser.Authenticate(succes => { signedIn = succes; });
 }
        //private bool mInitialServerAuthCodeUsed;

        public GooglePlayProvider() : base(SocialNetworkType.GOOGLE_PLAY)
        {
#if UNITY_ANDROID
            //mInitialServerAuthCodeUsed = false;

            GooglePlayGames.BasicApi.PlayGamesClientConfiguration config = new GooglePlayGames.BasicApi.PlayGamesClientConfiguration.Builder()
                                                                           //.RequestServerAuthCode(false)  // needed only for GetServerAuthCode()
                                                                           .AddOauthScope("openid")
                                                                           .RequestIdToken()
                                                                           .Build();
            GooglePlayGames.PlayGamesPlatform.InitializeInstance(config);
            GooglePlayGames.PlayGamesPlatform.DebugLogEnabled = true;
            GooglePlayGames.PlayGamesPlatform.Activate();
#endif
            sInstance = this;
        }
        private void CheckerForPlayServiceActivation()
        {
#if UNITY_ANDROID && UNITY_ANDROID_PLAY_GAMES
            // Debug.Log("Initialize GooglePlayGames.BasicApi.PlayGamesClientConfiguration.Builder");
            var config = new GooglePlayGames.BasicApi.PlayGamesClientConfiguration.Builder()
                         // requests a server auth code be generated so it can be passed to an
                         //  associated back end server application and exchanged for an OAuth token.
                         // .RequestServerAuthCode(false)
                         // requests an ID token be generated.  This OAuth token can be used to
                         //  identify the player to other services such as Firebase.
                         // .RequestIdToken()
                         .Build();
            PlayGamesPlatform.InitializeInstance(config);
            PlayGamesPlatform.DebugLogEnabled = true;
            PlayGamesPlatform.Activate();
            // PlayGamesPlatform.Instance.Authenticate(IsSuccesfullyAuthentificated);
#endif
#if UNITY_ANDROID && !UNITY_EDITOR && UNITY_ANDROID_PLAY_GAMES
            // // based on https://github.com/playgameservices/play-games-plugin-for-unity/issues/715
            const string googleApiAvailabilityClassname =
                "com.google.android.gms.common.GoogleApiAvailability";
            AndroidJavaClass clazz =
                new AndroidJavaClass(googleApiAvailabilityClassname);
            AndroidJavaObject obj =
                clazz.CallStatic <AndroidJavaObject>("getInstance");
            var androidJc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            var activity  = androidJc.GetStatic <AndroidJavaObject>("currentActivity");
            _playServiceStatus = (PlayService)obj.Call <int>("isGooglePlayServicesAvailable", activity);


            // // 0 == success
            // // 1 == service_missing
            // // 2 == update service required
            // // 3 == service disabled
            // // 18 == service updating
            // // 9 == service invalid
#endif
            StartWaiting();
        }
Beispiel #5
0
        private static void AuthorizedAction(Action action, Action <bool, Exception> callback)
        {
            if (Busy)
            {
                WriteLog("busy...");
                return;
            }

            if (callback == null)
            {
                callback = (success, exception) => { }
            }
            ;

            Busy = true;

            if (Social.localUser.authenticated)
            {
                try
                {
                    action();
                }
                catch (Exception e)
                {
                    Break(e.Message, callback);
                }
            }
            else
            {
                WriteLog("authentication...");

                #if UNITY_ANDROID
                if (!Social.localUser.authenticated)
                {
                    var config = new GooglePlayGames.BasicApi.PlayGamesClientConfiguration.Builder().Build();

                    GooglePlayGames.PlayGamesPlatform.InitializeInstance(config);
                    GooglePlayGames.PlayGamesPlatform.DebugLogEnabled = true;
                    GooglePlayGames.PlayGamesPlatform.Activate();
                }
                #endif

                Social.localUser.Authenticate(authenticated =>
                {
                    if (authenticated)
                    {
                        try
                        {
                            action();
                        }
                        catch (Exception e)
                        {
                            Break(e.Message, callback);
                        }
                    }
                    else
                    {
                        Break("Social.localUser.Authenticate failed", callback);
                    }
                });
            }
        }