namespace OM
{
///
/// Defines the direction in which something can play.
///
public enum OM_PlayDirection
{
Forward,
Backward
}
///
/// Extension methods for the OM_PlayDirection enum to simplify logic.
///
public static class OM_PlayDirectionExtension
{
///
/// Checks if the direction is Forward.
///
/// The direction to check.
/// True if Forward.
public static bool IsForward(this OM_PlayDirection direction)
{
return direction == OM_PlayDirection.Forward;
}
///
/// Checks if the direction is Backward.
///
/// The direction to check.
/// True if Backward.
public static bool IsBackward(this OM_PlayDirection direction)
{
return direction == OM_PlayDirection.Backward;
}
///
/// Returns 1 for Forward and -1 for Backward.
///
/// The direction.
/// 1 or -1 based on direction.
public static float GetDirectionMultiplier(this OM_PlayDirection direction)
{
return direction.IsForward() ? 1 : -1;
}
///
/// Determines if a timeline has finished based on the direction and elapsed time.
///
/// The current direction.
/// Elapsed time.
/// Total duration.
/// True if finished.
public static bool IsFinished(this OM_PlayDirection direction, float elapsedTime, float duration)
{
return direction.IsForward() ? elapsedTime >= duration : elapsedTime <= 0;
}
///
/// Reverses the current direction.
///
/// The direction to reverse.
/// The opposite direction.
public static OM_PlayDirection Reverse(this OM_PlayDirection direction)
{
return direction == OM_PlayDirection.Forward ? OM_PlayDirection.Backward : OM_PlayDirection.Forward;
}
}
}