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 _baseGameDurationSeconds = 10.0 * 60.0; [SerializeField] private double _remainingGameDurationSeconds = 0.0; [SerializeField, ShowOnly] private double _currentEfficiency = 0.0; [SerializeField] private List _developers = new(); /// /// Wie weit das Spiel bereits fortgeschritten ist, in Prozent. /// public double GameProgress => 1.0 - (_remainingGameDurationSeconds / _baseGameDurationSeconds); /// /// Wie Effizient das Team derzeit arbeitet. /// public double CurrentEfficiency => _currentEfficiency; /// /// Wie viele Sekunden das Spiel voraussichtlich noch dauern wird, würden die Effizienz sich nicht verändern. /// public double ExpectedRemainingGameDuration => _remainingGameDurationSeconds / _currentEfficiency; private void Awake() { if (Instance == null) { Instance = this; } else { Debug.LogError("GameManager already exists. Deleting duplicate."); Destroy(gameObject); } InvokeRepeating(nameof(UpdateProgress), 0.0f, 1.0f); } private void Start() { _remainingGameDurationSeconds = _baseGameDurationSeconds; } void UpdateProgress() { UpdateEfficiency(); UpdateGameDuration(); } void UpdateEfficiency() { double developerEfficiency = 0.0f; foreach (Developer developer in _developers) { developer.UpdateEfficiency(); developerEfficiency += developer.Efficiency; } _currentEfficiency = developerEfficiency; } void UpdateGameDuration() { // Entwickler Effizienz ist im Grunde wie viele Entwicklersekunden wir pro Sekunde verrichten können. _remainingGameDurationSeconds -= _currentEfficiency; } }