encompass-cs/encompass-cs/TimeDilationData.cs

57 lines
1.7 KiB
C#
Raw Normal View History

2020-03-20 07:09:57 +00:00
using System;
namespace Encompass
{
internal struct TimeDilationData
{
2020-03-20 07:09:57 +00:00
private readonly double _factor;
public double Factor
{
get
{
2020-03-20 07:09:57 +00:00
if (ElapsedTime < EaseInTime)
{
2020-03-20 07:09:57 +00:00
return EaseInFunction(ElapsedTime, 1, _factor - 1, EaseInTime);
}
2020-03-20 07:09:57 +00:00
else if (ElapsedTime < EaseInTime + ActiveTime)
{
2020-03-20 07:09:57 +00:00
return _factor;
}
2020-03-20 07:09:57 +00:00
else if (ElapsedTime < EaseInTime + ActiveTime + EaseOutTime)
{
2020-03-20 07:09:57 +00:00
var elapsedOutTime = ElapsedTime - EaseInTime - ActiveTime;
return EaseOutFunction(elapsedOutTime, _factor, 1 - _factor, EaseOutTime);
}
return 1;
}
}
2020-03-20 07:09:57 +00:00
public double ElapsedTime { get; set; }
public double EaseInTime { get; }
public Func<double, double, double, double, double> EaseInFunction { get; }
public double ActiveTime { get; }
public double EaseOutTime { get; }
public Func<double, double, double, double, double> EaseOutFunction { get; }
public TimeDilationData(
double factor,
double easeInTime,
Func<double, double, double, double, double> easeInfunction,
double activeTime,
double easeOutTime,
Func<double, double, double, double, double> easeOutFunction
)
{
_factor = factor;
EaseInTime = easeInTime;
EaseInFunction = easeInfunction;
ActiveTime = activeTime;
EaseOutTime = easeOutTime;
EaseOutFunction = easeOutFunction;
ElapsedTime = 0;
}
}
2020-03-20 07:09:57 +00:00
}