/// <summary> /// Shows the native achievement user interface, allowing the player to browse achievements. /// </summary> /// <param name="id">Current platform's ID for the leaderboard.</param> /// <param name="internalID">Internal CloudOnce ID, if available.</param> public void ShowOverlay(string id = "", string internalID = "") { if (!AGSPlayerClient.IsSignedIn()) { #if CLOUDONCE_DEBUG Debug.LogWarning("ShowOverlay can only be called after authentication."); #endif return; } if (string.IsNullOrEmpty(id)) { #if CLOUDONCE_DEBUG Debug.Log("Showing leaderboards overlay."); #endif AGSLeaderboardsClient.ShowLeaderboardsOverlay(); } else { #if CLOUDONCE_DEBUG Debug.Log(string.IsNullOrEmpty(internalID) ? string.Format("Showing {0} leaderboard overlay.", id) : string.Format("Showing {0} ({1}) leaderboard overlay.", internalID, id)); #endif AGSLeaderboardsClient.ShowLeaderboardsOverlay(id); } }
public void UpdateWhisperScoresAndLeaderboards(string PackName, string LevelName, GameType gameType, float currentScore) { //Obtain current Level info (scores) SyncableLevelScore slevel = WhisperPlayerScores.Instance.GetSyncLevelScore(PackName, LevelName, gameType); if (slevel == null) { Debug.Log("Something went wrong, no puede ser nulo, revisar"); return; } //Si el score que viene de parametro para ese nivel en ese modo en ese pack, entonces actualizar // el score de ese level en el GameDataMap de whisper sync. if (slevel != null && currentScore > slevel.score.BestScore.AsInt()) { Debug.Log("Deberia registrar el score"); slevel.score.BestScore.Set(currentScore); // Revisar si estoy logueado para poder hacer update de leaderboards if (AGSPlayerClient.IsSignedIn()) { // Update all pack leaderboards foreach (var packName in Globals.Constants.PackNameArray) { string packleaderboard = Managers.GameData.GetLeaderBoardName(packName); int packscore = WhisperPlayerScores.Instance.GetPackScore(packName); Managers.GameCircleAmazon.SubmitScoreToLeaderboard(packleaderboard, packscore); } int globalscore = WhisperPlayerScores.Instance.GetGlobalScore(); Managers.GameCircleAmazon.SubmitScoreToLeaderboard(Globals.Constants.LeaderBoardGlobal, globalscore); } } }
/// <summary> /// Unlocks an achievement. /// </summary> /// <param name="id">Current platform's ID for the achievement.</param> /// <param name="onComplete"> /// Callback that will be called to report the result of the operation: <c>true</c> on success, <c>false</c> otherwise. /// If <c>false</c>, an error message will be included in the callback. /// </param> /// <param name="internalID">Internal CloudOnce ID, if available.</param> public void Unlock(string id, Action <CloudRequestResult <bool> > onComplete, string internalID = "") { if (string.IsNullOrEmpty(id)) { ReportError("Can't unlock achievement. Supplied ID is null or empty!", onComplete); return; } if (!AGSPlayerClient.IsSignedIn()) { var authenticationError = string.IsNullOrEmpty(internalID) ? string.Format("Can't unlock {0}. UnlockAchievement can only be called after authentication.", id) : string.Format("Can't unlock {0} ({1}). Unlock can only be called after authentication.", internalID, id); ReportError(authenticationError, onComplete); return; } Action <AGSUpdateAchievementResponse> callback = null; callback = response => { OnReportCompleted(response, onComplete, unlockAction, id, internalID); AGSAchievementsClient.UpdateAchievementCompleted -= callback; }; AGSAchievementsClient.UpdateAchievementCompleted += callback; AGSAchievementsClient.UpdateAchievementProgress(id, 100f); }
/// <summary> /// Reports a score to a leaderboard. /// </summary> /// <param name="id">Current platform's ID for the leaderboard.</param> /// <param name="score">The score to submit.</param> /// <param name="onComplete"> /// Callback that will be called to report the result of the operation. /// If unsuccessful, an error message will be included in the callback. /// </param> /// <param name="internalID">Internal CloudOnce ID, if available.</param> public void SubmitScore( string id, long score, Action <CloudRequestResult <bool> > onComplete, string internalID = "") { if (string.IsNullOrEmpty(id)) { var errorMessage = string.Format( "Can't submit score to {0} leaderboard. Platform ID is null or empty!", internalID); ReportError(errorMessage, onComplete); return; } if (!AGSPlayerClient.IsSignedIn()) { const string errorMessage = "Can't submit score to leaderboard {0} ({1})." + " SubmitScore can only be called after authentication."; ReportError(string.Format(errorMessage, internalID, id), onComplete); return; } Action <AGSSubmitScoreResponse> callback = null; callback = response => { OnSubmitScoreCompleted(response, score, onComplete, id, internalID); AGSLeaderboardsClient.SubmitScoreCompleted -= callback; }; AGSLeaderboardsClient.SubmitScoreCompleted += callback; AGSLeaderboardsClient.SubmitScore(id, score); }
private void Start() { if (AGSClient.IsServiceReady() && AGSPlayerClient.IsSignedIn()) { if (Managers.GameCircleAmazon.achievementList == null) { Managers.GameCircleAmazon.RequestAchievements(); } } }
public void RequestAchievements() { if (AGSPlayerClient.IsSignedIn() == false) { return; } // subscribe to the events to receive the achievement list. SubscribeToAchievementRequestEvents(); // request the achievement list from the GameCircle plugin. AGSAchievementsClient.RequestAchievements(); }
void Update() { if (AGSPlayerClient.IsSignedIn()) { Info.text = "You are signed in!!!"; } else { Info.text = "Not signed in :("; } }
/// <summary> /// Draws the GameCircle Player Menu. Note that this must be called from an OnGUI function. /// </summary> public override void DrawMenu() { // Once the Status string is not null, player retrieval has begun. // This button begins the player retrieval process. if (GUILayout.Button(playerRetrieveButtonLabel)) { RequestLocalPlayerData(); } if (!string.IsNullOrEmpty(playerStatus)) { AmazonGUIHelpers.CenteredLabel(playerStatus); // If there is a status / error message, display it. if (!string.IsNullOrEmpty(playerStatusMessage)) { AmazonGUIHelpers.CenteredLabel(playerStatusMessage); } // player has been received, display it. if (null != player) { // When the player information is null (for guest accounts), // displaying "null" looks nicer than an empty string string playerId = !string.IsNullOrEmpty(player.playerId) ? player.playerId : nullAsString; string alias = !string.IsNullOrEmpty(player.alias) ? player.alias : nullAsString; string avatarUrl = !string.IsNullOrEmpty(player.avatarUrl) ? player.avatarUrl : nullAsString; AmazonGUIHelpers.CenteredLabel(string.Format(playerLabel, playerId, alias, avatarUrl)); } } AmazonGUIHelpers.CenteredLabel(string.Format(isSignedInLabel, AGSPlayerClient.IsSignedIn() ? "true" : "false")); // Always listen for signed in state change events. if (!haveSubscribedToSignedInStateChangeEvents) { AGSPlayerClient.OnSignedInStateChangedEvent += OnSignedInStateChanged; haveSubscribedToSignedInStateChangeEvents = true; } // If a signed in state change event has happened, display when it happened. if (haveGotStateChangeEvent && lastSignInStateChangeEvent != null) { double timeElapsed = (System.DateTime.Now - lastSignInStateChangeEvent.Value).TotalSeconds; if (signedInStateChange) { AmazonGUIHelpers.CenteredLabel(string.Format(signedInEventLabel, timeElapsed)); } else { AmazonGUIHelpers.CenteredLabel(string.Format(signedOutEventLabel, timeElapsed)); } } }
/// <summary> /// Shows the native achievement user interface, allowing the player to browse achievements. /// </summary> public void ShowOverlay() { if (!AGSPlayerClient.IsSignedIn()) { #if CLOUDONCE_DEBUG UnityEngine.Debug.LogWarning("ShowOverlay can only be called after authentication."); #endif return; } #if CLOUDONCE_DEBUG UnityEngine.Debug.Log("Showing achievements overlay."); #endif AGSAchievementsClient.ShowAchievementsOverlay(); }
private static void UpdateAchievementsData() { AGSAchievementsClient.RequestAchievementsCompleted -= OnRequestAchievementsCompleted; AGSAchievementsClient.RequestAchievementsCompleted += OnRequestAchievementsCompleted; if (!AGSPlayerClient.IsSignedIn()) { #if CO_DEBUG Debug.LogWarning("AGSAchievementsClient.RequestAchievements(); can only be called after authentication."); #endif return; } AGSAchievementsClient.RequestAchievements(); }
/// <summary> /// Clears all cloud variables currently stored in the cloud. /// </summary> private static void DeleteCloudData() { #if !UNITY_EDITOR && UNITY_ANDROID #if CLOUDONCE_AMAZON if (AGSClient.IsServiceReady()) { using (var dataMap = AGSWhispersyncClient.GetGameData()) { using (var developerString = dataMap.getDeveloperString(DevStringKey)) { developerString.setValue(string.Empty); if (AGSPlayerClient.IsSignedIn()) { AGSWhispersyncClient.Synchronize(); } else { AGSWhispersyncClient.Flush(); } } } } #elif CLOUDONCE_GOOGLE if (GooglePlayGamesCloudProvider.Instance.IsGpgsInitialized && PlayGamesPlatform.Instance.IsAuthenticated()) { PlayGamesPlatform.Instance.SavedGame.OpenWithAutomaticConflictResolution( "GameData", DataSource.ReadCacheOrNetwork, ConflictResolutionStrategy.UseLongestPlaytime, (status, metadata) => { if (status == SavedGameRequestStatus.Success) { PlayGamesPlatform.Instance.SavedGame.Delete(metadata); } }); } #endif #elif !UNITY_EDITOR && UNITY_IOS iCloudBridge.DeleteString(DevStringKey); #endif PlayerPrefs.DeleteKey(DevStringKey); PlayerPrefs.Save(); }
public void UpdateAchievements() { if (AGSClient.IsServiceReady() && AGSPlayerClient.IsSignedIn()) { if (achievementList != null) { foreach (AGSAchievement agsAchievement in achievementList) { if (agsAchievement.isUnlocked == false) { Debug.Log("Achievement no esta lock" + agsAchievement.id); float progress = Managers.Achievements.AchievementProgress(agsAchievement.id); if (progress > 0) { SubmitAchievement(agsAchievement.id, progress); } } } } else // La lista de achievements no se cargo, tratar de cargarla entonces { } } }
/// <summary> /// Callback when GameCircle is initialized and ready to use. /// </summary> private void ServiceReadyHandler() { initializationStatus = EInitializationStatus.Ready; Debug.Log("Dentro ServiceREadyHandler"); if (AGSPlayerClient.IsSignedIn()) { if (player == null) { Debug.Log("Dentro service, Request achievements"); WhisperPlayerScores.Instance.SynchronizeScores(); RequestLocalPlayerData(); } } // Once the callback is received, these events do not need to be subscribed to. UnsubscribeFromGameCircleInitializationEvents(); // Tell the GameCircle plugin the popup information set here. // Calling this after GameCircle initialization is safest. AGSClient.SetPopUpEnabled(enablePopups); AGSClient.SetPopUpLocation(toastLocation); }
public bool IsPlayerSignedIn() { return(AGSPlayerClient.IsSignedIn()); }
/// <summary> /// Saves all cloud variables, to both disk and cloud. /// If <see cref="Cloud.CloudSaveEnabled"/> is <c>false</c>, it will only save to disk. /// Skips saving if no variables have been changed. /// </summary> public void Save() { if (saveInitialized) { return; } saveInitialized = true; DataManager.SaveToDisk(); if (!AmazonCloudProvider.Instance.CloudSaveInitialized || !Cloud.CloudSaveEnabled) { #if CO_DEBUG Debug.LogWarning(!AmazonCloudProvider.Instance.CloudSaveInitialized ? "Cloud Save has not been initialized, skipping upload and only saving to disk." : "Cloud Save is currently disabled, skipping upload and only saving to disk."); #endif saveInitialized = false; cloudOnceEvents.RaiseOnCloudSaveComplete(false); return; } if (DataManager.IsLocalDataDirty) { if (AGSClient.IsServiceReady()) { #if CO_DEBUG Debug.Log("Saving cloud data"); #endif using (var dataMap = AGSWhispersyncClient.GetGameData()) { using (var developerString = dataMap.getDeveloperString(DataManager.DevStringKey)) { developerString.setValue(DataManager.SerializeLocalData().ToBase64String()); if (AGSPlayerClient.IsSignedIn()) { AGSWhispersyncClient.Synchronize(); } else { AGSWhispersyncClient.Flush(); } saveInitialized = false; DataManager.IsLocalDataDirty = false; cloudOnceEvents.RaiseOnCloudSaveComplete(true); } } } else { saveInitialized = false; Debug.LogWarning("Attempted to save cloud data, but the AGS service is not ready."); cloudOnceEvents.RaiseOnCloudSaveComplete(false); } } else { #if CO_DEBUG Debug.Log("Save called, but no data has changed since last save."); #endif saveInitialized = false; cloudOnceEvents.RaiseOnCloudSaveComplete(false); } }