Added Achievement Progression

dev-hazim
Hazim Bin Ijaz 4 weeks ago
parent 5729b9c842
commit 983b382973

@ -191,6 +191,11 @@ public class AchievementManagerEditor : Editor
EditorGUILayout.PropertyField(Achievement.FindPropertyRelative("Spoiler"));
EditorGUILayout.PropertyField(Achievement.FindPropertyRelative("Progression"));
EditorGUILayout.PropertyField(Achievement.FindPropertyRelative("isRecursive"));
if (Achievement.FindPropertyRelative("isRecursive").boolValue)
{
EditorGUILayout.PropertyField(Achievement.FindPropertyRelative("recursiveAddition"));
}
if (Achievement.FindPropertyRelative("Progression").boolValue)
{
EditorGUILayout.PropertyField(Achievement.FindPropertyRelative("ProgressGoal"));

@ -124,22 +124,55 @@ public class AchievementManager : MonoBehaviour
{
if (!States[Index].Achieved)
{
// Set current progress to the achievement's progress goal
States[Index].Progress = AchievementList[Index].ProgressGoal;
States[Index].Achieved = true;
DisplayUnlock(Index);
AutoSaveStates();
if(UseFinalAchievement)
// Check if the achievement is recursive
if (AchievementList[Index].isRecursive)
{
// Update the current achievement's progress goal
var achievementInfromation = AchievementList[Index];
achievementInfromation.ProgressGoal += AchievementList[Index].recursiveAddition;
// 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
}
else
{
// Reset progress for the next goal
States[Index].Progress = 0;
}
// Notify the reward system about the achievement modification
// NotifyRewardSystem(Index); // Implement this method to handle rewards
}
else
{
// For non-recursive achievements, mark as achieved directly
States[Index].Achieved = true; // Mark as achieved
DisplayUnlock(Index); // Display achievement notification
}
// Save the updated states
AutoSaveStates(); // Save states automatically if enabled
// Check for final achievement
if (UseFinalAchievement)
{
int Find = States.FindIndex(x => !x.Achieved);
bool CompletedAll = (Find == -1 || AchievementList[Find].Key.Equals(FinalAchievementKey));
if (CompletedAll)
{
Unlock(FinalAchievementKey);
Unlock(FinalAchievementKey); // Unlock the final achievement if all others are completed
}
}
}
}
/// <summary>
/// Set the progress of an achievement to a specific value.
/// </summary>
@ -200,6 +233,18 @@ public class AchievementManager : MonoBehaviour
}
}
}
public AchievementState GetAchievementState(string key)
{
return States[FindAchievementIndex(key)];
}
public AchievementInfromation GetAchivementFromKey(string key)
{
return AchievementList[FindAchievementIndex(key)];
}
#endregion
#region Saving and Loading
@ -211,29 +256,32 @@ public class AchievementManager : MonoBehaviour
for (int i = 0; i < States.Count; i++)
{
PlayerPrefs.SetString("AchievementState_" + i, JsonUtility.ToJson(States[i]));
PlayerPrefs.SetString("AchievementInfo_" + i, JsonUtility.ToJson(AchievementList[i]));
}
PlayerPrefs.Save();
PlayerPrefs.Save(); // Ensure data is saved
}
/// <summary>
/// Loads all progress and achievement states from player prefs. This function is automatically called if the Auto Load setting is set to true.
/// </summary>
public void LoadAchievementState()
{
AchievementState NewState;
States.Clear();
AchievementList.Clear(); // Clear existing data
for (int i = 0; i < AchievementList.Count; i++)
int i = 0; // Counter for achievement index
while (PlayerPrefs.HasKey("AchievementState_" + i))
{
//Ensure that new project get default values
if (PlayerPrefs.HasKey("AchievementState_" + i))
{
NewState = JsonUtility.FromJson<AchievementState>(PlayerPrefs.GetString("AchievementState_" + i));
States.Add(NewState);
}
else { States.Add(new AchievementState()); }
AchievementState loadedState = JsonUtility.FromJson<AchievementState>(PlayerPrefs.GetString("AchievementState_" + i));
States.Add(loadedState);
AchievementInfromation loadedInfo = JsonUtility.FromJson<AchievementInfromation>(PlayerPrefs.GetString("AchievementInfo_" + i));
AchievementList.Add(loadedInfo);
i++;
}
}
/// <summary>
/// Clears all saved progress and achieved states.
/// </summary>
@ -243,6 +291,7 @@ public class AchievementManager : MonoBehaviour
for (int i = 0; i < AchievementList.Count; i++)
{
PlayerPrefs.DeleteKey("AchievementState_" + i);
PlayerPrefs.DeleteKey("AchievementInfo_" + i);
States.Add(new AchievementState());
}
SaveAchievementState();
@ -255,7 +304,12 @@ public class AchievementManager : MonoBehaviour
/// <param name="Key">Key of achievevment</param>
private int FindAchievementIndex(string Key)
{
return AchievementList.FindIndex(x => x.Key.Equals(Key));
int index = AchievementList.FindIndex(x => x.Key.Equals(Key));
if (!States[index].Achieved)
{
return index;
}
return -1;
}
/// <summary>
/// Test if AutoSave is valid. If true, save list

