Last active
August 29, 2015 14:06
-
-
Save TarasOsiris/0a7fe3bbac6d928930ab to your computer and use it in GitHub Desktop.
Looped Enum List for Unity3D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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