Struct Range
Represents a closed mathematical interval of float values
Namespace: Atlas
Assembly: Atlas.Runtime.dll
Syntax
[Serializable]
public struct Range
Examples
using UnityEngine;
namespace Atlas.Examples
{
public sealed class Example_Range
{
// generic character class
public class Character
{
public void ApplyDamage( float damage ) { /* ... */ }
}
public void OnCharacterHit( Character hitCharacter )
{
// get randomized damage amount
float damageAmount = m_damageRange.GetRandomValue();
// apply damage
hitCharacter.ApplyDamage( damageAmount );
}
// range declaration
[SerializeField] private Range m_damageRange
= new Range() { m_minValue = 6f, m_maxValue = 20f };
}
}
Fields
| Improve this Doc View Sourcem_maxValue
The maximum value of the range (inclusive)
Declaration
public float m_maxValue
Field Value
Type | Description |
---|---|
System.Single |
m_minValue
The minimum value of the range (inclusive)
Declaration
public float m_minValue
Field Value
Type | Description |
---|---|
System.Single |
Methods
| Improve this Doc View SourceClamp(Single)
Clamps the given value
between the range
Declaration
public float Clamp(float value)
Parameters
Type | Name | Description |
---|---|---|
System.Single | value | The value to clamp |
Returns
Type | Description |
---|---|
System.Single | If the value is within the range, the value is returned unchanged. Otherwise, a value clamped to the range limits is returned. |
Contains(Range)
Determines whether or not the given range
value is contained within this
numerical range (inclusive)
Declaration
public bool Contains(Range range)
Parameters
Type | Name | Description |
---|---|---|
Range | range | The range value to determine |
Returns
Type | Description |
---|---|
System.Boolean | Whether or not the range value is contained |
Contains(Single)
Determines whether or not the given value
is within this numerical range (inclusive)
Declaration
public bool Contains(float value)
Parameters
Type | Name | Description |
---|---|---|
System.Single | value | The value to determine |
Returns
Type | Description |
---|---|
System.Boolean | Whether or not the value is within the range |
GetLerpedValue(Single)
Returns a linearly interpolated value between m_minValue and m_maxValue
where an input t
of 0 will return m_minValue, and an input of 1 will
return m_maxValue
Declaration
public float GetLerpedValue(float t)
Parameters
Type | Name | Description |
---|---|---|
System.Single | t | The value to interpulate normalized to [0, 1] |
Returns
Type | Description |
---|---|
System.Single | The linearly interpolated value |
GetNormalizedValue(Single)
Calculates a value representing the normalized position of the provided value
within the range, clamped to [0, 1]
Declaration
public float GetNormalizedValue(float value)
Parameters
Type | Name | Description |
---|---|---|
System.Single | value | The value to normalize |
Returns
Type | Description |
---|---|
System.Single | The normalized value |
GetRandomValue()
Returns a random number between m_minValue (inclusive) and m_maxValue (inclusive)
Declaration
public float GetRandomValue()
Returns
Type | Description |
---|---|
System.Single | A random value within the range |
IntersectionWith(Range)
Calculates the range of values where this range overlaps with the given range
.
If the ranges don't overlap, an invalid range is returned.
Declaration
public Range IntersectionWith(Range range)
Parameters
Type | Name | Description |
---|---|---|
Range | range | The range to intersect with |
Returns
Type | Description |
---|---|
Range | The intersecting range |
Intersects(Range)
Determines whether or not the given range
value overlaps this range
Declaration
public bool Intersects(Range range)
Parameters
Type | Name | Description |
---|---|---|
Range | range | The range value to test |
Returns
Type | Description |
---|---|
System.Boolean | Whether or not the ranges overlap eachother |
UnionWith(Range)
Combines the range with the given range
into a mathematical union, creating
a range that spans both ranges
Declaration
public Range UnionWith(Range range)
Parameters
Type | Name | Description |
---|---|---|
Range | range | The range to union with |
Returns
Type | Description |
---|---|
Range | The combined range |