@ -5,7 +5,7 @@ using UnityEngine;
/// Storesinformation related to a single achievement
/// </summary>
[System.Serializable]
public struct AchievementInfromation
public class AchievementInfromation
{
[Tooltip("Name used to unlock/set achievement progress")]
[SerializeField] public string Key;
@ -29,6 +29,8 @@ public struct AchievementInfromation
[SerializeField] public float NotificationFrequency;
[Tooltip("A string which will be displayed with a progress achievement e.g. $, KM, Miles etc")]
[SerializeField] public string ProgressSuffix;
[SerializeField] public bool isRecursive;
[SerializeField] public float recursiveAddition;
}
/// <summary>

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 169f6f7a0c484ca4e94cfd1007189d40
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -38,7 +38,6 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.3708985, g: 0.3783704, b: 0.35722548, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
@ -340,7 +339,7 @@ PrefabInstance:
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: States.Array.size
value: 8
value: 7
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
@ -350,22 +349,27 @@ PrefabInstance:
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.size
value: 8
value: 7
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: States.Array.data[0].Achieved
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: States.Array.data[0].Progress
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: States.Array.data[1].Achieved
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: States.Array.data[1].Progress
value: 5
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
@ -385,177 +389,222 @@ PrefabInstance:
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[3].Key
value: Completed_Advance_Level
value: Completed_Expert_Level
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[4].Key
value: Completed_Expert_Level
value: Completed_Advance_Level
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[5].Key
value: Watched_10_Ads
value: Watched_Ads
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[6].Key
value: Watched_20_Ads
value: Rotated_Pipes
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[7].Key
value: Rotated_Pipe
value:
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[1].Spoiler
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: States.Array.data[0].LastProgressUpdate
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: States.Array.data[1].LastProgressUpdate
value: 4
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[0].Description
value: This Achievement will unlock when user completes 5 easy levels
value:
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[0].DisplayName
value: Complete Easy Levels
value: Completed Easy Level
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[0].Progression
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[0].isRecursive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[1].Description
value: This Achievement will unlock when user completes 5 Medium levels
value:
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[1].DisplayName
value: Complete Medium Levels
value: Completed Medium Level
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[1].Progression
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[1].isRecursive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[2].Description
value: This Achievement will unlock when user completes 5 Hard levels
value:
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[2].DisplayName
value: Complete Hard Levels
value: Completed Hard Level
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[2].Progression
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[2].isRecursive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[3].Description
value: This Achievement will unlock when user completes 5 Advanced levels
value:
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[3].DisplayName
value: Complete Advance Levels
value: Completed Expert Level
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[3].Progression
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[3].isRecursive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[4].Description
value: This Achievement will unlock when user completes 5 Expert levels
value:
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[4].DisplayName
value: Complete Expert Levels
value: Completed Advance Level
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[4].Progression
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[4].isRecursive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[5].Description
value: This Achievement will unlock when user watches 10 ads
value:
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[5].DisplayName
value: Watch 10 Ads
value: Watched Ads
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[5].Progression
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[5].isRecursive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[6].Description
value: This Achievement will unlock when user watches 20 ads
value:
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[6].DisplayName
value: Watch 20 Ads
value: Rotated Pipes
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[6].Progression
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[6].isRecursive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[7].Description
value: This achievement will progress on every pipe rotation
value:
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[7].DisplayName
value: Pipe Rotation
value:
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[7].Progression
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[0].ProgressGoal
value: 5
value: 10
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[1].ProgressGoal
value: 5
value: 10
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[2].ProgressGoal
value: 5
value: 10
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[3].ProgressGoal
value: 5
value: 10
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[4].ProgressGoal
value: 5
value: 10
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
@ -565,7 +614,47 @@ PrefabInstance:
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[6].ProgressGoal
value: 20
value: 10
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[7].ProgressGoal
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[0].recursiveAddition
value: 10
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[1].recursiveAddition
value: 10
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[2].recursiveAddition
value: 10
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[3].recursiveAddition
value: 10
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[4].recursiveAddition
value: 10
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[5].recursiveAddition
value: 10
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[6].recursiveAddition
value: 10
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}

@ -5,12 +5,16 @@ public class GameConstants
public static string LevelCompletedStatsKey = "LevelsCompleted";
public static string NameEnteredCheckKey = "IsNameEntered";
public static string DisplayNameKey = "DisplayName";
#region MyRegion
public static string Ach_CompleteEasyLevelKey = "Completed_Easy_Level";
public static string Ach_CompleteMediumLevelKey = "Completed_Medium_Level";
public static string Ach_CompleteHardLevelKey = "Completed_Hard_Level";
public static string Ach_CompleteExpertLevelKey = "Completed_Expert_Level";
public static string Ach_CompleteAdvanceLevelKey = "Completed_Advance_Level";
public static string Ach_Watched10Ads = "Watched_10_Ads";
public static string Ach_Watched20Ads = "Watched_20_Ads";
public static string Ach_WatchedAds = "Watched_Ads";
public static string Ach_RotatedPipes = "Rotated_Pipes";
#endregion
}

@ -194,7 +194,7 @@ public class GamePlayManager : MonoBehaviour
private IEnumerator RotatePipe(Cell c)
{
AchievementManager.instance.AddAchievementProgress(GameConstants.Ach_RotatedPipes, 1);
// AchievementManager.instance.AddAchievementProgress(GameConstants.Ach_RotatedPipes, 1);
isRotating = true;
if (c != null)
{

@ -104,7 +104,7 @@ public class GameScene : MonoBehaviour
GameManager.Coin += rewardedVideoAmount;
UpdateUI();
Toast.instance.ShowMessage($"You got {rewardedVideoAmount} free coins");
AchievementManager.instance.AddAchievementProgress(GameConstants.Ach_Watched10Ads, 1);
AchievementManager.instance.AddAchievementProgress(GameConstants.Ach_WatchedAds, 1);
}
public bool debugHints = false;

Loading…
Cancel
Save