Skip to content

Instantly share code, notes, and snippets.

@TarasOsiris
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TarasOsiris/0a7fe3bbac6d928930ab to your computer and use it in GitHub Desktop.
Save TarasOsiris/0a7fe3bbac6d928930ab to your computer and use it in GitHub Desktop.
Looped Enum List for Unity3D
using System.Collections.Generic;
using System;
using UnityEngine;
public class LoopedEnumList<T>
{
private readonly List<T> _items;
private readonly int _startIndex;
private int _currentIndex;
public List<T> EquipItems {
get {
return _items;
}
}
public LoopedEnumList()
{
_items = new List<T>();
foreach (T item in Enum.GetValues(typeof(T)))
{
_items.Add(item);
Debug.Log(item.ToString());
}
_startIndex = UnityEngine.Random.Range(0, _items.Count);
_currentIndex = _startIndex;
}
public T GetNextItem()
{
_currentIndex++;
if (_currentIndex == _items.Count)
{
_currentIndex = 0;
return _items[0];
}
return _items[_currentIndex];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment