Ejemplo n.º 1
0
        /// <summary>
        /// Initializes Google Play Game Services.
        /// </summary>
        /// <param name="activateCloudSave">Whether or not Cloud Saving should be activated.</param>
        /// <param name="autoSignIn">
        /// Whether or not <see cref="SignIn"/> will be called automatically once Google Play Game Services is initialized.
        /// </param>
        /// <param name="autoCloudLoad">
        /// Whether or not cloud data should be loaded automatically if the user is successfully signed in.
        /// Ignored if Cloud Saving is deactivated or the user fails to sign in.
        /// </param>
        public override void Initialize(bool activateCloudSave = true, bool autoSignIn = true, bool autoCloudLoad = true)
        {
            if (initializing)
            {
                return;
            }
#if CLOUDONCE_DEBUG
            Debug.Log("Initializing Google Play Game Services.");
#endif
            initializing = true;

            cloudSaveEnabled = activateCloudSave;

#if CLOUDONCE_DEBUG
            Debug.Log("Saved Games support " + (activateCloudSave ? "enabled." : "disabled."));
#endif
            var config = new PlayGamesClientConfiguration.Builder();
            if (activateCloudSave)
            {
                config.EnableSavedGames();
                CloudSaveInitialized = true;
            }

            PlayGamesPlatform.InitializeInstance(config.Build());

            SubscribeOnAuthenticatedEvent();

#if CLOUDONCE_DEBUG   // Enable/disable logs on the PlayGamesPlatform
            PlayGamesPlatform.DebugLogEnabled = true;
            Debug.Log("PlayGamesPlatform debug logs enabled.");
#else
            PlayGamesPlatform.DebugLogEnabled = false;
            Debug.Log("PlayGamesPlatform debug logs disabled.");
#endif
            IsGpgsInitialized = true;
            if (!IsGuestUserDefault && autoSignIn)
            {
                var onSignedIn = new UnityAction <bool>(arg0 =>
                {
                    cloudOnceEvents.RaiseOnInitializeComplete();
                    initializing = false;
                });
                SignIn(autoCloudLoad, onSignedIn);
            }
            else
            {
                if (IsGuestUserDefault && autoSignIn)
                {
                    Logger.d("Guest user mode active, ignoring auto sign-in. Please call SignIn directly.");
                }

                if (autoCloudLoad)
                {
                    cloudOnceEvents.RaiseOnCloudLoadComplete(false);
                }

                cloudOnceEvents.RaiseOnInitializeComplete();
                initializing = false;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes the service. This is required before any other actions can be done e.g reporting scores.
        /// During the initialization process, a login popup will show up if the user hasn't logged in, otherwise
        /// the process will carry on silently.
        /// Note that on iOS, the login popup will show up automatically when the app gets focus for the first 3 times
        /// while subsequent authentication calls will be ignored.
        /// </summary>
        public static void Init()
        {
            // Authenticate and register a ProcessAuthentication callback
            // This call needs to be made before we can proceed to other calls in the Social API
#if UNITY_IOS
            GameCenterPlatform.ShowDefaultAchievementCompletionBanner(true);
            Social.localUser.Authenticate(ProcessAuthentication);

#if EASY_MOBILE_PRO && !UNITY_EDITOR
            // Register the default GKLocalPlayerListener for invitation delegate if Multiplayer is enabled.
            // EM Pro only.
            if (EM_Settings.GameServices.IsMultiplayerEnabled)
            {
                RegisterDefaultGKLocalPlayerListener();
            }
#endif
#elif UNITY_ANDROID && EM_GPGS
#if EASY_MOBILE_PRO
            PlayGamesClientConfiguration.Builder gpgsConfigBuilder = new PlayGamesClientConfiguration.Builder();

            // Enable Saved Games.
            if (EM_Settings.GameServices.IsSavedGamesEnabled)
            {
                gpgsConfigBuilder.EnableSavedGames();
            }

            // Register an internal invitation delegate and match delegate if Multiplayer is enabled.
            if (EM_Settings.GameServices.IsMultiplayerEnabled)
            {
                gpgsConfigBuilder.WithInvitationDelegate(OnGPGSInvitationReceived);
                gpgsConfigBuilder.WithMatchDelegate(OnGPGSTBMatchReceived);
            }

            // Build the config
            PlayGamesClientConfiguration gpgsConfig = gpgsConfigBuilder.Build();

            // Initialize PlayGamesPlatform
            PlayGamesPlatform.InitializeInstance(gpgsConfig);
#endif

            // Enable logging if required
            PlayGamesPlatform.DebugLogEnabled = EM_Settings.GameServices.GgpsDebugLogEnabled;

            // Set PlayGamesPlatforms as active
            if (Social.Active != PlayGamesPlatform.Instance)
            {
                PlayGamesPlatform.Activate();
            }

            // Now authenticate
            Social.localUser.Authenticate(ProcessAuthentication);
#elif UNITY_ANDROID && !EM_GPGS
            Debug.LogError("SDK missing. Please import Google Play Games plugin for Unity.");
#else
            Debug.Log("Failed to initialize Game Services module: platform not supported.");
#endif
        }
Ejemplo n.º 3
0
    public static void Init(bool saveGame, bool debug = false)
    {
        var config = new PlayGamesClientConfiguration.Builder();

        if (saveGame)
        {
            config.EnableSavedGames();
        }
        if (debug)
        {
            PlayGamesPlatform.DebugLogEnabled = true;
        }
        PlayGamesPlatform.InitializeInstance(config.Build());
        PlayGamesPlatform.Activate();
    }
    /// <summary>
    /// Initializes this instance.
    /// </summary>
    /// <param name="enableSavedGames">if set to <c>true</c> support saving game progress on the cloud.</param>
    public void Initialize(bool enableSavedGames)
    {
        PlayGamesClientConfiguration.Builder config = new PlayGamesClientConfiguration.Builder();
        if (enableSavedGames)
        {
            config.EnableSavedGames();
        }
        // Initialize Play Games
        PlayGamesPlatform.InitializeInstance(config.Build());
        PlayGamesPlatform.DebugLogEnabled = BuildInfo.IsDebugMode;
        // Activate the Google Play Games platform
        PlayGamesPlatform.Activate();

        // Create instances of achievmements and leaderboards assets
        m_achievements = new AchievementInfo();
        m_leaderboards = new LeaderboardInfo();

        // Set the initialized flag
        m_isInitialized = true;
    }
Ejemplo n.º 5
0
    /// <summary>
    /// A method used for cloud saving.
    /// Initializes and logs in to Google Play Games on Android and KeyChain on iOS.
    /// Loads cloud saves after logging in and makes sure locally saved material is the same as in the cloud.
    /// This method is called by a service handler via the LoadResources method.
    /// </summary>
    /// <param name="onSuccess">Callback for success.</param>
    /// <param name="onFail">Callback for failure.</param>
    private void PlatformInitialization(Action onSuccess, Action onFail)
    {
#if UNITY_ANDROID
        PlayGamesClientConfiguration.Builder builder = new PlayGamesClientConfiguration.Builder();
        builder.EnableSavedGames();
        PlayGamesPlatform.InitializeInstance(builder.Build());
        PlayGamesPlatform.Activate();
#endif

        Social.localUser.Authenticate((bool success) =>
        {
            if (success)
            {
                Logger.Log("Logged in");
#if UNITY_ANDROID
                //load Android cloud saves
                var platform = (PlayGamesPlatform)Social.Active;
                //fetches all Android cloud saves
                platform.SavedGame.FetchAllSavedGames(DataSource.ReadCacheOrNetwork,
                                                      OnPlayServicesSavesFetched);
#endif
#if UNITY_IOS
                //load iOS cloud saves
                KeyChain.InitializeKeychain();
                foreach (var saveName in Saves)
                {
                    if (!Saves[saveName.Key].Equals(KeyChain.GetString(saveName.Key)))
                    {
                        Saves[saveName.Key] = KeyChain.GetString(saveName.Key);
                    }
                }
#endif
                onSuccess();
            }
            else
            {
                Logger.LogError("Failed to login");
                onFail();
            }
        });
    }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes the service. This is required before any other actions can be done e.g reporting scores.
        /// During the initialization process, a login popup will show up if the user hasn't logged in, otherwise
        /// the process will carry on silently.
        /// Note that on iOS, the login popup will show up automatically when the app gets focus for the first 3 times
        /// while subsequent authentication calls will be ignored.
        /// </summary>
        public static void Init()
        {
            // Authenticate and register a ProcessAuthentication callback
            // This call needs to be made before we can proceed to other calls in the Social API
            #if UNITY_IOS
            GameCenterPlatform.ShowDefaultAchievementCompletionBanner(true);
            Social.localUser.Authenticate(ProcessAuthentication);
            #elif UNITY_ANDROID && EM_GPGS
            #if EASY_MOBILE_PRO
            PlayGamesClientConfiguration.Builder gpgsConfigBuilder = new PlayGamesClientConfiguration.Builder();

            if (EM_Settings.GameServices.IsSavedGamesEnabled)
            {
                gpgsConfigBuilder.EnableSavedGames();
            }

            // Build the config
            PlayGamesClientConfiguration gpgsConfig = gpgsConfigBuilder.Build();

            // Initialize PlayGamesPlatform
            PlayGamesPlatform.InitializeInstance(gpgsConfig);
            #endif

            // Enable logging if required
            PlayGamesPlatform.DebugLogEnabled = EM_Settings.GameServices.IsGPGSDebug;

            // Set PlayGamesPlatforms as active
            if (Social.Active != PlayGamesPlatform.Instance)
            {
                PlayGamesPlatform.Activate();
            }

            // Now authenticate
            Social.localUser.Authenticate(ProcessAuthentication);
            #elif UNITY_ANDROID && !EM_GPGS
            Debug.LogError("SDK missing. Please import Google Play Games plugin for Unity.");
            #else
            Debug.Log("Failed to initialize Game Services module: platform not supported.");
            #endif
        }
        public void Initialize(bool isEnableSavedGames      = true, bool isRequestEmail    = false,
                               bool isRequestServerAuthCode = false, bool isRequestIdToken = false,
                               InvitationReceivedDelegate invitationReceivedCallback = null,
                               MatchDelegate matchCallback = null)
        {
            if (_isInited)
            {
                Log.Warning(nameof(GooglePlayGameService), "플랫폼은 이미 초기화 되어 있다");
                return;
            }

            _isInited = true;

            Log.Verbose(nameof(GooglePlayGameService), "Initialize");

            var config = new PlayGamesClientConfiguration.Builder();

            // 구글 계정에 게임 저장 가능.
            if (isEnableSavedGames)
            {
                config = config.EnableSavedGames();
            }

            // 게임이 실행되고 있지 않을 때 받은 게임 초대장을 처리하기 위해 Callback 등록.
            if (invitationReceivedCallback != null)
            {
                config = config.WithInvitationDelegate(invitationReceivedCallback);
            }

            // 플레이어의 email 주소를 요청. (동의 여부를 묻는 메시지가 나타난다.)
            if (isRequestEmail)
            {
                config = config.RequestEmail();
            }

            // 게임이 실행되고 있지 않을 때 받은 턴기반 매치 알림에 대한 Callback 등록.
            if (matchCallback != null)
            {
                config = config.WithMatchDelegate(matchCallback);
            }

            // 서버 인증 코드를 생성하여 관련된 백엔드 서버 응용 프로그램에 전달하고 OAuth 토큰과 교환 할수 있도록 요청한다.
            if (isRequestServerAuthCode)
            {
                config = config.RequestServerAuthCode(false);
            }

            // ID 토큰을 생성하도록 요청한다. 이 OAuth 토큰을 사용하여 플레이어를 Firebase와 같은 다른 서비스로 식별 할수 있다.
            if (isRequestIdToken)
            {
                config = config.RequestIdToken();
            }

            PlayGamesPlatform.InitializeInstance(config.Build());
#if BF_DEBUG
            PlayGamesPlatform.DebugLogEnabled = true;
#endif
            // Google Play Games platform 활성화
            PlayGamesPlatform.Activate();
            _savedDataFilename = Application.identifier + "_cloud_savegame";
            IsGuestUser        = PlatformService.GetGuestUser();
            IsPlatformAuth     = PlatformService.GetPlatformAuth();
        }