Example #1
0
        /// <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);
        }
Example #2
0
    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);
            }
        }
    }
Example #3
0
        /// <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);
            }
        }
Example #4
0
    public void playerReceived(string json)
    {
        AGSClient.Log("GameCircleManager - playerReceived");

        AGSPlayerClient.
        PlayerReceived(json);
    }
Example #5
0
        /// <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);
        }
 private void Start()
 {
     if (AGSClient.IsServiceReady() && AGSPlayerClient.IsSignedIn())
     {
         if (Managers.GameCircleAmazon.achievementList == null)
         {
             Managers.GameCircleAmazon.RequestAchievements();
         }
     }
 }
Example #7
0
    /// <summary>
    /// Requests the local player data from the GameCircle plugin.
    /// </summary>
    void RequestLocalPlayerData()
    {
        // Need to subscribe to callback messages to receive the player from GameCircle.
        SubscribeToPlayerEvents();
        // Request the player from the GameCircle plugin
        AGSPlayerClient.RequestLocalPlayer();

        // update the menu to show that the retrieval process has begun.
        playerStatus = playerRetrievingLabel;
    }
    void Update()
    {
        if (AGSPlayerClient.IsSignedIn())
        {
            Info.text = "You are signed in!!!";
        }

        else
        {
            Info.text = "Not signed in :(";
        }
    }
Example #9
0
    /// <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));
            }
        }
    }
Example #10
0
    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();
    }
Example #11
0
        /// <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();
        }
Example #12
0
        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();
        }
Example #13
0
 private void OnRequestFriendIdsCompleted(AGSRequestFriendIdsResponse response)
 {
     if (response.IsError())
     {
         Action <bool> callback = simpleCallbacks.ContainsKey(response.userData) ? simpleCallbacks[response.userData] : null;
         if (callback != null)
         {
             callback(false);
         }
         simpleCallbacks.Remove(response.userData);
     }
     else
     {
         AGSPlayerClient.RequestBatchFriends(response.friendIds, response.userData);
     }
 }
Example #14
0
        /// <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();
        }
 /// <summary>
 /// Authenticate the local user with the active Social plugin.
 /// </summary>
 /// <param name='callback'>
 /// Callback.
 /// </param>
 public void Authenticate(System.Action <bool> callback)
 {
     // The Unity Social API implies a heavy connection between
     // initialization of the Social API and the local user.
     // http://docs.unity3d.com/Documentation/Components/net-SocialAPI.html
     // This means that the local player should be available as early as possible.
     callback += (successStatus) => {
         if (successStatus)
         {
             // On a successful initialization of the GameCircle through
             // the Unity Social API, immediately begin the process
             // of retrieving the local player.
             AGSPlayerClient.PlayerReceivedEvent += (player) => {
                 this.player = player;
             };
             AGSPlayerClient.RequestLocalPlayer();
         }
         else
         {
             player = null;
         }
     };
     Social.Active.Authenticate(this, callback);
 }
Example #16
0
 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
         {
         }
     }
 }
Example #17
0
        private void OnSignedInStateChangedEvent(bool signedIn)
        {
            if (signedIn)
            {
#if CLOUDONCE_DEBUG
                Debug.Log("Signed in to Amazon GameCircle.");
#endif
                if (CloudSaveInitialized && cloudSaveEnabled && autoLoadOnSignInEnabled)
                {
                    Cloud.Storage.Load();
                }

                AGSPlayerClient.RequestLocalPlayer();
                UpdateAchievementsData();
            }
            else
            {
#if CLOUDONCE_DEBUG
                Debug.Log("Signed out of Amazon GameCircle.");
#endif
            }

            cloudOnceEvents.RaiseOnSignedInChanged(signedIn);
        }
Example #18
0
    /// <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);
    }
        /// <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);
            }
        }
Example #20
0
 public void onSignedInStateChange(string isSignedIn)
 {
     AGSClient.Log("GameCircleManager - onSignedInStateChange");
     AGSPlayerClient.OnSignedInStateChanged(Boolean.Parse(isSignedIn));
 }
Example #21
0
 public bool IsPlayerSignedIn()
 {
     return(AGSPlayerClient.IsSignedIn());
 }
Example #22
0
 public void RequestLocalPlayer(Action <bool> callback)
 {
     simpleCallbacks.Add(requestID, callback);
     AGSPlayerClient.RequestLocalPlayer(requestID++);
 }
Example #23
0
 public void RequestFriends(Action <bool> callback)
 {
     simpleCallbacks.Add(requestID, callback);
     AGSPlayerClient.RequestFriendIds(requestID++);
 }
Example #24
0
 public void RetrieveLocalPlayer()
 {
             #if AMAZON_CIRCLE_ENABLED
     AGSPlayerClient.RequestLocalPlayer();
             #endif
 }
Example #25
0
 public void onSignedInStateChange(string isSignedIn)
 {
     AGSClient.Log("AGSPlayerClient - OnSignedInStateChanged");
     AGSPlayerClient.OnSignedInStateChanged(bool.Parse(isSignedIn));
 }
Example #26
0
 public void batchFriendsRequestComplete(string json)
 {
     AGSClient.Log("AGSPlayerClient - BatchFriendsRequestComplete");
     AGSPlayerClient.BatchFriendsRequestComplete(json);
 }
Example #27
0
 public void localPlayerFriendRequestComplete(string json)
 {
     AGSClient.Log("AGSPlayerClient - LocalPlayerFriendsComplete");
     AGSPlayerClient.LocalPlayerFriendsComplete(json);
 }
Example #28
0
 public void playerFailed(string json)
 {
     AGSClient.Log("AGSPlayerClient - PlayerFailed");
     AGSPlayerClient.PlayerFailed(json);
 }