82 lines
2.2 KiB
C#
82 lines
2.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
public class GameManager : MonoBehaviour
|
|
{
|
|
public static GameManager Instance { get; private set; }
|
|
|
|
[SerializeField]
|
|
private double _gameProgress = 0.0;
|
|
|
|
[SerializeField]
|
|
private double _baseGameDurationSeconds = 10.0 * 60.0;
|
|
|
|
[SerializeField, ShowOnly]
|
|
private double _currentEfficiency = 0.0;
|
|
|
|
[SerializeField, ShowOnly]
|
|
private double _remainingGameDurationSeconds = 0.0;
|
|
|
|
[SerializeField]
|
|
private List<Developer> _developers = new();
|
|
|
|
/// <summary>
|
|
/// Wie weit das Spiel bereits fortgeschritten ist.
|
|
/// </summary>
|
|
public double GameProgress => _gameProgress;
|
|
|
|
/// <summary>
|
|
/// Wie Effizient das Team derzeit arbeitet.
|
|
/// </summary>
|
|
public double CurrentEfficiency => _currentEfficiency;
|
|
|
|
/// <summary>
|
|
/// Wie viele Sekunden das Spiel voraussichtlich noch dauern wird, würden die Effizienz sich nicht verändern.
|
|
/// </summary>
|
|
public double RemainingGameDurationSeconds => _remainingGameDurationSeconds;
|
|
|
|
/// <summary>
|
|
/// Wie lange das Spiel voraussichtlich noch dauern wird, würden die Effizienz sich nicht verändern.
|
|
/// </summary>
|
|
public TimeSpan RemainingGameDuration => TimeSpan.FromSeconds(_remainingGameDurationSeconds);
|
|
|
|
/// <summary>
|
|
/// Wie lange voraussichtlich das gesamte Spiel dauern wird.
|
|
/// </summary>
|
|
public double ExpectedTotalGameSeconds => 0.0;
|
|
|
|
private void Awake()
|
|
{
|
|
if (Instance == null)
|
|
{
|
|
Instance = this;
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("GameManager already exists. Deleting duplicate.");
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
UpdateEfficiency();
|
|
UpdateGameDuration();
|
|
}
|
|
|
|
void UpdateEfficiency()
|
|
{
|
|
_currentEfficiency = _developers.Sum(d => d.Efficiency);
|
|
}
|
|
|
|
void UpdateGameDuration()
|
|
{
|
|
double baseSecondsLeft = _baseGameDurationSeconds * (1.0 - GameProgress);
|
|
|
|
_remainingGameDurationSeconds = baseSecondsLeft / _currentEfficiency;
|
|
}
|
|
}
|