|
|
|
@ -45,6 +45,7 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
|
public static AchievementManager instance = null; //Singleton Instance
|
|
|
|
|
public AchievenmentStack Stack;
|
|
|
|
|
public Button ClaimRewardButton;
|
|
|
|
|
public AchievenmentListIngame achievementListIngame;
|
|
|
|
|
|
|
|
|
|
void Awake()
|
|
|
|
|
{
|
|
|
|
@ -62,9 +63,9 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
|
LoadAchievementState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void PlaySound (AudioClip Sound)
|
|
|
|
|
private void PlaySound(AudioClip Sound)
|
|
|
|
|
{
|
|
|
|
|
if(AudioSource != null)
|
|
|
|
|
if (AudioSource != null)
|
|
|
|
|
{
|
|
|
|
|
AudioSource.clip = Sound;
|
|
|
|
|
AudioSource.Play();
|
|
|
|
@ -104,7 +105,7 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float GetAchievedPercentage()
|
|
|
|
|
{
|
|
|
|
|
if(States.Count == 0)
|
|
|
|
|
if (States.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -137,18 +138,10 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
|
float ct = 0;
|
|
|
|
|
float nt;
|
|
|
|
|
float tot = animTime;
|
|
|
|
|
Text coinTxt=null;
|
|
|
|
|
if(FindAnyObjectByType<HomeScene>()!=null)
|
|
|
|
|
{
|
|
|
|
|
coinTxt = FindAnyObjectByType<HomeScene>().coinLbl;
|
|
|
|
|
coinTxt.transform.DOShakePosition(0.5f);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if(FindAnyObjectByType<GameScene>()!=null)
|
|
|
|
|
{
|
|
|
|
|
coinTxt = FindAnyObjectByType<GameScene>().coinLbl;
|
|
|
|
|
coinTxt.transform.DOShakePosition(0.5f);
|
|
|
|
|
}
|
|
|
|
|
Text coinTxt = null;
|
|
|
|
|
HomeScene homeScene = FindAnyObjectByType<HomeScene>();
|
|
|
|
|
coinTxt = homeScene.coinLbl;
|
|
|
|
|
coinTxt.transform.DOShakePosition(1f);
|
|
|
|
|
//coinTxt.transform.DOShakePosition(0.5f);
|
|
|
|
|
// coinTxt.GetComponent<Animation>().Play("textShake");
|
|
|
|
|
while (ct < tot)
|
|
|
|
@ -166,19 +159,37 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
|
/// Fully unlocks a progression or goal achievement.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <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)
|
|
|
|
|
{
|
|
|
|
|
if (!States[Index].Achieved)
|
|
|
|
|
{
|
|
|
|
|
int numOfCoins = AchievementList[Index].CoinRewards[AchievementList[Index].SubAchievementIndex];
|
|
|
|
|
ClaimRewardButton.onClick.AddListener(() => AddCoins(numOfCoins));
|
|
|
|
|
//ButtonSetterForUnlockedAcheivement(Index);
|
|
|
|
|
|
|
|
|
|
//ClaimRewardButton.onClick.AddListener(() => AddCoins(numOfCoins));
|
|
|
|
|
// Set current progress to the achievement's progress goal
|
|
|
|
|
States[Index].Progress = AchievementList[Index].ProgressGoal;
|
|
|
|
|
|
|
|
|
|
var achievementInfromation = AchievementList[Index];
|
|
|
|
|
achievementInfromation.ProgressGoal += 5;
|
|
|
|
|
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;
|
|
|
|
|
// Check if the new progress goal has reached or exceeded 50
|
|
|
|
|
if (AchievementList[Index].ProgressGoal >= 50)
|
|
|
|
|
{
|
|
|
|
@ -196,10 +207,15 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
|
bool CompletedAll = (Find == -1 || AchievementList[Find].Key.Equals(FinalAchievementKey));
|
|
|
|
|
if (CompletedAll)
|
|
|
|
|
{
|
|
|
|
|
//ButtonSetterForUnlockedAcheivement(Index);
|
|
|
|
|
Unlock(FinalAchievementKey); // Unlock the final achievement if all others are completed
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ButtonSetterForUnlockedAcheivement(Index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -218,7 +234,7 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
|
/// <param name="Progress">Set progress to this value</param>
|
|
|
|
|
public void SetAchievementProgress(int Index, float Progress)
|
|
|
|
|
{
|
|
|
|
|
if(AchievementList[Index].Progression)
|
|
|
|
|
if (AchievementList[Index].Progression)
|
|
|
|
|
{
|
|
|
|
|
if (States[Index].Progress >= AchievementList[Index].ProgressGoal)
|
|
|
|
|
{
|
|
|
|
|