Beispiel #1
0
 /// <summary>
 /// Returns the achievement corresponding to the passed achievement identifier.
 /// </summary>
 /// <returns>
 /// The achievement corresponding to the identifer. <code>null</code> if no such
 /// achievement is found or if the user is not authenticated.
 /// </returns>
 /// <param name="achievementId">
 /// The identifier of the achievement.
 /// </param>
 public Achievement GetAchievement(string achievementId)
 {
     if (!IsAuthenticated())
     {
         Logger.e("GetAchievement can only be called after authentication.");
         return(null);
     }
     return(mClient.GetAchievement(achievementId));
 }
Beispiel #2
0
        /// <summary>
        /// Reports the progress of an achievement (reveal, unlock or increment). This method attempts
        /// to implement the expected behavior of ISocialPlatform.ReportProgress as closely as possible,
        /// as described below. Although this method works with incremental achievements for compatibility
        /// purposes, calling this method for incremental achievements is not recommended,
        /// since the Play Games API exposes incremental achievements in a very different way
        /// than the interface presented by ISocialPlatform.ReportProgress. The implementation of this
        /// method for incremental achievements attempts to produce the correct result, but may be
        /// imprecise. If possible, call <see cref="IncrementAchievement" /> instead.
        /// </summary>
        /// <param name='achievementID'>
        /// The ID of the achievement to unlock, reveal or increment. This can be a raw Google Play
        /// Games achievement ID (alphanumeric string), or an alias that was previously configured
        /// by a call to <see cref="AddIdMapping" />.
        /// </param>
        /// <param name='progress'>
        /// Progress of the achievement. If the achievement is standard (not incremental), then
        /// a progress of 0.0 will reveal the achievement and 100.0 will unlock it. Behavior of other
        /// values is undefined. If the achievement is incremental, then this value is interpreted
        /// as the total percentage of the achievement's progress that the player should have
        /// as a result of this call (regardless of the progress they had before). So if the
        /// player's previous progress was 30% and this call specifies 50.0, the new progress will
        /// be 50% (not 80%).
        /// </param>
        /// <param name='callback'>
        /// Callback that will be called to report the result of the operation: <c>true</c> on
        /// success, <c>false</c> otherwise.
        /// </param>
        public void ReportProgress(string achievementID, double progress, Action <bool> callback)
        {
            if (!IsAuthenticated())
            {
                Logger.e("ReportProgress can only be called after authentication.");
                if (callback != null)
                {
                    callback.Invoke(false);
                }
                return;
            }

            // map ID, if it's in the dictionary
            Logger.d("ReportProgress, " + achievementID + ", " + progress);
            achievementID = MapId(achievementID);

            // if progress is 0.0, we just want to reveal it
            if (progress < 0.000001)
            {
                Logger.d("Progress 0.00 interpreted as request to reveal.");
                mClient.RevealAchievement(achievementID, callback);
                return;
            }

            // figure out if it's a standard or incremental achievement
            bool        isIncremental = false;
            int         curSteps = 0, totalSteps = 0;
            Achievement ach = mClient.GetAchievement(achievementID);

            if (ach == null)
            {
                Logger.w("Unable to locate achievement " + achievementID);
                Logger.w("As a quick fix, assuming it's standard.");
                isIncremental = false;
            }
            else
            {
                isIncremental = ach.IsIncremental;
                curSteps      = ach.CurrentSteps;
                totalSteps    = ach.TotalSteps;
                Logger.d("Achievement is " + (isIncremental ? "INCREMENTAL" : "STANDARD"));
                if (isIncremental)
                {
                    Logger.d("Current steps: " + curSteps + "/" + totalSteps);
                }
            }

            // do the right thing depending on the achievement type
            if (isIncremental)
            {
                // increment it to the target percentage (approximate)
                Logger.d("Progress " + progress +
                         " interpreted as incremental target (approximate).");
                int targetSteps = (int)(progress * totalSteps);
                int numSteps    = targetSteps - curSteps;
                Logger.d("Target steps: " + targetSteps + ", cur steps:" + curSteps);
                Logger.d("Steps to increment: " + numSteps);
                if (numSteps > 0)
                {
                    mClient.IncrementAchievement(achievementID, numSteps, callback);
                }
            }
            else
            {
                // unlock it!
                Logger.d("Progress " + progress + " interpreted as UNLOCK.");
                mClient.UnlockAchievement(achievementID, callback);
            }
        }
        /// <summary>
        /// Reports the progress of an achievement (reveal, unlock or increment). This method attempts
        /// to implement the expected behavior of ISocialPlatform.ReportProgress as closely as possible,
        /// as described below. Although this method works with incremental achievements for compatibility
        /// purposes, calling this method for incremental achievements is not recommended,
        /// since the Play Games API exposes incremental achievements in a very different way
        /// than the interface presented by ISocialPlatform.ReportProgress. The implementation of this
        /// method for incremental achievements attempts to produce the correct result, but may be
        /// imprecise. If possible, call <see cref="IncrementAchievement" /> instead.
        /// </summary>
        /// <param name='achievementID'>
        /// The ID of the achievement to unlock, reveal or increment. This can be a raw Google Play
        /// Games achievement ID (alphanumeric string), or an alias that was previously configured
        /// by a call to <see cref="AddIdMapping" />.
        /// </param>
        /// <param name='progress'>
        /// Progress of the achievement. If the achievement is standard (not incremental), then
        /// a progress of 0.0 will reveal the achievement and 100.0 will unlock it. Behavior of other
        /// values is undefined. If the achievement is incremental, then this value is interpreted
        /// as the total percentage of the achievement's progress that the player should have
        /// as a result of this call (regardless of the progress they had before). So if the
        /// player's previous progress was 30% and this call specifies 50.0, the new progress will
        /// be 50% (not 80%).
        /// </param>
        /// <param name='callback'>
        /// Callback that will be called to report the result of the operation: <c>true</c> on
        /// success, <c>false</c> otherwise.
        /// </param>
        public void ReportProgress(string achievementID, double progress, Action <bool> callback)
        {
            if (!IsAuthenticated())
            {
                Logger.e("ReportProgress can only be called after authentication.");
                if (callback != null)
                {
                    callback.Invoke(false);
                }
                return;
            }

            // map ID, if it's in the dictionary
            Logger.d("ReportProgress, " + achievementID + ", " + progress);
            achievementID = MapId(achievementID);

            // if progress is 0.0, we just want to reveal it
            if (progress < 0.000001)
            {
                Logger.d("Progress 0.00 interpreted as request to reveal.");
                mClient.RevealAchievement(achievementID, callback);
                return;
            }

            // figure out if it's a standard or incremental achievement
            bool        isIncremental = false;
            int         curSteps = 0, totalSteps = 0;
            Achievement ach = mClient.GetAchievement(achievementID);

            if (ach == null)
            {
                Logger.w("Unable to locate achievement " + achievementID);
                Logger.w("As a quick fix, assuming it's standard.");
                isIncremental = false;
            }
            else
            {
                isIncremental = ach.IsIncremental;
                curSteps      = ach.CurrentSteps;
                totalSteps    = ach.TotalSteps;
                Logger.d("Achievement is " + (isIncremental ? "INCREMENTAL" : "STANDARD"));
                if (isIncremental)
                {
                    Logger.d("Current steps: " + curSteps + "/" + totalSteps);
                }
            }

            // do the right thing depending on the achievement type
            if (isIncremental)
            {
                // increment it to the target percentage (approximate)
                Logger.d("Progress " + progress +
                         " interpreted as incremental target (approximate).");
                if (progress >= 0.0 && progress <= 1.0)
                {
                    // in a previous version, incremental progress was reported by using the range [0-1]
                    Logger.w("Progress " + progress + " is less than or equal to 1. You might be trying to use values in the range of [0,1], while values are expected to be within the range [0,100]. If you are using the latter, you can safely ignore this message.");
                }
                int targetSteps = (int)((progress / 100) * totalSteps);
                int numSteps    = targetSteps - curSteps;
                Logger.d("Target steps: " + targetSteps + ", cur steps:" + curSteps);
                Logger.d("Steps to increment: " + numSteps);
                if (numSteps > 0)
                {
                    mClient.IncrementAchievement(achievementID, numSteps, callback);
                }
            }
            else if (progress >= 100)
            {
                // unlock it!
                Logger.d("Progress " + progress + " interpreted as UNLOCK.");
                mClient.UnlockAchievement(achievementID, callback);
            }
            else
            {
                // not enough to unlock
                Logger.d("Progress " + progress + " not enough to unlock non-incremental achievement.");
            }
        }