Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SocialPlatforms;
- namespace Manager
- {
- [System.Serializable]
- public class Scores
- {
- [SerializeField] private int score;
- [SerializeField] private string name;
- public int GetScore()
- {
- return score;
- }
- public string GetName()
- {
- return name;
- }
- public void SetScore(int newScore)
- {
- score = newScore;
- }
- public void SetName(string newName)
- {
- name = newName;
- }
- }
- public class GameManager : MonoBehaviour
- {
- [Header("Badge States")]
- [SerializeField] bool archeryBadge = false;
- [SerializeField] bool destructionBadge = false;
- [SerializeField] bool rockClimbingBadge = false;
- [Header("Game Highscores")]
- [SerializeField] Scores[] archeryScore = new Scores[5];
- [SerializeField] Scores[] destructionScore = new Scores[5];
- [SerializeField] Scores[] rockClimbingScore = new Scores[5];
- public enum Games { Archery, Destruction, RockClimbing }
- // Singleton implementation
- private static GameManager instance = null;
- public static GameManager Instance { get { return instance; } }
- void Awake()
- {
- //Set Singleton Reference
- if (instance != null)
- {
- if (instance != this)
- {
- Destroy(this);
- }
- }
- else
- {
- instance = this;
- }
- DontDestroyOnLoad(this.gameObject);
- //Establish Leaderboards
- for (int i = 0; i < archeryScore.Length; i++)
- {
- archeryScore[i] = new Scores();
- }
- for (int i = 0; i < destructionScore.Length; i++)
- {
- destructionScore[i] = new Scores();
- }
- for (int i = 0; i < rockClimbingScore.Length; i++)
- {
- rockClimbingScore[i] = new Scores();
- }
- //StartCoroutine(TestScores());
- }
- //used to test leaderboards
- IEnumerator TestScores()
- {
- yield return new WaitForSeconds(2f);
- for (int i = 0; i < archeryScore.Length; i++)
- {
- Debug.Log("Archery Leaderboard " + i + "Name: "+archeryScore[i].GetName()+"; Score " + archeryScore[i].GetScore());
- }
- /*
- for (int i = 0; i < destructionScore.Length; i++)
- {
- Debug.Log("Destruction Score " + destructionScore[i].GetScore());
- Debug.Log("Destruction Name " + destructionScore[i].GetName());
- }
- for (int i = 0; i < rockClimbingScore.Length; i++)
- {
- Debug.Log("rockClimbing Score " + rockClimbingScore[i].GetScore());
- Debug.Log("rockClimbing Name " + rockClimbingScore[i].GetName());
- }
- */
- }
- public void SetBadgeState(Games badge, bool badgeState)
- {
- switch (badge)
- {
- case Games.Archery:
- archeryBadge = badgeState;
- break;
- case Games.Destruction:
- destructionBadge = badgeState;
- break;
- case Games.RockClimbing:
- rockClimbingBadge = badgeState;
- break;
- }
- }
- public bool GetBadgeState(Games game)
- {
- switch (game)
- {
- case Games.Archery:
- return archeryBadge;
- case Games.Destruction:
- return destructionBadge;
- case Games.RockClimbing:
- return rockClimbingBadge;
- }
- return false;
- }
- public void SetHighScore(Games game, int score, string name)
- {
- int scoreToUpdate = -1;
- bool updateScore = false;
- switch (game)
- {
- case Games.Archery:
- for (int i = 0; i < archeryScore.Length; i++)
- {
- if (archeryScore[i].GetScore() == score) { break; }
- if (archeryScore[i].GetScore() < score)
- {
- scoreToUpdate = i;
- updateScore = true;
- break;
- }
- }
- if (updateScore == true)
- {
- for (int x = 4; x >= 0; x--)
- {
- if (x != scoreToUpdate)
- {
- archeryScore[x] = archeryScore[x - 1];
- Debug.Log("Archery Sort " + x + "Name: " + archeryScore[x].GetName() + "; Score " + archeryScore[x].GetScore());
- }
- else
- {
- archeryScore[x].SetScore(score);
- archeryScore[x].SetName(name);
- Debug.Log("Archery Leaderboard Set " + x + "Name: " + archeryScore[x].GetName() + "; Score " + archeryScore[x].GetScore());
- break;
- }
- }
- }
- break;
- /*
- case Games.Destruction:
- for (int i = 0; i < destructionScore.Length - 1; i++)
- {
- if (destructionScore[i].score == score) { break; }
- if (destructionScore[i].score < score)
- {
- scoreToUpdate = i;
- updateScore = true;
- break;
- }
- }
- if (updateScore == true)
- {
- for (int x = 4; x >= 0; x--)
- {
- if (x != scoreToUpdate)
- {
- destructionScore[x] = destructionScore[x - 1];
- }
- else
- {
- destructionScore[x].score = score;
- destructionScore[x].name = name;
- break;
- }
- }
- }
- break;
- case Games.RockClimbing:
- for (int i = 0; i < rockClimbingScore.Length - 1; i++)
- {
- if (rockClimbingScore[i].score == score) { break; }
- if (rockClimbingScore[i].score < score)
- {
- scoreToUpdate = i;
- updateScore = true;
- break;
- }
- }
- if (updateScore == true)
- {
- for (int x = 4; x >= 0; x--)
- {
- if (x != scoreToUpdate)
- {
- rockClimbingScore[x] = rockClimbingScore[x - 1];
- }
- else
- {
- rockClimbingScore[x].score = score;
- rockClimbingScore[x].name = name;
- break;
- }
- }
- }
- break;
- */
- }
- }
- public Scores[] GetHighScores(Games game)
- {
- switch (game)
- {
- case Games.Archery:
- return archeryScore;
- case Games.Destruction:
- return destructionScore;
- case Games.RockClimbing:
- return rockClimbingScore;
- }
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment