2020-04-18 14:09:37 +00:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public abstract class MicrogameController : MonoBehaviour
|
|
|
|
|
{
|
2020-04-18 20:45:36 +00:00
|
|
|
|
[BeforeStart]
|
|
|
|
|
public string microgameName = "[UNSET]";
|
2020-04-18 14:09:37 +00:00
|
|
|
|
[BeforeStart]
|
|
|
|
|
public float startingTime = 4f;
|
2020-04-18 20:45:36 +00:00
|
|
|
|
|
2020-04-18 14:09:37 +00:00
|
|
|
|
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;
|
2020-04-18 20:45:36 +00:00
|
|
|
|
if(timeLeft <= 0) {
|
|
|
|
|
End();
|
|
|
|
|
}
|
2020-04-18 14:09:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-18 17:02:22 +00:00
|
|
|
|
public float TimeFraction {
|
|
|
|
|
get {
|
2020-04-18 20:45:36 +00:00
|
|
|
|
return timeLeft / startingTime;
|
2020-04-18 17:02:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-18 20:45:36 +00:00
|
|
|
|
public delegate void OnMicrogameStartHandler(MicrogameController microgame);
|
|
|
|
|
public event OnMicrogameStartHandler OnMicrogameStart;
|
|
|
|
|
public delegate void OnMicrogameEndHandler(MicrogameController microgame);
|
|
|
|
|
public event OnMicrogameEndHandler OnMicrogameEnd;
|
|
|
|
|
|
2020-04-18 14:09:37 +00:00
|
|
|
|
public abstract bool MicrogameResults();
|
|
|
|
|
|
2020-04-18 20:45:36 +00:00
|
|
|
|
private void Start() {
|
|
|
|
|
timeLeft = startingTime;
|
|
|
|
|
OnMicrogameStart?.Invoke(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void End() {
|
|
|
|
|
OnMicrogameEnd?.Invoke(this);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-18 14:09:37 +00:00
|
|
|
|
private void Update() {
|
2020-04-18 20:45:36 +00:00
|
|
|
|
TimeLeft -= Time.deltaTime;
|
2020-04-18 14:09:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|