public virtual Group GetGroup(IMatcher matcher)
{
Group group;
if (!_groups.TryGetValue(matcher, out group))
{
group = new Group(matcher);
var entities = GetEntities();
for (int i = 0, entitiesLength = entities.Length; i < entitiesLength; i++)
{
group.HandleEntity(entities[i]);
}
_groups.Add(matcher, group);
for (int i = 0, indicesLength = matcher.indices.Length; i < indicesLength; i++)
{
var index = matcher.indices[i];
if (_groupsForIndex[index] == null)
{
_groupsForIndex[index] = new List <Group>();
}
_groupsForIndex[index].Add(group);
}
if (OnGroupCreated != null)
{
OnGroupCreated(this, group);
}
}
return(group);
}