rabidus-test/Assets/Scripts/PlayerSetup.cs

87 lines
1.9 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerSetup : MonoBehaviour
{
public static PlayerSetup Instance;
private PlayerInfo _playerInfo;
private Player _currentPlayer;
public Player CurrentPlayer => _currentPlayer;
public List<Player> AllPlayers
{
get
{
return _playerInfo.Players;
}
}
public string DefaultName = "Ïåíçåíåö 367";
private void Awake()
{
transform.parent = null;
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
LoadPlayerData();
}
else if (Instance == this)
{
Destroy(gameObject);
}
}
private void LoadPlayerData()
{
SaveLoadController.Instance.Load(ref _playerInfo);
}
public void CreateNewPlayer()
{
_currentPlayer = new Player();
_currentPlayer.Name = DefaultName;
_currentPlayer.DateTime = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss");
_playerInfo.AddNewPlayer(_currentPlayer);
}
public void SetPlayerName(string name)
{
_currentPlayer.Name = name;
}
public void AddPlayerScore(int score)
{
_currentPlayer.Score += score;
}
public void UnlockMonument(MonumentInfo info)
{
_currentPlayer.UnlockedMonumets.Add(info);
}
public bool TryFindMonument(MonumentInfo info)
{
return _currentPlayer.UnlockedMonumets.Contains(info);
}
public void SaveCurrnetPlayerData()
{
SaveLoadController.Instance.Save(_playerInfo);
}
public Player DebugPlayer;
[ContextMenu("Add debug player")]
private void AddDebug()
{
DebugPlayer.DateTime = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss");
_playerInfo.AddNewPlayer(DebugPlayer);
SaveCurrnetPlayerData();
}
}