Entitas  0.35.0
Entitas is a super fast Entity Component System (ECS) Framework specifically made for C# and Unity
MatcherToString.cs
1 using System.Text;
2 
3 namespace Entitas {
4 
5  public partial class Matcher {
6 
7  public string[] componentNames;
8 
9  string _toStringCache;
10 
11  public override string ToString() {
12  if(_toStringCache == null) {
13  var sb = new StringBuilder();
14  if(_allOfIndices != null) {
15  appendIndices(sb, "AllOf", _allOfIndices, componentNames);
16  }
17  if(_anyOfIndices != null) {
18  if(_allOfIndices != null) {
19  sb.Append(".");
20  }
21  appendIndices(sb, "AnyOf", _anyOfIndices, componentNames);
22  }
23  if(_noneOfIndices != null) {
24  appendIndices(sb, ".NoneOf", _noneOfIndices, componentNames);
25  }
26  _toStringCache = sb.ToString();
27  }
28 
29  return _toStringCache;
30  }
31 
32  static void appendIndices(StringBuilder sb, string prefix, int[] indexArray, string[] componentNames) {
33  const string separator = ", ";
34  sb.Append(prefix);
35  sb.Append("(");
36  var lastSeparator = indexArray.Length - 1;
37  for (int i = 0; i < indexArray.Length; i++) {
38  var index = indexArray[i];
39  if(componentNames == null) {
40  sb.Append(index);
41  } else {
42  sb.Append(componentNames[index]);
43  }
44 
45  if(i < lastSeparator) {
46  sb.Append(separator);
47  }
48  }
49  sb.Append(")");
50  }
51  }
52 }