Contains changes from "gwen-dotnet" removing dependancies on Windows, which ultimately means certain features (e.g. file load/save dialogs) do not work. Those classes still exist, but the code has been commented out.
70 lines
1.7 KiB
C#
70 lines
1.7 KiB
C#
using System;
|
|
|
|
namespace Gwen.Anim
|
|
{
|
|
// Timed animation. Provides a useful base for animations.
|
|
public class TimedAnimation : Animation
|
|
{
|
|
private bool m_Started;
|
|
private bool m_Finished;
|
|
private float m_Start;
|
|
private float m_End;
|
|
private float m_Ease;
|
|
|
|
public override bool Finished { get { return m_Finished; } }
|
|
|
|
public TimedAnimation(float length, float delay = 0.0f, float ease = 1.0f)
|
|
{
|
|
m_Start = Platform.Neutral.GetTimeInSeconds() + delay;
|
|
m_End = m_Start + length;
|
|
m_Ease = ease;
|
|
m_Started = false;
|
|
m_Finished = false;
|
|
}
|
|
|
|
protected override void Think()
|
|
{
|
|
//base.Think();
|
|
|
|
if (m_Finished)
|
|
return;
|
|
|
|
float current = Platform.Neutral.GetTimeInSeconds();
|
|
float secondsIn = current - m_Start;
|
|
if (secondsIn < 0.0)
|
|
return;
|
|
|
|
if (!m_Started)
|
|
{
|
|
m_Started = true;
|
|
OnStart();
|
|
}
|
|
|
|
float delta = secondsIn / (m_End - m_Start);
|
|
if (delta < 0.0f)
|
|
delta = 0.0f;
|
|
if (delta > 1.0f)
|
|
delta = 1.0f;
|
|
|
|
Run((float)Math.Pow(delta, m_Ease));
|
|
|
|
if (delta == 1.0f)
|
|
{
|
|
m_Finished = true;
|
|
OnFinish();
|
|
}
|
|
}
|
|
|
|
// These are the magic functions you should be overriding
|
|
|
|
protected virtual void OnStart()
|
|
{ }
|
|
|
|
protected virtual void Run(float delta)
|
|
{ }
|
|
|
|
protected virtual void OnFinish()
|
|
{ }
|
|
}
|
|
}
|