soundvision/UnityProject/Assets/Scripts/Math/BodyHolder.cs

45 lines
1 KiB
C#
Raw Normal View History

2019-11-03 12:29:35 +00:00
using System.Collections.Generic;
2019-11-03 14:19:11 +00:00
using Windows.Kinect;
2019-11-03 12:29:35 +00:00
namespace cylvester
{
2019-11-03 14:19:11 +00:00
public class BodyHolder
2019-11-03 12:29:35 +00:00
{
2019-11-03 14:19:11 +00:00
private readonly List<Body> elements_;
2019-11-03 12:29:35 +00:00
private readonly int capacity_;
2019-11-03 14:19:11 +00:00
public BodyHolder(int capacity)
2019-11-03 12:29:35 +00:00
{
capacity_ = capacity;
2019-11-03 14:19:11 +00:00
elements_ = new List<Body>();
2019-11-03 12:29:35 +00:00
}
2019-11-03 14:19:11 +00:00
public bool Add(Body newBody)
2019-11-03 12:29:35 +00:00
{
if (elements_.Count == capacity_)
return false;
2019-11-03 14:19:11 +00:00
if (elements_.Contains(newBody))
2019-11-03 12:29:35 +00:00
return false;
2019-11-03 14:19:11 +00:00
elements_.Add(newBody);
2019-11-03 12:29:35 +00:00
return true;
}
2019-11-03 14:19:11 +00:00
public bool Exist(Body element)
2019-11-03 12:29:35 +00:00
{
return elements_.Contains(element);
}
2019-11-03 14:19:11 +00:00
public int? IndexOf(Body element)
2019-11-03 12:29:35 +00:00
{
var index = elements_.FindIndex(e => e.Equals(element));
return (index < 0) ? (int?) null : index;
}
2019-11-03 14:19:11 +00:00
public void Remove(Body element)
2019-11-03 12:29:35 +00:00
{
elements_.Remove(element);
}
}
}