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("ProgressSuffix"));
EditorGUILayout.PropertyField(Achievement.FindPropertyRelative("CoinRewards"));
EditorGUILayout.PropertyField(Achievement.FindPropertyRelative("TotalCoinReward"));
EditorGUILayout.PropertyField(Achievement.FindPropertyRelative("SubAchievementIndex"));
}
}

@ -561,7 +561,31 @@ MonoBehaviour:
m_TargetGraphic: {fileID: 2870595462047946196}
m_OnClick:
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
GameObject:
m_ObjectHideFlags: 0
@ -1121,6 +1145,8 @@ MonoBehaviour:
type: 3}
SpoilerText: {fileID: 0}
AS: {fileID: 0}
CompleteToClaimButton: {fileID: 5755234034907795143}
ClaimButton: {fileID: 2415671530643276917}
--- !u!1 &8753576779850342754
GameObject:
m_ObjectHideFlags: 0

@ -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();
@ -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];
achievementInfromation.ProgressGoal += 5;
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;
// Check if the new progress goal has reached or exceeded 50
if (AchievementList[Index].ProgressGoal >= 50)
{
@ -196,10 +207,15 @@ 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>
@ -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)
{

@ -1,6 +1,8 @@
using MS;
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
using System;
/// <summary>
/// Add list of achievements to screen
@ -32,32 +34,43 @@ public class AchievenmentListIngame : MonoBehaviour
AchievementManager AM = AchievementManager.instance;
int AchievedCount = AM.GetAchievedCount();
if(CountText)
if (CountText)
CountText.text = "" + AchievedCount + " / " + AM.States.Count;
if(CompleteText)
if (CompleteText)
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]);
}
}
Scrollbar.value = 1;
}
public List<UIAchievement> Stack;
public void AddAchievementToUI(AchievementInfromation Achievement, AchievementState State)
{
UIAchievement UIAchievement = Instantiate(prefab, new Vector3(0f, 0f, 0f), Quaternion.identity).GetComponent<UIAchievement>();
Stack.Add(UIAchievement);
UIAchievement.Set(Achievement, State);
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>
/// Filter out a set of locked or unlocked achievements
/// </summary>
public void ChangeFilter ()
public void ChangeFilter()
{
AddAchievements(Filter.options[Filter.value].text);
}
@ -65,6 +78,18 @@ public class AchievenmentListIngame : MonoBehaviour
/// <summary>
/// Closes the UI window.
/// </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()
{
MenuOpen = false;
@ -77,17 +102,41 @@ public class AchievenmentListIngame : MonoBehaviour
{
MenuOpen = true;
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>
/// Toggles the state of the UI window open or closed
/// </summary>
public void ToggleWindow()
{
if (MenuOpen){
if (MenuOpen)
{
CloseWindow();
}
else{
else
{
OpenWindow();
}
}

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

@ -3,6 +3,7 @@ using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.WSA;
/// <summary>
/// Defines the logic behind a single achievement on the UI
@ -15,6 +16,8 @@ public class UIAchievement : MonoBehaviour
public TMP_Text SpoilerText;
public AchievenmentStack AS;
public GameObject CompleteToClaimButton;
public Button ClaimButton;
/// <summary>
/// Destroy object after a certain amount of time
/// </summary>
@ -23,9 +26,23 @@ public class UIAchievement : MonoBehaviour
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>
/// Add information about an Achievement to the UI elements
/// </summary>
public void Set (AchievementInfromation Information, AchievementState State)
{
if(Information.Spoiler && !State.Achieved)
@ -38,7 +55,7 @@ public class UIAchievement : MonoBehaviour
else
{
// Title.text = Information.DisplayName;
Description.text = Information.Description;
//Description.text = Information.Description;
if (Information.LockOverlay && !State.Achieved)
{
@ -63,9 +80,12 @@ public class UIAchievement : MonoBehaviour
if (State.Achieved)
{
RewardSetter(Information);
if(Percent)
{
Percent.text = Information.ProgressGoal + Information.ProgressSuffix + " / " + Information.ProgressGoal + Information.ProgressSuffix + " (Achieved)";
}
}
else
{
if(Percent)

File diff suppressed because it is too large Load Diff

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

Loading…
Cancel
Save