fgm24/Assets/Scripts/Utilities/CircularBuffer.cs

15 lines
424 B
C#

[System.Serializable]
public class CircularBuffer<T> {
public T[] buffer;
public int bufferSize;
public CircularBuffer(int bufferSize) {
this.bufferSize = bufferSize;
buffer = new T[bufferSize];
}
public void Add(T item, int index) => buffer[index % bufferSize] = item;
public T Get(int index) => buffer[index % bufferSize];
public void Clear() => buffer = new T[bufferSize];
}