2 using System.Collections.Generic;
10 if(_indices == null) {
11 _indices = mergeIndices();
17 public int[] allOfIndices {
get {
return _allOfIndices; } }
18 public int[] anyOfIndices {
get {
return _anyOfIndices; } }
19 public int[] noneOfIndices {
get {
return _noneOfIndices; } }
30 _anyOfIndices = distinctIndices(indices);
40 _noneOfIndices = distinctIndices(indices);
46 return NoneOf(mergeIndices(matchers));
49 public bool Matches(
Entity entity) {
50 return (_allOfIndices == null || entity.
HasComponents(_allOfIndices))
55 int[] mergeIndices() {
58 if(_allOfIndices != null) {
59 indicesList.AddRange(_allOfIndices);
61 if(_anyOfIndices != null) {
62 indicesList.AddRange(_anyOfIndices);
64 if(_noneOfIndices != null) {
65 indicesList.AddRange(_noneOfIndices);
68 var mergedIndices = distinctIndices(indicesList);
75 static int[] mergeIndices(
IMatcher[] matchers) {
76 var indices =
new int[matchers.Length];
77 for (
int i = 0; i < matchers.Length; i++) {
78 var matcher = matchers[i];
79 if(matcher.indices.Length != 1) {
82 indices[i] = matcher.indices[0];
88 static string[] getComponentNames(
IMatcher[] matchers) {
89 for (
int i = 0; i < matchers.Length; i++) {
90 var matcher = matchers[i] as
Matcher;
91 if(matcher != null && matcher.componentNames != null) {
92 return matcher.componentNames;
100 var componentNames = getComponentNames(matchers);
101 if(componentNames != null) {
102 matcher.componentNames = componentNames;
106 static int[] distinctIndices(IList<int> indices) {
109 foreach(var index
in indices) {
110 indicesSet.Add(index);
112 var uniqueIndices =
new int[indicesSet.Count];
113 indicesSet.CopyTo(uniqueIndices);
114 Array.Sort(uniqueIndices);
118 return uniqueIndices;
124 "matcher.indices.Length must be 1 but was " + matcher.indices.Length) {
bool HasComponents(int[] indices)
bool HasAnyComponent(int[] indices)