|
|
@ -31,9 +31,9 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
public AudioClip AchievedSound;
|
|
|
|
public AudioClip AchievedSound;
|
|
|
|
[Tooltip("The sound which plays when a progress update is displayed to a user. Sounds are only played when Display Achievements is true.")]
|
|
|
|
[Tooltip("The sound which plays when a progress update is displayed to a user. Sounds are only played when Display Achievements is true.")]
|
|
|
|
public AudioClip ProgressMadeSound;
|
|
|
|
public AudioClip ProgressMadeSound;
|
|
|
|
|
|
|
|
|
|
|
|
private AudioSource AudioSource;
|
|
|
|
private AudioSource AudioSource;
|
|
|
|
|
|
|
|
|
|
|
|
[SerializeField] public List<AchievementState> States = new List<AchievementState>(); //List of achievement states (achieved, progress and last notification)
|
|
|
|
[SerializeField] public List<AchievementState> States = new List<AchievementState>(); //List of achievement states (achieved, progress and last notification)
|
|
|
|
[SerializeField] public List<AchievementInfromation> AchievementList = new List<AchievementInfromation>(); //List of all available achievements
|
|
|
|
[SerializeField] public List<AchievementInfromation> AchievementList = new List<AchievementInfromation>(); //List of all available achievements
|
|
|
|
|
|
|
|
|
|
|
@ -45,6 +45,7 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
public static AchievementManager instance = null; //Singleton Instance
|
|
|
|
public static AchievementManager instance = null; //Singleton Instance
|
|
|
|
public AchievenmentStack Stack;
|
|
|
|
public AchievenmentStack Stack;
|
|
|
|
public Button ClaimRewardButton;
|
|
|
|
public Button ClaimRewardButton;
|
|
|
|
|
|
|
|
public AchievenmentListIngame achievementListIngame;
|
|
|
|
|
|
|
|
|
|
|
|
void Awake()
|
|
|
|
void Awake()
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -62,9 +63,9 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
LoadAchievementState();
|
|
|
|
LoadAchievementState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void PlaySound (AudioClip Sound)
|
|
|
|
private void PlaySound(AudioClip Sound)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(AudioSource != null)
|
|
|
|
if (AudioSource != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
AudioSource.clip = Sound;
|
|
|
|
AudioSource.clip = Sound;
|
|
|
|
AudioSource.Play();
|
|
|
|
AudioSource.Play();
|
|
|
@ -95,8 +96,8 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
public int GetAchievedCount()
|
|
|
|
public int GetAchievedCount()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int Count = (from AchievementState i in States
|
|
|
|
int Count = (from AchievementState i in States
|
|
|
|
where i.Achieved == true
|
|
|
|
where i.Achieved == true
|
|
|
|
select i).Count();
|
|
|
|
select i).Count();
|
|
|
|
return Count;
|
|
|
|
return Count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
@ -104,7 +105,7 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public float GetAchievedPercentage()
|
|
|
|
public float GetAchievedPercentage()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(States.Count == 0)
|
|
|
|
if (States.Count == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -137,18 +138,10 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
float ct = 0;
|
|
|
|
float ct = 0;
|
|
|
|
float nt;
|
|
|
|
float nt;
|
|
|
|
float tot = animTime;
|
|
|
|
float tot = animTime;
|
|
|
|
Text coinTxt=null;
|
|
|
|
Text coinTxt = null;
|
|
|
|
if(FindAnyObjectByType<HomeScene>()!=null)
|
|
|
|
HomeScene homeScene = FindAnyObjectByType<HomeScene>();
|
|
|
|
{
|
|
|
|
coinTxt = homeScene.coinLbl;
|
|
|
|
coinTxt = FindAnyObjectByType<HomeScene>().coinLbl;
|
|
|
|
coinTxt.transform.DOShakePosition(1f);
|
|
|
|
coinTxt.transform.DOShakePosition(0.5f);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(FindAnyObjectByType<GameScene>()!=null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
coinTxt = FindAnyObjectByType<GameScene>().coinLbl;
|
|
|
|
|
|
|
|
coinTxt.transform.DOShakePosition(0.5f);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//coinTxt.transform.DOShakePosition(0.5f);
|
|
|
|
//coinTxt.transform.DOShakePosition(0.5f);
|
|
|
|
// coinTxt.GetComponent<Animation>().Play("textShake");
|
|
|
|
// coinTxt.GetComponent<Animation>().Play("textShake");
|
|
|
|
while (ct < tot)
|
|
|
|
while (ct < tot)
|
|
|
@ -166,19 +159,37 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
/// Fully unlocks a progression or goal achievement.
|
|
|
|
/// Fully unlocks a progression or goal achievement.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="Index">The index of the achievement to be unlocked</param>
|
|
|
|
/// <param name="Index">The index of the achievement to be unlocked</param>
|
|
|
|
|
|
|
|
public void ButtonSetterForUnlockedAcheivement(int index)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Debug.Log("ButtonSetterForUnlockedAcheivement");
|
|
|
|
|
|
|
|
int numOfCoins = AchievementList[index].TotalCoinReward;
|
|
|
|
|
|
|
|
//int numOfCoins = AchievementList[index].CoinRewards[AchievementList[index].SubAchievementIndex];
|
|
|
|
|
|
|
|
achievementListIngame.Stack[index].ClaimButton.gameObject.SetActive(true);
|
|
|
|
|
|
|
|
achievementListIngame.Stack[index].ClaimButton.onClick.AddListener(() => AddCoins(numOfCoins));
|
|
|
|
|
|
|
|
achievementListIngame.Stack[index].CompleteToClaimButton.SetActive(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
public void Unlock(int Index)
|
|
|
|
public void Unlock(int Index)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!States[Index].Achieved)
|
|
|
|
if (!States[Index].Achieved)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int numOfCoins = AchievementList[Index].CoinRewards[AchievementList[Index].SubAchievementIndex];
|
|
|
|
//ButtonSetterForUnlockedAcheivement(Index);
|
|
|
|
ClaimRewardButton.onClick.AddListener(() => AddCoins(numOfCoins));
|
|
|
|
|
|
|
|
|
|
|
|
//ClaimRewardButton.onClick.AddListener(() => AddCoins(numOfCoins));
|
|
|
|
// Set current progress to the achievement's progress goal
|
|
|
|
// Set current progress to the achievement's progress goal
|
|
|
|
States[Index].Progress = AchievementList[Index].ProgressGoal;
|
|
|
|
States[Index].Progress = AchievementList[Index].ProgressGoal;
|
|
|
|
|
|
|
|
|
|
|
|
var achievementInfromation = AchievementList[Index];
|
|
|
|
var achievementInfromation = AchievementList[Index];
|
|
|
|
|
|
|
|
States[Index].LastProgressGoal = achievementInfromation.ProgressGoal;
|
|
|
|
|
|
|
|
PlayerPrefs.SetInt("UIAchievement" + Index + "Claimable", 1);
|
|
|
|
|
|
|
|
int numOfPrevCoins = PlayerPrefs.GetInt("TotalCoinsForReward" + Index, 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int subAchievementIndex = PlayerPrefs.GetInt("subAchievementIndex" + Index, 0);
|
|
|
|
|
|
|
|
Debug.Log("SubAchievementIndex for " + Index + ": " + subAchievementIndex);
|
|
|
|
|
|
|
|
PlayerPrefs.SetInt("TotalCoinsForReward" + Index, numOfPrevCoins + achievementInfromation.CoinRewards[Mathf.Clamp(subAchievementIndex,0, achievementInfromation.CoinRewards.Count-1)]);
|
|
|
|
|
|
|
|
subAchievementIndex++;
|
|
|
|
|
|
|
|
PlayerPrefs.SetInt("subAchievementIndex" + Index, subAchievementIndex);
|
|
|
|
|
|
|
|
|
|
|
|
achievementInfromation.ProgressGoal += 5;
|
|
|
|
achievementInfromation.ProgressGoal += 5;
|
|
|
|
States[Index].LastProgressGoal = achievementInfromation.ProgressGoal;
|
|
|
|
|
|
|
|
// Check if the new progress goal has reached or exceeded 50
|
|
|
|
// Check if the new progress goal has reached or exceeded 50
|
|
|
|
if (AchievementList[Index].ProgressGoal >= 50)
|
|
|
|
if (AchievementList[Index].ProgressGoal >= 50)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -196,12 +207,17 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
bool CompletedAll = (Find == -1 || AchievementList[Find].Key.Equals(FinalAchievementKey));
|
|
|
|
bool CompletedAll = (Find == -1 || AchievementList[Find].Key.Equals(FinalAchievementKey));
|
|
|
|
if (CompletedAll)
|
|
|
|
if (CompletedAll)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
//ButtonSetterForUnlockedAcheivement(Index);
|
|
|
|
Unlock(FinalAchievementKey); // Unlock the final achievement if all others are completed
|
|
|
|
Unlock(FinalAchievementKey); // Unlock the final achievement if all others are completed
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ButtonSetterForUnlockedAcheivement(Index);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Set the progress of an achievement to a specific value.
|
|
|
|
/// Set the progress of an achievement to a specific value.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
@ -218,7 +234,7 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
/// <param name="Progress">Set progress to this value</param>
|
|
|
|
/// <param name="Progress">Set progress to this value</param>
|
|
|
|
public void SetAchievementProgress(int Index, float Progress)
|
|
|
|
public void SetAchievementProgress(int Index, float Progress)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(AchievementList[Index].Progression)
|
|
|
|
if (AchievementList[Index].Progression)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (States[Index].Progress >= AchievementList[Index].ProgressGoal)
|
|
|
|
if (States[Index].Progress >= AchievementList[Index].ProgressGoal)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -228,7 +244,7 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
{
|
|
|
|
{
|
|
|
|
States[Index].Progress = Progress;
|
|
|
|
States[Index].Progress = Progress;
|
|
|
|
DisplayUnlock(Index);
|
|
|
|
DisplayUnlock(Index);
|
|
|
|
AutoSaveStates();
|
|
|
|
AutoSaveStates();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -298,7 +314,7 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
States.Add(new AchievementState());
|
|
|
|
States.Add(new AchievementState());
|
|
|
|
AchievementList[i].ProgressGoal = 5;
|
|
|
|
AchievementList[i].ProgressGoal = 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|