GameVsJam/3d Prototyp/Assets/Scripts/GameManager.cs

83 lines
2.2 KiB
C#
Raw Normal View History

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]
private double _baseGameDurationSeconds = 10.0 * 60.0;
2024-04-04 15:26:31 +02:00
[SerializeField]
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>
/// Wie weit das Spiel bereits fortgeschritten ist, in Prozent.
2024-04-04 15:26:31 +02:00
/// </summary>
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>
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);
}
InvokeRepeating(nameof(UpdateProgress), 0.0f, 1.0f);
2024-04-04 12:14:58 +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()
{
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()
{
// Entwickler Effizienz ist im Grunde wie viele Entwicklersekunden wir pro Sekunde verrichten können.
_remainingGameDurationSeconds -= _currentEfficiency;
2024-04-04 12:14:58 +02:00
}
}