Able
Askowl Base Library Enabler
Range.cs
1 // With thanks to Jason Weimann -- jason@unity3d.college
2 
3 using System;
4 using UnityEngine;
5 using Random = UnityEngine.Random;
6 
7 namespace Askowl {
8  /// <a href="http://bit.ly/2OuGzAF">Simple class to represent the high and low bounds for a float. It includes a picker to randomly choose a number within that range</a> <inheritdoc />
9  [Serializable] public class Range : Pick<float> {
10  [SerializeField] private float min;
11  [SerializeField] private float max;
12 
13  /// <a href="http://bit.ly/2OuGzAF">Lowest value a number can have in this range</a>
14  public float Min { get => min; set => min = value; }
15 
16  /// <a href="http://bit.ly/2OuGzAF">Highest value a number can have in this range</a>
17  public float Max { get => max; set => max = value; }
18 
19  /// <a href="http://bit.ly/2OuGzAF">Default constructor used when the range is set in a MonoBehaviour in the Unity Editor</a>
20  public Range() { }
21 
22  /// <a href="http://bit.ly/2OuGzAF">Constructor used to set the range directly or as initialisation for MonoBehaviour data</a>
23  public Range(float min, float max) {
24  Min = min;
25  Max = max;
26  }
27 
28  /// <a href="http://bit.ly/2OuGzAF">Choose a random number within the inclusive range</a> <inheritdoc />
29  public float Pick() => Random.Range(min, max);
30  }
31 
32  /// <a href="http://bit.ly/2NTC1o1">Used for `Range` variable in the Unity Editor to set the maximum bounds they can be set to</a>
33  public class RangeBoundsAttribute : Attribute {
34  /// <a href="http://bit.ly/2NTC1o1">[SerializeField, RangeBounds(0, 999)] private Range distance = new Range(1, 999);</a>
35  public RangeBoundsAttribute(float min, float max) {
36  Min = min;
37  Max = max;
38  }
39 
40  /// <a href="http://bit.ly/2NTC1o1">Used by RangeDrawer exclusively</a>
41  public float Max { get; }
42 
43  /// <a href="http://bit.ly/2NTC1o1">Used by RangeDrawer exclusively</a>
44  public float Min { get; }
45  }
46 }
Definition: Clock.cs:3
RangeBoundsAttribute(float min, float max)
[SerializeField, RangeBounds(0, 999)] private Range distance = new Range(1, 999); ...
Definition: Range.cs:35
float Min
Lowest value a number can have in this range
Definition: Range.cs:14
Simple class to represent the high and low bounds for a float. It includes a picker to randomly choos...
Definition: Range.cs:9
float Min
Used by RangeDrawer exclusively
Definition: Range.cs:44
Used for Range variable in the Unity Editor to set the maximum bounds they can be set to ...
Definition: Range.cs:33
Range(float min, float max)
Constructor used to set the range directly or as initialisation for MonoBehaviour data ...
Definition: Range.cs:23
Range()
Default constructor used when the range is set in a MonoBehaviour in the Unity Editor ...
Definition: Range.cs:20
float Max
Highest value a number can have in this range
Definition: Range.cs:17
float Pick()
Choose a random number within the inclusive range
Interface so that code can use a picker without know more about the source. A picker returns a value ...
Definition: Pick.cs:5
float Max
Used by RangeDrawer exclusively
Definition: Range.cs:41