Giving Rewards To User

dev-hazim
Ali Sharoz 4 weeks ago
parent ece6ca7637
commit ee87a23f9e

@ -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

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

@ -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
@ -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,17 +102,41 @@ 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();
} }
} }

@ -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,9 +80,12 @@ 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
{ {
if(Percent) if(Percent)

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save