2020-04-18 14:09:37 +00:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public abstract class MicrogameController : MonoBehaviour
|
|
|
|
|
{
|
2020-04-19 01:48:15 +00:00
|
|
|
|
[Header("Microgame Settings")]
|
2020-04-18 14:09:37 +00:00
|
|
|
|
[BeforeStart]
|
|
|
|
|
public float startingTime = 4f;
|
2020-04-18 20:45:36 +00:00
|
|
|
|
|
2020-04-19 01:48:15 +00:00
|
|
|
|
[Header("Wheel Settings")]
|
|
|
|
|
[BeforeStart]
|
|
|
|
|
public string microgameName;
|
|
|
|
|
[BeforeStart]
|
|
|
|
|
public Color microgameNameColor;
|
|
|
|
|
[BeforeStart]
|
|
|
|
|
public Font microgameNameFont;
|
|
|
|
|
|
|
|
|
|
protected GameController gameController;
|
|
|
|
|
|
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;
|
2020-04-19 01:48:15 +00:00
|
|
|
|
public delegate void OnMicrogameEndHandler(MicrogameController microgame, bool victory);
|
2020-04-18 20:45:36 +00:00
|
|
|
|
public event OnMicrogameEndHandler OnMicrogameEnd;
|
|
|
|
|
|
2020-04-19 01:48:15 +00:00
|
|
|
|
protected abstract bool MicrogameResults();
|
|
|
|
|
|
|
|
|
|
private void Awake() {
|
|
|
|
|
gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameController>();
|
|
|
|
|
}
|
2020-04-18 14:09:37 +00:00
|
|
|
|
|
2020-04-18 20:45:36 +00:00
|
|
|
|
private void Start() {
|
|
|
|
|
timeLeft = startingTime;
|
|
|
|
|
OnMicrogameStart?.Invoke(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void End() {
|
2020-04-19 01:48:15 +00:00
|
|
|
|
OnMicrogameEnd?.Invoke(this, MicrogameResults());
|
2020-04-18 20:45:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|