using UnityEngine;
namespace FirstGearGames.Utilities.Maths
{
///
/// Various utility classes relating to floats.
///
public static class Ints
{
private static System.Random _random = new System.Random();
///
/// Pads an index a specified value. Preferred over typical padding so that pad values used with skins can be easily found in the code.
///
///
///
///
public static string PadInt(int value, int padding)
{
return value.ToString().PadLeft(padding, '0');
}
///
/// Provides a random inclusive int within a given range. Preferred over Unity's Random to eliminate confusion as Unity uses inclusive for floats max, and exclusive for int max.
///
/// Inclusive minimum value.
/// Inclusive maximum value.
///
public static int RandomInclusiveRange(int minimum, int maximum)
{
return _random.Next(minimum, maximum + 1);
}
///
/// Provides a random exclusive int within a given range. Preferred over Unity's Random to eliminate confusion as Unity uses inclusive for floats max, and exclusive for int max.
///
/// Inclusive minimum value.
/// Exclusive maximum value.
///
public static int RandomExclusiveRange(int minimum, int maximum)
{
return _random.Next(minimum, maximum);
}
///
/// Returns a clamped int within a specified range.
///
/// Value to clamp.
/// Minimum value.
/// Maximum value.
///
public static int Clamp(int value, int minimum, int maximum)
{
if (value < minimum)
value = minimum;
else if (value > maximum)
value = maximum;
return value;
}
///
/// Determins if all values passed in are the same.
///
/// Values to check.
/// True if all values are the same.
public static bool ValuesMatch(params int[] values)
{
if (values.Length == 0)
{
Debug.Log("Ints -> ValuesMatch -> values array is empty.");
return false;
}
//Assign first value as element in first array.
int firstValue = values[0];
//Check all values.
for (int i = 1; i < values.Length; i++)
{
//If any value doesn't match first value return false.
if (firstValue != values[i])
return false;
}
//If this far all values match.
return true;
}
}
}