1
Fork 0
mirror of https://github.com/Steffo99/keep-everything-alive.git synced 2024-11-23 01:44:18 +00:00
keep-everything-alive/Assets/Scripts/Microgame/MicrogameController.cs

52 lines
1.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public abstract class MicrogameController : MonoBehaviour
{
[BeforeStart]
public string microgameName = "[UNSET]";
[BeforeStart]
public float startingTime = 4f;
public delegate void OnTimeLeftChangeHandler(float previous, float current);
public event OnTimeLeftChangeHandler OnTimeLeftChange;
private float timeLeft;
public float TimeLeft {
get {
return timeLeft;
}
set {
OnTimeLeftChange?.Invoke(TimeLeft, value);
timeLeft = value;
if(timeLeft <= 0) {
End();
}
}
}
public float TimeFraction {
get {
return timeLeft / startingTime;
}
}
public delegate void OnMicrogameStartHandler(MicrogameController microgame);
public event OnMicrogameStartHandler OnMicrogameStart;
public delegate void OnMicrogameEndHandler(MicrogameController microgame);
public event OnMicrogameEndHandler OnMicrogameEnd;
public abstract bool MicrogameResults();
private void Start() {
timeLeft = startingTime;
OnMicrogameStart?.Invoke(this);
}
private void End() {
OnMicrogameEnd?.Invoke(this);
}
private void Update() {
TimeLeft -= Time.deltaTime;
}
}