added some stuff
This commit is contained in:
parent
9b69003715
commit
3dbf2f9010
520 changed files with 176780 additions and 2 deletions
72
Assets/Scripts/LemonGenericLib/Scoring System/ScoreKeeper.cs
Normal file
72
Assets/Scripts/LemonGenericLib/Scoring System/ScoreKeeper.cs
Normal file
|
@ -0,0 +1,72 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace Lemon.GenericLib.Score {
|
||||
|
||||
public class ScoreKeeper
|
||||
{
|
||||
public string HIGHSCORE_PLAYERPREF = "HighScore";
|
||||
|
||||
//score variables
|
||||
private int score = 0;
|
||||
private int scoreMultiplier = 1;
|
||||
public int maxMultiplier = 7;
|
||||
|
||||
//score changing event
|
||||
//mainly used for UI
|
||||
public Action<int> OnScoreModified;
|
||||
public Action<int> OnScoreMultiplierModified;
|
||||
public Action<int> OnNewHighScore;
|
||||
|
||||
//getter setters, not advice to set score directly
|
||||
public int Score { get => score; set => score = value; }
|
||||
public int ScoreMultiplier { get => scoreMultiplier; set => scoreMultiplier = value; }
|
||||
public int HighScore { get => PlayerPrefs.GetInt(HIGHSCORE_PLAYERPREF); set => PlayerPrefs.SetInt(HIGHSCORE_PLAYERPREF, score); }
|
||||
|
||||
|
||||
public void ForceUpdate()
|
||||
{
|
||||
OnScoreModified?.Invoke(score);
|
||||
OnScoreMultiplierModified?.Invoke(scoreMultiplier);
|
||||
}
|
||||
|
||||
public void ModifyScore(int value)
|
||||
{
|
||||
score += (value * scoreMultiplier);
|
||||
OnScoreModified?.Invoke(score);
|
||||
}
|
||||
|
||||
public void ResetScore()
|
||||
{
|
||||
score = 0;
|
||||
OnScoreModified?.Invoke(score);
|
||||
}
|
||||
|
||||
public void ModifyMultiplier(int value)
|
||||
{
|
||||
scoreMultiplier += value;
|
||||
scoreMultiplier = Mathf.Clamp(scoreMultiplier, 1, maxMultiplier);
|
||||
OnScoreMultiplierModified?.Invoke(scoreMultiplier);
|
||||
}
|
||||
|
||||
public void ResetMultiplier()
|
||||
{
|
||||
scoreMultiplier = 1;
|
||||
OnScoreMultiplierModified?.Invoke(scoreMultiplier);
|
||||
}
|
||||
|
||||
public bool CheckHighScore()
|
||||
{
|
||||
if (score > PlayerPrefs.GetInt(HIGHSCORE_PLAYERPREF))
|
||||
{
|
||||
PlayerPrefs.SetInt(HIGHSCORE_PLAYERPREF, score);
|
||||
OnNewHighScore?.Invoke(score);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 70caaedb4a6576a4fbb4a7f78ecc4605
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue