Merge branch 'dev-ali'

dev-hazim
Hazim Bin Ijaz 4 weeks ago
commit 7d5db079ce

@ -197,6 +197,7 @@ public class AchievementManagerEditor : Editor
EditorGUILayout.PropertyField(Achievement.FindPropertyRelative("NotificationFrequency")); EditorGUILayout.PropertyField(Achievement.FindPropertyRelative("NotificationFrequency"));
EditorGUILayout.PropertyField(Achievement.FindPropertyRelative("ProgressSuffix")); EditorGUILayout.PropertyField(Achievement.FindPropertyRelative("ProgressSuffix"));
EditorGUILayout.PropertyField(Achievement.FindPropertyRelative("CoinRewards")); EditorGUILayout.PropertyField(Achievement.FindPropertyRelative("CoinRewards"));
EditorGUILayout.PropertyField(Achievement.FindPropertyRelative("TotalCoinReward"));
EditorGUILayout.PropertyField(Achievement.FindPropertyRelative("SubAchievementIndex")); EditorGUILayout.PropertyField(Achievement.FindPropertyRelative("SubAchievementIndex"));
} }
} }

@ -561,7 +561,31 @@ MonoBehaviour:
m_TargetGraphic: {fileID: 2870595462047946196} m_TargetGraphic: {fileID: 2870595462047946196}
m_OnClick: m_OnClick:
m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls:
- m_Target: {fileID: 3414891153139813893}
m_TargetAssemblyTypeName: UnityEngine.GameObject, UnityEngine
m_MethodName: SetActive
m_Mode: 6
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- m_Target: {fileID: 5755234034907795143}
m_TargetAssemblyTypeName: UnityEngine.GameObject, UnityEngine
m_MethodName: SetActive
m_Mode: 6
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 1
m_CallState: 2
--- !u!1 &3889238865471154235 --- !u!1 &3889238865471154235
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1121,6 +1145,8 @@ MonoBehaviour:
type: 3} type: 3}
SpoilerText: {fileID: 0} SpoilerText: {fileID: 0}
AS: {fileID: 0} AS: {fileID: 0}
CompleteToClaimButton: {fileID: 5755234034907795143}
ClaimButton: {fileID: 2415671530643276917}
--- !u!1 &8753576779850342754 --- !u!1 &8753576779850342754
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

