Ejemplo n.º 1
0
        /// <summary>
        /// Overload: Gets the next random entry. Refills depending on passed LotteryMode.
        /// </summary>
        /// <param name="mode">The mode to determine how to behave, when copied list is empty.</param>
        /// <returns>Returns next entry or default(T), depending on mode.</returns>
        public T DrawNext(LotteryMode mode)
        {
            if (IsEmtpy())
            {
                switch (mode)
                {
                case LotteryMode.RefillOnEmpty:
                    CopyEntries();
                    break;

                case LotteryMode.RemoveOnEmpty:
                    LotteryManager <T> .Remove(Collection);

                    return(default(T));

                case LotteryMode.None:
                    return(default(T));
                }
            }
            var id   = UnityEngine.Random.Range(0, CollectionCopy.Count);
            var temp = CollectionCopy[id];

            CollectionCopy.Remove(CollectionCopy[id]);
            return(temp);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Removes all collections from the dictionary.
 /// </summary>
 public static void Clear <T> (this IList <T> collection)
 {
     LotteryManager <T> .Clear();
 }
Ejemplo n.º 3
0
 // Returns true, if all elements of the passed IList<T> have been returned once
 public static bool IsEmpty <T>(this IList <T> collection)
 {
     return(LotteryManager <T> .IsEmpty(collection));
 }
Ejemplo n.º 4
0
 // Disables remembering which elements of the passed IList<T> have been already returned
 // by removing from an internal tracking dictionary
 public static void Remove <T>(this IList <T> collection)
 {
     Debug.Log("Removed: " + collection.GetType());
     LotteryManager <T> .Remove(collection);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// ExtensionMethod for calling DrawNext() function in LotteryManager.
 /// </summary>
 /// <param name="collection">The iList from which an entry should be returned.</param>
 /// <returns>Returns next list entry that has not been returned yet.</returns>
 public static T DrawNext <T>(this IList <T> collection)
 {
     return(LotteryManager <T> .DrawNext(collection));
 }