本文整理汇总了C#中Easing.Any方法的典型用法代码示例。如果您正苦于以下问题:C# Easing.Any方法的具体用法?C# Easing.Any怎么用?C# Easing.Any使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Easing
的用法示例。
在下文中一共展示了Easing.Any方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPerSecondFactor
/// <summary> Gets a value between 0.0f and 1.0f that we should multiply against the XPerSecond or YPerSecond value to know how many units we should move in this Update frame. </summary>
private float GetPerSecondFactor(Easing[] easings, float currentPercent)
{
if (easings == null || !easings.Any())
return 1.0f;
Easing? closestEasing = null;
if (easings[0].StartPercent > currentPercent)
{
// We're before the first easing we have, so we'll use the first easing's initial speed.
return easings[0].StartPerSecondPercent;
}
foreach (var easing in easings)
{
if (easing.StartPercent <= currentPercent)
{
if (easing.EndPercent >= currentPercent)
{
//return easing.EndPerSecondPercent;
// We're somewhere within this Easing, so let's get the specific percent of the PerSecond value we should be using.
// (Current - Start) / (End - Start)
// Example: 0.0 to 0.5, current at 0.2 -> (0.2 - 0.0) / (0.5 - 0.0) -> 0.2 / 0.5 = 0.4f
// Example: 0.5 to 0.75, current at 0.67 -> (0.67 - 0.5) / (0.75 - 0.5) -> 0.17 / 0.25 = 0.68f
// Taking this value gives us how much of the PerSecond we should be using for this round. However, the full PerSecond
// is also eased between the Start and End time slot, so we'll use the formula to determine how much of the full PerSecond
// we should be using.
var perSecondPercent = (currentPercent - easing.StartPercent) / (easing.EndPercent - easing.StartPercent);
// The below examples work for Acceleration and Deceleration)
// Accel (0.25 to 0.8 at 0% time): 0.0f * (0.8 - 0.25) + 0.25 = 0.0 * 0.55f + 0.25 = 0.0f + 0.25 = 0.25 = 25.0% of the YPerSecond for this frame.
// (0.25 to 0.8 at 20% time): 0.2f * (0.8 - 0.25) + 0.25 = 0.2 * 0.55f + 0.25 = 0.11f + 0.25 = 0.36 = 36.0% of the YPerSecond for this frame.
// (0.25 to 0.8 at 50% time): 0.5f * (0.8 - 0.25) + 0.25 = 0.5 * 0.55f + 0.25 = 0.275f + 0.25 = 0.525 = 52.5% of the YPerSecond for this frame.
// (0.25 to 0.8 at 80% time): 0.8f * (0.8 - 0.25) + 0.25 = 0.8 * 0.55f + 0.25 = 0.44f + 0.25 = 0.69 = 69.0% of the YPerSecond for this frame.
// (0.25 to 0.8 at 100% time): 1.0f * (0.8 - 0.25) + 0.25 = 1.0 * 0.55f + 0.25 = 0.55f + 0.25 = 0.8 = 80.0% of the YPerSecond for this frame.
// Deccel (0.8 to 0.25 at 0% time): 0.0f * (0.25 - 0.8) + 0.8 = 0.0 * -0.55f + 0.8 = 0.0f + 0.8 = 0.8 = 25.0% of the YPerSecond for this frame.
// (0.8 to 0.25 at 20% time): 0.2f * (0.25 - 0.8) + 0.8 = 0.2 * -0.55f + 0.8 = -0.11f + 0.8 = 0.69 = 69.0% of the YPerSecond for this frame.
// (0.8 to 0.25 at 50% time): 0.5f * (0.25 - 0.8) + 0.8 = 0.5 * -0.55f + 0.8 = -0.275f + 0.8 = 0.525 = 52.5% of the YPerSecond for this frame.
// (0.8 to 0.25 at 80% time): 0.8f * (0.25 - 0.8) + 0.8 = 0.8 * -0.55f + 0.8 = -0.44f + 0.8 = 0.36 = 36.0% of the YPerSecond for this frame.
// (0.8 to 0.25 at 100% time): 1.0f * (0.25 - 0.8) + 0.8 = 1.0 * -0.55f + 0.8 = -0.55f + 0.8 = 0.25 = 25.0% of the YPerSecond for this frame.
return (perSecondPercent * (easing.EndPerSecondPercent - easing.StartPerSecondPercent)) + easing.StartPerSecondPercent;
}
else
{
// We're beyond the End of the easing, so this will be our new 'Closest' one to where we're at.
closestEasing = easing;
}
}
}
// This easing is the last one where we passed the End but didn't fall into another bucket, so we'll go at the max of this easing bracket, if any. Otherwise, max speed.
if (closestEasing.HasValue)
{
return closestEasing.Value.EndPerSecondPercent;
}
return 1.0f;
}