Entitas  0.40.0
Entitas is a super fast Entity Component System (ECS) Framework specifically made for C# and Unity
Matcher.cs
1 namespace Entitas {
2 
3  public partial class Matcher<TEntity> : IAllOfMatcher<TEntity> where TEntity : class, IEntity, new() {
4 
5  public int[] indices {
6  get {
7  if(_indices == null) {
8  _indices = mergeIndices(_allOfIndices, _anyOfIndices, _noneOfIndices);
9  }
10  return _indices;
11  }
12  }
13 
14  public int[] allOfIndices { get { return _allOfIndices; } }
15  public int[] anyOfIndices { get { return _anyOfIndices; } }
16  public int[] noneOfIndices { get { return _noneOfIndices; } }
17 
18  public string[] componentNames { get; set; }
19 
20  int[] _indices;
21  int[] _allOfIndices;
22  int[] _anyOfIndices;
23  int[] _noneOfIndices;
24 
25  Matcher() {
26  }
27 
28  IAnyOfMatcher<TEntity> IAllOfMatcher<TEntity>.AnyOf(params int[] indices) {
29  _anyOfIndices = distinctIndices(indices);
30  _indices = null;
31  _isHashCached = false;
32  return this;
33  }
34 
36  return ((IAllOfMatcher<TEntity>)this).AnyOf(mergeIndices(matchers));
37  }
38 
39  public INoneOfMatcher<TEntity> NoneOf(params int[] indices) {
40  _noneOfIndices = distinctIndices(indices);
41  _indices = null;
42  _isHashCached = false;
43  return this;
44  }
45 
46  public INoneOfMatcher<TEntity> NoneOf(params IMatcher<TEntity>[] matchers) {
47  return NoneOf(mergeIndices(matchers));
48  }
49 
50  public bool Matches(TEntity entity) {
51  return (_allOfIndices == null || entity.HasComponents(_allOfIndices))
52  && (_anyOfIndices == null || entity.HasAnyComponent(_anyOfIndices))
53  && (_noneOfIndices == null || !entity.HasAnyComponent(_noneOfIndices));
54  }
55  }
56 }