Components!

This commit is contained in:
Matt Thorson
2020-05-05 19:53:13 -07:00
parent 409a82d6b8
commit bde9a51f9e
8 changed files with 189 additions and 4 deletions

58
src/Components/Timer.bf Normal file
View File

@ -0,0 +1,58 @@
using System;
using System.Diagnostics;
namespace Strawberry
{
public class Timer : Component
{
private float value;
public Action OnComplete ~ delete _;
public bool DestroyOnComplete;
public this()
: base(false, false)
{
}
public this(float value, Action onComplete, bool destroyOnComplete = false)
: base(false, false)
{
Value = value;
OnComplete = onComplete;
DestroyOnComplete = destroyOnComplete;
}
public float Value
{
get
{
return value;
}
set
{
this.value = Math.Max(0, value);
Active = (this.value > 0);
}
}
public override void Update()
{
if (value > 0)
{
value -= Time.Delta;
if (value <= 0)
{
value = 0;
Active = false;
OnComplete?.Invoke();
if (DestroyOnComplete)
RemoveSelf();
}
}
}
}
}