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/Core/MicrogameController.cs

67 lines
1.7 KiB
C#
Raw Normal View History

2020-04-18 14:09:37 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2020-04-19 14:24:38 +00:00
public class MicrogameController : MonoBehaviour
2020-04-18 14:09:37 +00:00
{
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;
2020-04-19 12:42:38 +00:00
[Header("Microgame Results")]
public bool victory = true;
2020-04-19 01:48:15 +00:00
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
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 12:42:38 +00:00
OnMicrogameEnd?.Invoke(this, victory);
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
}
}