@ -31,9 +31,9 @@ public class AchievementManager : MonoBehaviour
public AudioClip AchievedSound; 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.")] [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; public AudioClip ProgressMadeSound;
private AudioSource AudioSource; private AudioSource AudioSource;
[SerializeField] public List<AchievementState> States = new List<AchievementState>(); //List of achievement states (achieved, progress and last notification) [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 [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 static AchievementManager instance = null; //Singleton Instance
public AchievenmentStack Stack; public AchievenmentStack Stack;
public Button ClaimRewardButton; public Button ClaimRewardButton;
public AchievenmentListIngame achievementListIngame;
void Awake() void Awake()
{ {
@ -62,9 +63,9 @@ public class AchievementManager : MonoBehaviour
LoadAchievementState(); LoadAchievementState();
} }
private void PlaySound (AudioClip Sound) private void PlaySound(AudioClip Sound)
{ {
if(AudioSource != null) if (AudioSource != null)
{ {
AudioSource.clip = Sound; AudioSource.clip = Sound;
AudioSource.Play(); AudioSource.Play();
@ -95,8 +96,8 @@ public class AchievementManager : MonoBehaviour
public int GetAchievedCount() public int GetAchievedCount()
{ {
int Count = (from AchievementState i in States int Count = (from AchievementState i in States
where i.Achieved == true where i.Achieved == true
select i).Count(); select i).Count();
return Count; return Count;
} }
/// <summary> /// <summary>
@ -104,7 +105,7 @@ public class AchievementManager : MonoBehaviour
/// </summary> /// </summary>
public float GetAchievedPercentage() public float GetAchievedPercentage()
{ {
if(States.Count == 0) if (States.Count == 0)
{ {
return 0; return 0;
} }
@ -137,18 +138,10 @@ public class AchievementManager : MonoBehaviour
float ct = 0; float ct = 0;
float nt; float nt;
float tot = animTime; float tot = animTime;
Text coinTxt=null; Text coinTxt = null;
if(FindAnyObjectByType<HomeScene>()!=null) HomeScene homeScene = FindAnyObjectByType<HomeScene>();
{ coinTxt = homeScene.coinLbl;
coinTxt = FindAnyObjectByType<HomeScene>().coinLbl; coinTxt.transform.DOShakePosition(1f);
coinTxt.transform.DOShakePosition(0.5f);
}
else if(FindAnyObjectByType<GameScene>()!=null)
{
coinTxt = FindAnyObjectByType<GameScene>().coinLbl;
coinTxt.transform.DOShakePosition(0.5f);
}
//coinTxt.transform.DOShakePosition(0.5f); //coinTxt.transform.DOShakePosition(0.5f);
// coinTxt.GetComponent<Animation>().Play("textShake"); // coinTxt.GetComponent<Animation>().Play("textShake");
while (ct < tot) while (ct < tot)
@ -166,19 +159,37 @@ public class AchievementManager : MonoBehaviour
/// Fully unlocks a progression or goal achievement. /// Fully unlocks a progression or goal achievement.
/// </summary> /// </summary>
/// <param name="Index">The index of the achievement to be unlocked</param> /// <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) public void Unlock(int Index)
{ {
if (!States[Index].Achieved) if (!States[Index].Achieved)
{ {
int numOfCoins = AchievementList[Index].CoinRewards[AchievementList[Index].SubAchievementIndex]; //ButtonSetterForUnlockedAcheivement(Index);
ClaimRewardButton.onClick.AddListener(() => AddCoins(numOfCoins));
//ClaimRewardButton.onClick.AddListener(() => AddCoins(numOfCoins));
// Set current progress to the achievement's progress goal // Set current progress to the achievement's progress goal
States[Index].Progress = AchievementList[Index].ProgressGoal; States[Index].Progress = AchievementList[Index].ProgressGoal;
var achievementInfromation = AchievementList[Index]; 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; achievementInfromation.ProgressGoal += 5;
States[Index].LastProgressGoal = achievementInfromation.ProgressGoal;
// Check if the new progress goal has reached or exceeded 50 // Check if the new progress goal has reached or exceeded 50
if (AchievementList[Index].ProgressGoal >= 50) if (AchievementList[Index].ProgressGoal >= 50)
{ {
@ -196,12 +207,17 @@ public class AchievementManager : MonoBehaviour
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
} }
} }
} }
else
{
ButtonSetterForUnlockedAcheivement(Index);
}
} }
/// <summary> /// <summary>
/// Set the progress of an achievement to a specific value. /// Set the progress of an achievement to a specific value.
/// </summary> /// </summary>
@ -218,7 +234,7 @@ public class AchievementManager : MonoBehaviour
/// <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)
{ {
if(AchievementList[Index].Progression) if (AchievementList[Index].Progression)
{ {
if (States[Index].Progress >= AchievementList[Index].ProgressGoal) if (States[Index].Progress >= AchievementList[Index].ProgressGoal)
{ {
@ -228,7 +244,7 @@ public class AchievementManager : MonoBehaviour
{ {
States[Index].Progress = Progress; States[Index].Progress = Progress;
DisplayUnlock(Index); DisplayUnlock(Index);
AutoSaveStates(); AutoSaveStates();
} }
} }
} }
@ -298,7 +314,7 @@ public class AchievementManager : MonoBehaviour
States.Add(new AchievementState()); States.Add(new AchievementState());
AchievementList[i].ProgressGoal = 5; AchievementList[i].ProgressGoal = 5;
} }
} }
} }
/// <summary> /// <summary>

