You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// A collection of extension methods for <see cref="IEnumerable{T}"/>, <see cref="List{T}"/> and arrays.
10
+
/// </summary>
11
+
publicstaticclassLINQExtensions
12
+
{
13
+
/// <summary>
14
+
/// Takes a collection, generates values from the items and and returns the item with the lowest generated value.
15
+
/// Useful for example to find the closest item. Reverse the generated values to find the item with the highest generated value.
16
+
///
17
+
/// This returns the same as list.Where(element => predicateValue(valueConverter(element))).OrderBy(valueConverter).First(), but it
18
+
/// a) doesn't need to order the whole list and
19
+
/// b) doesn't need to call valueConverted more than once per element.
20
+
/// </summary>
21
+
/// <typeparam name="TElement">The collection element type.</typeparam>
22
+
/// <typeparam name="TValue">The generated value type.</typeparam>
23
+
/// <param name="list">The list of elements.</param>
24
+
/// <param name="valueConverter">The method to convert an element to a generated value used for ordering.</param>
25
+
/// <param name="predicateValue">A predicate testing whether the generated value is permitted. If true, the element is used; if false, the element is skipped.</param>
26
+
/// <returns>The first element by the generated value in order that succeeded the predicateValue test.</returns>
Copy file name to clipboardExpand all lines: README.md
+6-3Lines changed: 6 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,8 +8,10 @@ If you find any bugs or have suggestions, please add an [Issue](https://github.c
8
8
9
9
## Overview
10
10
*[Countdown](https://github.com/TobiasWehrum/unity-utilities/tree/master/Countdown): Useful for things like cooldowns or spawn delays. It is also helpful for tweening things by using the `PercentElapsed` property.
11
+
*[LINQExtensions](https://github.com/TobiasWehrum/unity-utilities/tree/master/LINQExtensions): A collection of extension methods for `IEnumerable`s, `List`s and arrays.
11
12
*[NoiseOutputValue](https://github.com/TobiasWehrum/unity-utilities/tree/master/NoiseOutputValue): Enter a range and a speed in the editor, get an output value that fluctuates over time using [Perlin Noise](http://docs.unity3d.com/ScriptReference/Mathf.PerlinNoise.html).
12
-
*[Range](https://github.com/TobiasWehrum/unity-utilities/tree/master/Range): Editable data types that takes an int/float range. Used for things like "Spawn 2 to 4 enemies."
13
+
*[RandomBag](https://github.com/TobiasWehrum/unity-utilities/tree/master/RandomBag): A `RandomBag` gives you random items from a group while ensuring that in a certain interval every item was given back the same number of times.
14
+
*[Range](https://github.com/TobiasWehrum/unity-utilities/tree/master/Range): Editable data types that take an `int`/`float` range. Used for things like "Spawn 2 to 4 enemies."
13
15
*[Singleton](https://github.com/TobiasWehrum/unity-utilities/tree/master/Singleton): Allows easy and convenient creation of a Singleton. Optionally makes a Singleton persist between scenes while ensuring that only one exists.
14
16
15
17
## Usage
@@ -23,5 +25,6 @@ You can also just use selected scripts, but you should check the "Dependencies"
23
25
The class documentation is available [here](http://tobiaswehrum.github.io/UnityUtilities/html/annotated.html).
24
26
25
27
## Changelog
26
-
* 2015-05-09: Added the [class documentation website](http://tobiaswehrum.github.io/UnityUtilities/html/annotated.html).
27
-
* 2015-05-08: Added [Countdown](https://github.com/TobiasWehrum/unity-utilities/tree/master/Countdown), [NoiseOutputValue](https://github.com/TobiasWehrum/unity-utilities/tree/master/NoiseOutputValue), [Range](https://github.com/TobiasWehrum/unity-utilities/tree/master/Range) and [Singleton](https://github.com/TobiasWehrum/unity-utilities/tree/master/Singleton).
28
+
* 2016-05-15: Added [LINQExtensions](https://github.com/TobiasWehrum/unity-utilities/tree/master/LINQExtensions) and [RandomBag](https://github.com/TobiasWehrum/unity-utilities/tree/master/RandomBag).
29
+
* 2016-05-09: Added the [class documentation website](http://tobiaswehrum.github.io/UnityUtilities/html/annotated.html).
30
+
* 2016-05-08: Added [Countdown](https://github.com/TobiasWehrum/unity-utilities/tree/master/Countdown), [NoiseOutputValue](https://github.com/TobiasWehrum/unity-utilities/tree/master/NoiseOutputValue), [Range](https://github.com/TobiasWehrum/unity-utilities/tree/master/Range) and [Singleton](https://github.com/TobiasWehrum/unity-utilities/tree/master/Singleton).
A RandomBag ensures that per interval [fillings * itemCount], every different item in it will be given back [fillings] times. Once the bag is empty, it is automatically refilled, either from a fixed array or by calling a delegate.
4
+
5
+
An example for that is used in [some implementations of Tetris](http://tetris.wikia.com/wiki/Random_Generator). The bag is filled with one instance (fillings=1) of each of the seven different pieces. Every time the next piece is needed, a random one is taken out of the bag until the bag is empty. That way, any two pieces are never longer than 14 pulls apart - and even that is only the case if the first and the last piece in the bag are the same one.
0 commit comments