52 lines
983 B
C#
52 lines
983 B
C#
using UnityEngine;
|
|
|
|
namespace EnergyBarToolkit
|
|
{
|
|
public class EnergyBarCommons
|
|
{
|
|
public static void SmoothDisplayValue(ref float displayValue, float target, float speed)
|
|
{
|
|
if (!Application.isPlaying)
|
|
{
|
|
displayValue = target;
|
|
return;
|
|
}
|
|
float num = target - displayValue;
|
|
if (num != 0f)
|
|
{
|
|
float num2 = ((!(num < 0f)) ? speed : (0f - speed));
|
|
num2 *= Time.deltaTime;
|
|
if (Mathf.Abs(num2) > Mathf.Abs(num))
|
|
{
|
|
displayValue = target;
|
|
}
|
|
else
|
|
{
|
|
displayValue += num2;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static bool Blink(float val, float blinkVal, float rate, ref float accum)
|
|
{
|
|
if (val <= blinkVal)
|
|
{
|
|
return Blink(rate, ref accum);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static bool Blink(float rate, ref float accum)
|
|
{
|
|
float num = rate * 2f;
|
|
if (rate > 0f)
|
|
{
|
|
accum += Time.deltaTime;
|
|
int num2 = (int)(accum / (1f / rate));
|
|
accum -= 1f / rate * (float)num2;
|
|
}
|
|
return accum > 1f / num;
|
|
}
|
|
}
|
|
}
|