Class Floats
Inheritance
Inherited Members
Namespace: GameKit.Dependencies.Utilities
Assembly: GameKit.Dependencies.dll
Syntax
public static class Floats
Methods
Clamp(Single, Single, Single, ref Boolean)
Clamps a float and returns if the float required clamping.
Declaration
public static float Clamp(float value, float min, float max, ref bool clamped)
Parameters
Type | Name | Description |
---|---|---|
System.Single | value | |
System.Single | min | |
System.Single | max | |
System.Boolean | clamped |
Returns
Type | Description |
---|---|
System.Single |
InRange(Single, Single, Single)
Returns if a float is within a range.
Declaration
public static bool InRange(this float source, float rangeMin, float rangeMax)
Parameters
Type | Name | Description |
---|---|---|
System.Single | source | Value of float. |
System.Single | rangeMin | Minimum of range. |
System.Single | rangeMax | Maximum of range. |
Returns
Type | Description |
---|---|
System.Boolean |
Near(Single, Single, Single)
Returns if a target float is within variance of the source float.
Declaration
public static bool Near(this float a, float b, float tolerance = 0.01F)
Parameters
Type | Name | Description |
---|---|---|
System.Single | a | |
System.Single | b | |
System.Single | tolerance |
Returns
Type | Description |
---|---|
System.Boolean |
PreciseSign(Single)
Returns negative-one, zero, or postive-one of a value instead of just negative-one or positive-one.
Declaration
public static float PreciseSign(float value)
Parameters
Type | Name | Description |
---|---|---|
System.Single | value | Value to sign. |
Returns
Type | Description |
---|---|
System.Single | Precise sign. |
Random01()
Returns a random float between 0f and 1f.
Declaration
public static float Random01()
Returns
Type | Description |
---|---|
System.Single |
RandomInclusiveRange(Single, Single)
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.
Declaration
public static float RandomInclusiveRange(float minimum, float maximum)
Parameters
Type | Name | Description |
---|---|---|
System.Single | minimum | Inclusive minimum value. |
System.Single | maximum | Inclusive maximum value. |
Returns
Type | Description |
---|---|
System.Single |
RandomlyFlip(Single)
Randomly flips a float value.
Declaration
public static float RandomlyFlip(this float value)
Parameters
Type | Name | Description |
---|---|---|
System.Single | value |
Returns
Type | Description |
---|---|
System.Single |
SetIfOverTolerance(Single, Single, Single)
Sets a source float to value if equal to or greater than tolerance.
Declaration
public static float SetIfOverTolerance(this float source, float tolerance, float value)
Parameters
Type | Name | Description |
---|---|---|
System.Single | source | Float to check against tolerance. |
System.Single | tolerance | Tolerance float must be equal to or greater than to change to value. |
System.Single | value | Value source is set to when breaking tolerance. |
Returns
Type | Description |
---|---|
System.Single |
SetIfUnderTolerance(Single, Single, Single)
Sets a source float to value if equal to or less than tolerance.
Declaration
public static float SetIfUnderTolerance(this float source, float tolerance, float value)
Parameters
Type | Name | Description |
---|---|---|
System.Single | source | Float to check against tolerance. |
System.Single | tolerance | Tolerance float must be equal to or less than to change to value. |
System.Single | value | Value source is set to when breaking tolerance. |
Returns
Type | Description |
---|---|
System.Single |
TimeRemainingText(Single, Byte, Boolean)
Returns time remaining as a string using hh:mm:ss.
Declaration
public static string TimeRemainingText(this float value, byte segments, bool emptyOnZero = false)
Parameters
Type | Name | Description |
---|---|---|
System.Single | value | |
System.Byte | segments | Number of places to return. 1 is seconds, 2 is minutes, 3 is hours. If a placement does not exist it is replaced with 00. |
System.Boolean | emptyOnZero | True to return an empty string when value is 0 or less. |
Returns
Type | Description |
---|---|
System.String |
TimeRemainingValue(Single)
Returns how much time is left on an endTime. Returns -1 if no time is left.
Declaration
public static float TimeRemainingValue(this float endTime)
Parameters
Type | Name | Description |
---|---|---|
System.Single | endTime |
Returns
Type | Description |
---|---|
System.Single |
TimeRemainingValue(Single, Boolean)
Returns how much time is left on an endTime. Returns -1 if no time is left.
Declaration
public static int TimeRemainingValue(this float endTime, bool useFloor = true)
Parameters
Type | Name | Description |
---|---|---|
System.Single | endTime | |
System.Boolean | useFloor |
Returns
Type | Description |
---|---|
System.Int32 |
Variance(Single, Single)
Returns a float after being adjusted by the specified variance.
Declaration
public static float Variance(this float source, float variance)
Parameters
Type | Name | Description |
---|---|---|
System.Single | source | |
System.Single | variance |
Returns
Type | Description |
---|---|
System.Single |
Variance(Single, Single, ref Single)
Sets a float value to result after being adjusted by the specified variance.
Declaration
public static void Variance(this float source, float variance, ref float result)
Parameters
Type | Name | Description |
---|---|---|
System.Single | source | |
System.Single | variance | |
System.Single | result |