2024-04-04 15:26:31 +02:00
|
|
|
using System;
|
2024-04-04 12:14:58 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
2024-04-04 15:26:31 +02:00
|
|
|
using System.Linq;
|
2024-04-04 12:14:58 +02:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class GameManager : MonoBehaviour
|
|
|
|
{
|
2024-04-04 15:26:31 +02:00
|
|
|
public static GameManager Instance { get; private set; }
|
2024-04-04 12:21:07 +02:00
|
|
|
|
2024-04-04 15:26:31 +02:00
|
|
|
[SerializeField]
|
2024-04-04 16:33:12 +02:00
|
|
|
private double _baseGameDurationSeconds = 10.0 * 60.0;
|
2024-04-04 15:26:31 +02:00
|
|
|
|
|
|
|
[SerializeField]
|
2024-04-04 16:33:12 +02:00
|
|
|
private double _remainingGameDurationSeconds = 0.0;
|
2024-04-04 15:26:31 +02:00
|
|
|
|
|
|
|
[SerializeField, ShowOnly]
|
|
|
|
private double _currentEfficiency = 0.0;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private List<Developer> _developers = new();
|
|
|
|
|
|
|
|
/// <summary>
|
2024-04-04 16:33:12 +02:00
|
|
|
/// Wie weit das Spiel bereits fortgeschritten ist, in Prozent.
|
2024-04-04 15:26:31 +02:00
|
|
|
/// </summary>
|
2024-04-04 16:33:12 +02:00
|
|
|
public double GameProgress => 1.0 - (_remainingGameDurationSeconds / _baseGameDurationSeconds);
|
2024-04-04 15:26:31 +02:00
|
|
|
|
|
|
|
/// <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>
|
2024-04-04 16:33:12 +02:00
|
|
|
public double ExpectedRemainingGameDuration => _remainingGameDurationSeconds / _currentEfficiency;
|
2024-04-04 15:26:31 +02:00
|
|
|
|
|
|
|
private void Awake()
|
2024-04-04 12:14:58 +02:00
|
|
|
{
|
2024-04-04 15:26:31 +02:00
|
|
|
if (Instance == null)
|
|
|
|
{
|
|
|
|
Instance = this;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Debug.LogError("GameManager already exists. Deleting duplicate.");
|
|
|
|
Destroy(gameObject);
|
|
|
|
}
|
2024-04-04 16:33:12 +02:00
|
|
|
|
|
|
|
InvokeRepeating(nameof(UpdateProgress), 0.0f, 1.0f);
|
2024-04-04 12:14:58 +02:00
|
|
|
}
|
|
|
|
|
2024-04-04 16:33:12 +02:00
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
_remainingGameDurationSeconds = _baseGameDurationSeconds;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateProgress()
|
2024-04-04 12:14:58 +02:00
|
|
|
{
|
2024-04-04 15:26:31 +02:00
|
|
|
UpdateEfficiency();
|
|
|
|
UpdateGameDuration();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateEfficiency()
|
|
|
|
{
|
2024-04-04 16:33:12 +02:00
|
|
|
double developerEfficiency = 0.0f;
|
|
|
|
|
|
|
|
foreach (Developer developer in _developers)
|
|
|
|
{
|
|
|
|
developer.UpdateEfficiency();
|
|
|
|
developerEfficiency += developer.Efficiency;
|
|
|
|
}
|
|
|
|
|
|
|
|
_currentEfficiency = developerEfficiency;
|
2024-04-04 15:26:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateGameDuration()
|
|
|
|
{
|
2024-04-04 16:33:12 +02:00
|
|
|
// Entwickler Effizienz ist im Grunde wie viele Entwicklersekunden wir pro Sekunde verrichten können.
|
|
|
|
_remainingGameDurationSeconds -= _currentEfficiency;
|
2024-04-04 12:14:58 +02:00
|
|
|
}
|
|
|
|
}
|