|
|
|
@ -7,9 +7,6 @@ using System.Collections;
|
|
|
|
|
using TMPro;
|
|
|
|
|
using DG.Tweening;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Controls interactions with the Achievement System
|
|
|
|
|
/// </summary>
|
|
|
|
|
[System.Serializable]
|
|
|
|
|
public class AchievementManager : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
@ -72,27 +69,15 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
# region Miscellaneous
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Does an achievement exist in the list
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="Key">The Key of the achievement to test</param>
|
|
|
|
|
/// <returns>true : if exists. false : does not exist</returns>
|
|
|
|
|
|
|
|
|
|
public bool AchievementExists(string Key)
|
|
|
|
|
{
|
|
|
|
|
return AchievementExists(AchievementList.FindIndex(x => x.Key.Equals(Key)));
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Does an achievement exist in the list
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="Index">The index of the achievement to test</param>
|
|
|
|
|
/// <returns>true : if exists. false : does not exist</returns>
|
|
|
|
|
public bool AchievementExists(int Index)
|
|
|
|
|
{
|
|
|
|
|
return Index <= AchievementList.Count && Index >= 0;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the total number of achievements which have been unlocked.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int GetAchievedCount()
|
|
|
|
|
{
|
|
|
|
|
int Count = (from AchievementState i in States
|
|
|
|
@ -100,9 +85,6 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
|
select i).Count();
|
|
|
|
|
return Count;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the current percentage of unlocked achievements.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float GetAchievedPercentage()
|
|
|
|
|
{
|
|
|
|
|
if (States.Count == 0)
|
|
|
|
@ -114,10 +96,6 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Unlock and Progress
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fully unlocks a progression or goal achievement.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="Key">The Key of the achievement to be unlocked</param>
|
|
|
|
|
public void Unlock(string Key)
|
|
|
|
|
{
|
|
|
|
|
Unlock(FindAchievementIndex(Key));
|
|
|
|
@ -142,8 +120,6 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
|
HomeScene homeScene = FindAnyObjectByType<HomeScene>();
|
|
|
|
|
coinTxt = homeScene.coinLbl;
|
|
|
|
|
coinTxt.transform.DOShakePosition(1f);
|
|
|
|
|
//coinTxt.transform.DOShakePosition(0.5f);
|
|
|
|
|
// coinTxt.GetComponent<Animation>().Play("textShake");
|
|
|
|
|
while (ct < tot)
|
|
|
|
|
{
|
|
|
|
|
ct += Time.deltaTime;
|
|
|
|
@ -152,13 +128,7 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
|
coinTxt.text = ((int)(val)).ToString();
|
|
|
|
|
yield return null;
|
|
|
|
|
}
|
|
|
|
|
//coinTxt.GetComponent<Animation>().Stop();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fully unlocks a progression or goal achievement.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="Index">The index of the achievement to be unlocked</param>
|
|
|
|
|
public void Unlock(int Index)
|
|
|
|
|
{
|
|
|
|
|
if (!States[Index].Achieved)
|
|
|
|
@ -179,42 +149,32 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
achievementInfromation.ProgressGoal += 5;
|
|
|
|
|
// Check if the new progress goal has reached or exceeded 50
|
|
|
|
|
if (AchievementList[Index].ProgressGoal >= 50)
|
|
|
|
|
{
|
|
|
|
|
// Mark achievement as completed
|
|
|
|
|
States[Index].Achieved = true; // Mark as achieved
|
|
|
|
|
States[Index].Progress = AchievementList[Index].ProgressGoal; // Set progress to goal
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AutoSaveStates(); // Save states automatically if enabled
|
|
|
|
|
AutoSaveStates();
|
|
|
|
|
|
|
|
|
|
// Check for final achievement
|
|
|
|
|
if (UseFinalAchievement)
|
|
|
|
|
{
|
|
|
|
|
int Find = States.FindIndex(x => !x.Achieved);
|
|
|
|
|
bool CompletedAll = (Find == -1 || AchievementList[Find].Key.Equals(FinalAchievementKey));
|
|
|
|
|
if (CompletedAll)
|
|
|
|
|
{
|
|
|
|
|
//ButtonSetterForUnlockedAcheivement(Index);
|
|
|
|
|
Unlock(FinalAchievementKey); // Unlock the final achievement if all others are completed
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Set the progress of an achievement to a specific value.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="Key">The Key of the achievement</param>
|
|
|
|
|
/// <param name="Progress">Set progress to this value</param>
|
|
|
|
|
public void SetAchievementProgress(string Key, float Progress)
|
|
|
|
|
{
|
|
|
|
|
SetAchievementProgress(FindAchievementIndex(Key), Progress);
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Set the progress of an achievement to a specific value.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="Index">The index of the achievement</param>
|
|
|
|
|
/// <param name="Progress">Set progress to this value</param>
|
|
|
|
|
public void SetAchievementProgress(int Index, float Progress)
|
|
|
|
@ -233,18 +193,12 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adds the input amount of progress to an achievement. Clamps achievement progress to its max value.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="Key">The Key of the achievement</param>
|
|
|
|
|
/// <param name="Progress">Add this number to progress</param>
|
|
|
|
|
public void AddAchievementProgress(string Key, float Progress)
|
|
|
|
|
{
|
|
|
|
|
AddAchievementProgress(FindAchievementIndex(Key), Progress);
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adds the input amount of progress to an achievement. Clamps achievement progress to its max value.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="Index">The index of the achievement</param>
|
|
|
|
|
/// <param name="Progress">Add this number to progress</param>
|
|
|
|
|
public void AddAchievementProgress(int Index, float Progress)
|
|
|
|
@ -317,17 +271,11 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Find the index of an achievement with a cetain key
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="Key">Key of achievevment</param>
|
|
|
|
|
private int FindAchievementIndex(string Key)
|
|
|
|
|
{
|
|
|
|
|
return AchievementList.FindIndex(x => x.Key.Equals(Key));
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Test if AutoSave is valid. If true, save list
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void AutoSaveStates()
|
|
|
|
|
{
|
|
|
|
|
if (AutoSave)
|
|
|
|
@ -335,9 +283,6 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
|
SaveAchievementState();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Display achievements progress to screen
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="Index">Index of achievement to display</param>
|
|
|
|
|
private void DisplayUnlock(int Index)
|
|
|
|
|
{
|
|
|
|
|