/// <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 }
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(); }