GameManager etwas mehr gefüllt
This commit is contained in:
@ -1,20 +1,81 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
public double GameProgress = 0.0;
|
||||
public static GameManager Instance { get; private set; }
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
[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);
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
UpdateEfficiency();
|
||||
UpdateGameDuration();
|
||||
}
|
||||
|
||||
void UpdateEfficiency()
|
||||
{
|
||||
_currentEfficiency = _developers.Sum(d => d.Efficiency);
|
||||
}
|
||||
|
||||
void UpdateGameDuration()
|
||||
{
|
||||
double baseSecondsLeft = _baseGameDurationSeconds * (1.0 - GameProgress);
|
||||
|
||||
_remainingGameDurationSeconds = baseSecondsLeft / _currentEfficiency;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user