You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.3 KiB
C#
61 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Otter {
|
|
public class Countdown : Component {
|
|
|
|
public float Max;
|
|
public float Min;
|
|
public float Decrement = -1;
|
|
public float Value;
|
|
|
|
public bool IsCompleted {
|
|
get { return Value <= 0; }
|
|
}
|
|
|
|
public float Completion {
|
|
get {
|
|
return Util.Clamp((Max - Value) / Max, 0, 1);
|
|
}
|
|
}
|
|
|
|
public Action OnTrigger = delegate { };
|
|
public bool Triggered;
|
|
|
|
public Countdown(float max) {
|
|
Max = max;
|
|
Value = max;
|
|
}
|
|
|
|
public Countdown(float max, float value) : this(max) {
|
|
Value = value;
|
|
}
|
|
|
|
public override void Update() {
|
|
base.Update();
|
|
Tick();
|
|
}
|
|
|
|
public void Tick() {
|
|
Value += Decrement;
|
|
if (IsCompleted) {
|
|
Value = 0;
|
|
if (!Triggered) {
|
|
Triggered = true;
|
|
OnTrigger();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Reset() {
|
|
Value = Max;
|
|
Triggered = false;
|
|
}
|
|
|
|
|
|
}
|
|
}
|