GameManagerScript.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class GameManagerScript : MonoBehaviour {
  6. private int playerCount;
  7. private string gameMode;
  8. private int gameId;
  9. public Database db;
  10. public string GameMode { get => gameMode; set => gameMode = value; }
  11. public int GameId { get; internal set; }
  12. List<KeyValuePair<string, int>> players;
  13. // Start is called before the first frame update
  14. void Start() {
  15. db = GameObject.Find("GameManager").GetComponent<Database>();
  16. GameId = PlayerPrefs.GetInt("GameId");
  17. db.SetLocalOrOnline("Local");
  18. db.SetLastPlayedDate(gameId);
  19. StatsScript statsScript = GameObject.Find("StatsPanel").GetComponent<StatsScript>();
  20. statsScript.AddPlayersToStats(GetPlayersForGame());
  21. }
  22. private List<KeyValuePair<string,int>> GetPlayersForGame() {
  23. players = db.GetPlayersForGame(GameId);
  24. return players;
  25. }
  26. public List<KeyValuePair<string, int>> GetPlayers() {
  27. if (players == null) {
  28. players = GetPlayersForGame();
  29. }
  30. return players;
  31. }
  32. public Database GetDatabase() {
  33. if (db == null) {
  34. db = GameObject.Find("GameManager").GetComponent<Database>();
  35. }
  36. return db;
  37. }
  38. }