|
|
|
@ -31,9 +31,9 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
|
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.")]
|
|
|
|
|
public AudioClip ProgressMadeSound;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private AudioSource AudioSource;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[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
|
|
|
|
|
|
|
|
|
@ -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();
|
|
|
|
@ -95,8 +96,8 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
|
public int GetAchievedCount()
|
|
|
|
|
{
|
|
|
|
|
int Count = (from AchievementState i in States
|
|
|
|
|
where i.Achieved == true
|
|
|
|
|
select i).Count();
|
|
|
|
|
where i.Achieved == true
|
|
|
|
|
select i).Count();
|
|
|
|
|
return Count;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
@ -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];
|
|
|
|
|
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;
|
|
|
|
|
States[Index].LastProgressGoal = achievementInfromation.ProgressGoal;
|
|
|
|
|
// Check if the new progress goal has reached or exceeded 50
|
|
|
|
|
if (AchievementList[Index].ProgressGoal >= 50)
|
|
|
|
|
{
|
|
|
|
@ -196,12 +207,17 @@ 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>
|
|
|
|
|
/// Set the progress of an achievement to a specific value.
|
|
|
|
|
/// </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)
|
|
|
|
|
{
|
|
|
|
@ -228,7 +244,7 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
States[Index].Progress = Progress;
|
|
|
|
|
DisplayUnlock(Index);
|
|
|
|
|
AutoSaveStates();
|
|
|
|
|
AutoSaveStates();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -298,7 +314,7 @@ public class AchievementManager : MonoBehaviour
|
|
|
|
|
States.Add(new AchievementState());
|
|
|
|
|
AchievementList[i].ProgressGoal = 5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|