Beispiel #1
0
        internal GameHelperManager(AndroidClient client)
        {
            mAndroidClient = client;
            Logger.d("Setting up GameHelperManager.");

            // create GameHelper
            Logger.d("GHM creating GameHelper.");
            mGameHelper = new AndroidJavaObject(GameHelperClass, mAndroidClient.GetActivity());
            if (mGameHelper == null)
            {
                throw new System.Exception("Failed to create GameHelper.");
            }

            // set up the GameHelper
            Logger.d("GHM setting up GameHelper.");
            mGameHelper.Call("enableDebugLog", Logger.DebugLogEnabled, "GameHelper");
            int flags = mGameHelper.GetStatic <int>("CLIENT_ALL");

            Logger.d("GHM client request flags: " + flags);
            GameHelperListener listenerProxy = new GameHelperListener(this, ORIGIN_MAIN_ACTIVITY);

            Logger.d("GHM calling GameHelper.setRequestedClients, " + flags);
            mGameHelper.Call("setRequestedClients", flags);
            Logger.d("GHM calling GameHelper.setup");
            mGameHelper.Call("setup", listenerProxy);

            // set up callbacks so we're informed of pause/unpause events
            PlayGamesHelperObject.SetPauseCallback((bool paused) => {
                if (paused)
                {
                    OnPause();
                }
                else
                {
                    OnResume();
                }
            });

            // start silent auth
            Logger.d("GHM calling GameHelper.onStart to try silent auth.");
            mConnectionState = ConnectionState.Connecting;
            mGameHelper.Call("onStart", mAndroidClient.GetActivity());
        }
        public void Setup(GameHelperListener listener, int clientsToUse)
        {
            this.listener  = listener;
            requestClients = clientsToUse;

            List <string> scopesList = new List <string>();

            if (0 != (clientsToUse & CLIENT_GAMES))
            {
                scopesList.Add(Scopes.Games);
            }
            if (0 != (clientsToUse & CLIENT_PLUS))
            {
                scopesList.Add(Scopes.PlusLogin);
            }
            if (0 != (clientsToUse & CLIENT_APPSTATE))
            {
                scopesList.Add(Scopes.AppState);
            }

            if (0 != (clientsToUse & CLIENT_GAMES))
            {
                gamesClient = new GamesClient.Builder(activity, this, this)
                              .SetGravityForPopups((int)(GravityFlags.Top | GravityFlags.CenterHorizontal))
                              .SetScopes(scopesList.ToArray())
                              .Create();
            }

            if (0 != (clientsToUse & CLIENT_PLUS))
            {
                plusCient = new PlusClient.Builder(activity, this, this)
                            .SetScopes(scopesList.ToArray())
                            .Build();
            }

            if (0 != (clientsToUse & CLIENT_APPSTATE))
            {
                appStateClient = new AppStateClient.Builder(activity, this, this)
                                 .SetScopes(scopesList.ToArray())
                                 .Create();
            }
        }
        internal GameHelperManager(AndroidClient client) {
            mAndroidClient = client;
            Logger.d("Setting up GameHelperManager.");

            // create GameHelper
            Logger.d("GHM creating GameHelper.");
            mGameHelper = new AndroidJavaObject(GameHelperClass, mAndroidClient.GetActivity());
            if (mGameHelper == null) {
                throw new System.Exception("Failed to create GameHelper.");
            }

            // set up the GameHelper
            Logger.d("GHM setting up GameHelper.");
            mGameHelper.Call("enableDebugLog", Logger.DebugLogEnabled, "GameHelper");
            int flags = mGameHelper.GetStatic<int>("CLIENT_ALL");
            Logger.d("GHM client request flags: " + flags);
            GameHelperListener listenerProxy = new GameHelperListener(this, ORIGIN_MAIN_ACTIVITY);
            Logger.d("GHM calling GameHelper.setRequestedClients, " + flags);
            mGameHelper.Call("setRequestedClients", flags);
            Logger.d("GHM calling GameHelper.setup");
            mGameHelper.Call("setup", listenerProxy);

            // set up callbacks so we're informed of pause/unpause events
            PlayGamesHelperObject.SetPauseCallback((bool paused) => {
                if (paused) {
                    OnPause();
                } else {
                    OnResume();
                }
            });

            // start silent auth
            Logger.d("GHM calling GameHelper.onStart to try silent auth.");
            mConnectionState = ConnectionState.Connecting;
            mGameHelper.Call("onStart", mAndroidClient.GetActivity());
        }
        internal GameHelperManager(AndroidClient client)
        {
            mAndroidClient = client;
            Logger.d("Setting up GameHelperManager.");

            // create GameHelper
            Logger.d("GHM creating GameHelper.");
            int flags = JavaConsts.GAMEHELPER_CLIENT_ALL;

            Logger.d("GHM calling GameHelper constructor with flags=" + flags);
            mGameHelper = new AndroidJavaObject(GameHelperClass, mAndroidClient.GetActivity(),
                                                flags);
            if (mGameHelper == null)
            {
                throw new System.Exception("Failed to create GameHelper.");
            }

            // set up the GameHelper
            Logger.d("GHM setting up GameHelper.");
            mGameHelper.Call("enableDebugLog", Logger.DebugLogEnabled, "GameHelper");


            GameHelperListener listenerProxy = new GameHelperListener(this, ORIGIN_MAIN_ACTIVITY);


            // IMPORTANT: we need to tweak the default behavior of GameHelper because
            // it should never attempt to automatically start the
            // sign in flow, because this must be done by the SignInActivity! This
            // is why we call setMaxAutoSignInAttempts(0). This is important because if THIS
            // GameHelper were to attempt the sign-in flow, nothing would work, because
            // it needs onActivityResult to be hooked up, and we have no way to access
            // onActivityResult on the Unity player activity. This is why we use a separate
            // Activity for the sign in flow.

            Logger.d("GHM Setting GameHelper options.");
            mGameHelper.Call("setMaxAutoSignInAttempts", 0);
            AndroidJavaClass  gameOptionsClass = JavaUtil.GetGmsClass("games.Games$GamesOptions");
            AndroidJavaObject builder          = gameOptionsClass.CallStatic <AndroidJavaObject>("builder");
            AndroidJavaObject tmp = builder.Call <AndroidJavaObject>("setSdkVariant",
                                                                     JavaConsts.SDK_VARIANT);
            AndroidJavaObject options = builder.Call <AndroidJavaObject>("build");

            mGameHelper.Call("setGamesApiOptions", options);
            options.Dispose();
            options = null;
            tmp.Dispose();
            tmp = null;
            builder.Dispose();
            builder = null;

            Logger.d("GHM calling GameHelper.setup");
            mGameHelper.Call("setup", listenerProxy);
            Logger.d("GHM: GameHelper setup done.");

            // set up callbacks so we're informed of pause/unpause events
            Logger.d("GHM Setting up lifecycle.");
            PlayGamesHelperObject.SetPauseCallback((bool paused) => {
                if (paused)
                {
                    OnPause();
                }
                else
                {
                    OnResume();
                }
            });

            // start initial auth
            Logger.d("GHM calling GameHelper.onStart to try initial auth.");
            mConnectionState = ConnectionState.Connecting;
            mGameHelper.Call("onStart", mAndroidClient.GetActivity());
        }
        public void Setup(GameHelperListener listener, int clientsToUse)
        {
            this.listener = listener;
            requestClients = clientsToUse;

            List<string> scopesList = new List<string>();
            if (0 != (clientsToUse & CLIENT_GAMES))
            {
                scopesList.Add(Scopes.Games);
            }
            if (0 != (clientsToUse & CLIENT_PLUS))
            {
                scopesList.Add(Scopes.PlusLogin);
            }
            if (0 != (clientsToUse & CLIENT_APPSTATE))
            {
                scopesList.Add(Scopes.AppState);
            }

            if (0 != (clientsToUse & CLIENT_GAMES))
            {
                gamesClient = new GamesClient.Builder(activity, this, this)
                .SetGravityForPopups((int)(GravityFlags.Top | GravityFlags.CenterHorizontal))
                .SetScopes(scopesList.ToArray())
                .Create();
            }

            if (0 != (clientsToUse & CLIENT_PLUS))
            {
                plusCient = new PlusClient.Builder(activity, this, this)
                .SetScopes(scopesList.ToArray())
                .Build();
            }

            if (0 != (clientsToUse & CLIENT_APPSTATE))
            {
                appStateClient = new AppStateClient.Builder(activity, this, this)
                .SetScopes(scopesList.ToArray())
                .Create();
            }
        }
 public void Setup(GameHelperListener listener)
 {
     Setup(listener, CLIENT_GAMES);
 }
 public void Setup(GameHelperListener listener)
 {
     Setup(listener, CLIENT_GAMES);
 }