Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace GameCore.Utilities
- {
- using Extentions;
- [Serializable]
- public class RandomStack<T>
- {
- private IEnumerable<T> RandCollection;
- private IEnumerable<T> StarCollection;
- private Stack<T> Stack;
- private T LastRandom;
- public RandomStack(params T [] colection)
- {
- RandCollection = new List<T>(colection);
- StarCollection = colection;
- }
- public RandomStack(IEnumerable<T> colection)
- {
- RandCollection = new List<T>(colection);
- StarCollection = colection;
- }
- public T Get()
- {
- if (StarCollection.Count() == 1)
- return StarCollection.ElementAt(0);
- if (RandCollection.Count() == 0)
- RandCollection = new List<T>(StarCollection);
- T rand;
- do
- {
- rand = RandCollection.GetRandom();
- }
- while (rand.Equals(LastRandom));
- Remove(rand);
- LastRandom = rand;
- return rand;
- }
- private void Remove(T rand)
- {
- List<T> list = RandCollection.ToList();
- list.Remove(rand);
- RandCollection = new List<T>(list);
- list.Clear();
- }
- public void Log()
- {
- UnityEngine.Debug.Log("StarCollection");
- StarCollection.Log();
- UnityEngine.Debug.Log("RandCollection");
- RandCollection.Log();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement