Achievement optimization

dev-ali-pushnotifications
Ali Sharoz 1 week ago
parent efd902c023
commit ae0ae60ec1

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

@ -4,9 +4,6 @@ using UnityEngine.UI;
using System.Collections.Generic; using System.Collections.Generic;
using System; using System;
/// <summary>
/// Add list of achievements to screen
/// </summary>
public class AchievenmentListIngame : MonoBehaviour public class AchievenmentListIngame : MonoBehaviour
{ {
public GameObject scrollContent; public GameObject scrollContent;
@ -19,11 +16,7 @@ public class AchievenmentListIngame : MonoBehaviour
private bool MenuOpen = false; private bool MenuOpen = false;
[Tooltip("Key used to open UI menu. Set to \"None\" to prevent menu from opening with any key press")] [Tooltip("Key used to open UI menu. Set to \"None\" to prevent menu from opening with any key press")]
// public KeyCode OpenMenuKey; //Key to open in-game menu
/// <summary>
/// Adds all achievements to the UI based on a filter
/// </summary>
/// <param name="Filter">Filter to use (All, Achieved or Unachieved)</param> /// <param name="Filter">Filter to use (All, Achieved or Unachieved)</param>
private void AddAchievements(string Filter) private void AddAchievements(string Filter)
{ {
@ -57,17 +50,11 @@ public class AchievenmentListIngame : MonoBehaviour
UIAchievement.transform.SetParent(scrollContent.transform); UIAchievement.transform.SetParent(scrollContent.transform);
UIAchievement.GetComponent<RectTransform>().localScale = Vector3.one; UIAchievement.GetComponent<RectTransform>().localScale = Vector3.one;
} }
/// <summary>
/// Filter out a set of locked or unlocked achievements
/// </summary>
public void ChangeFilter() public void ChangeFilter()
{ {
AddAchievements(Filter.options[Filter.value].text); AddAchievements(Filter.options[Filter.value].text);
} }
/// <summary>
/// Closes the UI window.
/// </summary>
void Start() void Start()
{ {
AddAchievements("All"); AddAchievements("All");
@ -85,9 +72,6 @@ public class AchievenmentListIngame : MonoBehaviour
MenuOpen = false; MenuOpen = false;
Menu.Close(); Menu.Close();
} }
/// <summary>
/// Opens the UI window.
/// </summary>
public void OpenWindow() public void OpenWindow()
{ {
MenuOpen = true; MenuOpen = true;
@ -114,9 +98,6 @@ public class AchievenmentListIngame : MonoBehaviour
} }
} }
} }
/// <summary>
/// Toggles the state of the UI window open or closed
/// </summary>
public void ToggleWindow() public void ToggleWindow()
{ {
if (MenuOpen) if (MenuOpen)
@ -128,12 +109,4 @@ public class AchievenmentListIngame : MonoBehaviour
OpenWindow(); OpenWindow();
} }
} }
// private void Update()
// {
// if(Input.GetKeyDown(OpenMenuKey))
// {
// ToggleWindow();
// }
// }
} }

@ -3,10 +3,6 @@ using System.Collections.Generic;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
/// <summary>
/// Defines the logic behind a single achievement on the UI
/// </summary>
public class UIAchievement : MonoBehaviour public class UIAchievement : MonoBehaviour
{ {
public TMP_Text Title, Description, Percent; public TMP_Text Title, Description, Percent;
@ -17,9 +13,6 @@ public class UIAchievement : MonoBehaviour
public GameObject CompleteToClaimButton; public GameObject CompleteToClaimButton;
public Button ClaimButton; public Button ClaimButton;
/// <summary>
/// Destroy object after a certain amount of time
/// </summary>
public void StartDeathTimer () public void StartDeathTimer ()
{ {
StartCoroutine(Wait()); StartCoroutine(Wait());
@ -37,11 +30,6 @@ public class UIAchievement : MonoBehaviour
Information.TotalCoinReward = TotalReward; Information.TotalCoinReward = TotalReward;
SafePlayerPrefs.SetInt("TotalRewards"+index, TotalReward); SafePlayerPrefs.SetInt("TotalRewards"+index, TotalReward);
} }
/// <summary>
/// Add information about an Achievement to the UI elements
/// </summary>
public void Set (AchievementInfromation Information, AchievementState State) public void Set (AchievementInfromation Information, AchievementState State)
{ {
if(Information.Spoiler && !State.Achieved) if(Information.Spoiler && !State.Achieved)

@ -140,7 +140,7 @@ PlayerSettings:
loadStoreDebugModeEnabled: 0 loadStoreDebugModeEnabled: 0
visionOSBundleVersion: 1.0 visionOSBundleVersion: 1.0
tvOSBundleVersion: 1.0 tvOSBundleVersion: 1.0
bundleVersion: 2.4 bundleVersion: 2.5
preloadedAssets: [] preloadedAssets: []
metroInputSource: 0 metroInputSource: 0
wsaTransparentSwapchain: 0 wsaTransparentSwapchain: 0
@ -170,7 +170,7 @@ PlayerSettings:
iPhone: 0 iPhone: 0
tvOS: 0 tvOS: 0
overrideDefaultApplicationIdentifier: 1 overrideDefaultApplicationIdentifier: 1
AndroidBundleVersionCode: 14 AndroidBundleVersionCode: 15
AndroidMinSdkVersion: 22 AndroidMinSdkVersion: 22
AndroidTargetSdkVersion: 34 AndroidTargetSdkVersion: 34
AndroidPreferredInstallLocation: 1 AndroidPreferredInstallLocation: 1

Loading…
Cancel
Save