@ -1,6 +1,8 @@
using MS; using MS;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using System.Collections.Generic;
using System;
/// <summary> /// <summary>
/// Add list of achievements to screen /// Add list of achievements to screen
@ -15,7 +17,7 @@ public class AchievenmentListIngame : MonoBehaviour
public Text CompleteText; public Text CompleteText;
public Scrollbar Scrollbar; public Scrollbar Scrollbar;
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 // public KeyCode OpenMenuKey; //Key to open in-game menu
@ -24,7 +26,7 @@ public class AchievenmentListIngame : MonoBehaviour
/// </summary> /// </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)
{ {
foreach (Transform child in scrollContent.transform) foreach (Transform child in scrollContent.transform)
{ {
Destroy(child.gameObject); Destroy(child.gameObject);
@ -32,32 +34,43 @@ public class AchievenmentListIngame : MonoBehaviour
AchievementManager AM = AchievementManager.instance; AchievementManager AM = AchievementManager.instance;
int AchievedCount = AM.GetAchievedCount(); int AchievedCount = AM.GetAchievedCount();
if(CountText) if (CountText)
CountText.text = "" + AchievedCount + " / " + AM.States.Count; CountText.text = "" + AchievedCount + " / " + AM.States.Count;
if(CompleteText) if (CompleteText)
CompleteText.text = "Complete (" + AM.GetAchievedPercentage() + "%)"; CompleteText.text = "Complete (" + AM.GetAchievedPercentage() + "%)";
for (int i = 0; i < AM.AchievementList.Count; i ++) for (int i = 0; i < AM.AchievementList.Count; i++)
{ {
if((Filter.Equals("All")) || (Filter.Equals("Achieved") && AM.States[i].Achieved) || (Filter.Equals("Unachieved") && !AM.States[i].Achieved)) if ((Filter.Equals("All")) || (Filter.Equals("Achieved") && AM.States[i].Achieved) || (Filter.Equals("Unachieved") && !AM.States[i].Achieved))
{ {
AddAchievementToUI(AM.AchievementList[i], AM.States[i]); AddAchievementToUI(AM.AchievementList[i], AM.States[i]);
} }
} }
Scrollbar.value = 1; Scrollbar.value = 1;
} }
public List<UIAchievement> Stack;
public void AddAchievementToUI(AchievementInfromation Achievement, AchievementState State) public void AddAchievementToUI(AchievementInfromation Achievement, AchievementState State)
{ {
UIAchievement UIAchievement = Instantiate(prefab, new Vector3(0f, 0f, 0f), Quaternion.identity).GetComponent<UIAchievement>(); UIAchievement UIAchievement = Instantiate(prefab, new Vector3(0f, 0f, 0f), Quaternion.identity).GetComponent<UIAchievement>();
Stack.Add(UIAchievement);
UIAchievement.Set(Achievement, State); UIAchievement.Set(Achievement, State);
UIAchievement.transform.SetParent(scrollContent.transform); UIAchievement.transform.SetParent(scrollContent.transform);
UIAchievement.GetComponent<RectTransform>().localScale= Vector3.one; UIAchievement.GetComponent<RectTransform>().localScale = Vector3.one;
//if (Achievement.TotalCoinReward > 0)
//{
// UIAchievement.ClaimButton.gameObject.SetActive(true);
// UIAchievement.CompleteToClaimButton.SetActive(false);
// int numOfCoins = Achievement.TotalCoinReward;
// //int numOfCoins = AchievementList[index].CoinRewards[AchievementList[index].SubAchievementIndex];
// UIAchievement.ClaimButton.onClick.RemoveAllListeners();
// UIAchievement.ClaimButton.onClick.AddListener(() => AchievementManager.instance.AddCoins(numOfCoins));
//}
} }
/// <summary> /// <summary>
/// Filter out a set of locked or unlocked achievements /// Filter out a set of locked or unlocked achievements
/// </summary> /// </summary>
public void ChangeFilter () public void ChangeFilter()
{ {
AddAchievements(Filter.options[Filter.value].text); AddAchievements(Filter.options[Filter.value].text);
} }
@ -65,6 +78,18 @@ public class AchievenmentListIngame : MonoBehaviour
/// <summary> /// <summary>
/// Closes the UI window. /// Closes the UI window.
/// </summary> /// </summary>
void Start()
{
AddAchievements("All");
Invoke(nameof(Starter), 0.5f);
}
public void Starter()
{
if (AchievementManager.instance.achievementListIngame == null)
{
AchievementManager.instance.achievementListIngame = this;
}
}
public void CloseWindow() public void CloseWindow()
{ {
MenuOpen = false; MenuOpen = false;
@ -77,21 +102,45 @@ public class AchievenmentListIngame : MonoBehaviour
{ {
MenuOpen = true; MenuOpen = true;
Menu.Open(); Menu.Open();
AddAchievements("All"); Setter();
//AddAchievements("All");
}
void Setter()
{
for (int i = 0; i < Stack.Count; i++)
{
if (PlayerPrefs.GetInt("UIAchievement" + i + "Claimable") == 1)
{
PlayerPrefs.SetInt("UIAchievement" + i + "Claimable", 0);
Stack[i].ClaimButton.gameObject.SetActive(true);
Stack[i].CompleteToClaimButton.SetActive(false);
int numofCoinsToAdd = PlayerPrefs.GetInt("TotalCoinsForReward" + i);
Stack[i].ClaimButton.onClick.RemoveAllListeners();
Stack[i].ClaimButton.onClick.AddListener(() =>
{
AchievementManager.instance.AddCoins(numofCoinsToAdd);
PlayerPrefs.SetInt("TotalCoinsForReward" + i, 0);
});
}
}
} }
/// <summary> /// <summary>
/// Toggles the state of the UI window open or closed /// Toggles the state of the UI window open or closed
/// </summary> /// </summary>
public void ToggleWindow() public void ToggleWindow()
{ {
if (MenuOpen){ if (MenuOpen)
{
CloseWindow(); CloseWindow();
} }
else{ else
{
OpenWindow(); OpenWindow();
} }
} }
// private void Update() // private void Update()
// { // {
// if(Input.GetKeyDown(OpenMenuKey)) // if(Input.GetKeyDown(OpenMenuKey))

@ -30,6 +30,7 @@ public class AchievementInfromation
[Tooltip("A string which will be displayed with a progress achievement e.g. $, KM, Miles etc")] [Tooltip("A string which will be displayed with a progress achievement e.g. $, KM, Miles etc")]
[SerializeField] public string ProgressSuffix; [SerializeField] public string ProgressSuffix;
public List<int> CoinRewards; public List<int> CoinRewards;
public int TotalCoinReward;
public int SubAchievementIndex; public int SubAchievementIndex;
} }

@ -3,6 +3,7 @@ using System.Collections.Generic;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using UnityEngine.WSA;
/// <summary> /// <summary>
/// Defines the logic behind a single achievement on the UI /// Defines the logic behind a single achievement on the UI
@ -15,6 +16,8 @@ public class UIAchievement : MonoBehaviour
public TMP_Text SpoilerText; public TMP_Text SpoilerText;
public AchievenmentStack AS; public AchievenmentStack AS;
public GameObject CompleteToClaimButton;
public Button ClaimButton;
/// <summary> /// <summary>
/// Destroy object after a certain amount of time /// Destroy object after a certain amount of time
/// </summary> /// </summary>
@ -23,9 +26,23 @@ public class UIAchievement : MonoBehaviour
StartCoroutine(Wait()); StartCoroutine(Wait());
} }
void RewardSetter(AchievementInfromation Information)
{
Debug.Log("Reward Setter");
int index=transform.GetSiblingIndex();
int CurrentTotalReward = Information.TotalCoinReward;
int subAchievementIndex = Information.SubAchievementIndex;
int RewardtoAdd = Information.CoinRewards[subAchievementIndex];
int TotalReward = RewardtoAdd + CurrentTotalReward;
Information.TotalCoinReward = TotalReward;
PlayerPrefs.SetInt("TotalRewards"+index, TotalReward);
}
/// <summary> /// <summary>
/// Add information about an Achievement to the UI elements /// Add information about an Achievement to the UI elements
/// </summary> /// </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)
@ -38,7 +55,7 @@ public class UIAchievement : MonoBehaviour
else else
{ {
// Title.text = Information.DisplayName; // Title.text = Information.DisplayName;
Description.text = Information.Description; //Description.text = Information.Description;
if (Information.LockOverlay && !State.Achieved) if (Information.LockOverlay && !State.Achieved)
{ {
@ -63,8 +80,11 @@ public class UIAchievement : MonoBehaviour
if (State.Achieved) if (State.Achieved)
{ {
RewardSetter(Information);
if(Percent) if(Percent)
{
Percent.text = Information.ProgressGoal + Information.ProgressSuffix + " / " + Information.ProgressGoal + Information.ProgressSuffix + " (Achieved)"; Percent.text = Information.ProgressGoal + Information.ProgressSuffix + " / " + Information.ProgressGoal + Information.ProgressSuffix + " (Achieved)";
}
} }
else else
{ {

File diff suppressed because it is too large Load Diff

@ -73,7 +73,7 @@ public class GameManager
{ {
get get
{ {
return PlayerPrefs.GetInt("Coin", 50); return PlayerPrefs.GetInt("Coin", 0);
} }
set set
{ {

Loading…
Cancel
Save