Achievement optimization

dev-ali
Ali Sharoz 20 hours ago
parent efd902c023
commit ae0ae60ec1

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

@ -4,9 +4,6 @@ using UnityEngine.UI;
using System.Collections.Generic;
using System;
/// <summary>
/// Add list of achievements to screen
/// </summary>
public class AchievenmentListIngame : MonoBehaviour
{
public GameObject scrollContent;
@ -19,11 +16,7 @@ public class AchievenmentListIngame : MonoBehaviour
private bool MenuOpen = false;
[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>
private void AddAchievements(string Filter)
{
@ -57,17 +50,11 @@ public class AchievenmentListIngame : MonoBehaviour
UIAchievement.transform.SetParent(scrollContent.transform);
UIAchievement.GetComponent<RectTransform>().localScale = Vector3.one;
}
/// <summary>
/// Filter out a set of locked or unlocked achievements
/// </summary>
public void ChangeFilter()
{
AddAchievements(Filter.options[Filter.value].text);
}
/// <summary>
/// Closes the UI window.
/// </summary>
void Start()
{
AddAchievements("All");
@ -85,9 +72,6 @@ public class AchievenmentListIngame : MonoBehaviour
MenuOpen = false;
Menu.Close();
}
/// <summary>
/// Opens the UI window.
/// </summary>
public void OpenWindow()
{
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()
{
if (MenuOpen)
@ -128,12 +109,4 @@ public class AchievenmentListIngame : MonoBehaviour
OpenWindow();
}
}
// private void Update()
// {
// if(Input.GetKeyDown(OpenMenuKey))
// {
// ToggleWindow();
// }
// }
}

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

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

Loading…
Cancel
Save