Entitas  0.40.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<TEntity> {
6 
7  string _toStringCache;
8  StringBuilder _toStringBuilder;
9 
10  public override string ToString() {
11  if(_toStringCache == null) {
12  if(_toStringBuilder == null) {
13  _toStringBuilder = new StringBuilder();
14  }
15  _toStringBuilder.Length = 0;
16  if(_allOfIndices != null) {
17  appendIndices(_toStringBuilder, "AllOf", _allOfIndices, componentNames);
18  }
19  if(_anyOfIndices != null) {
20  if(_allOfIndices != null) {
21  _toStringBuilder.Append(".");
22  }
23  appendIndices(_toStringBuilder, "AnyOf", _anyOfIndices, componentNames);
24  }
25  if(_noneOfIndices != null) {
26  appendIndices(_toStringBuilder, ".NoneOf", _noneOfIndices, componentNames);
27  }
28  _toStringCache = _toStringBuilder.ToString();
29  }
30 
31  return _toStringCache;
32  }
33 
34  static void appendIndices(StringBuilder sb, string prefix, int[] indexArray, string[] componentNames) {
35  const string separator = ", ";
36  sb.Append(prefix);
37  sb.Append("(");
38  var lastSeparator = indexArray.Length - 1;
39  for (int i = 0; i < indexArray.Length; i++) {
40  var index = indexArray[i];
41  if(componentNames == null) {
42  sb.Append(index);
43  } else {
44  sb.Append(componentNames[index]);
45  }
46 
47  if(i < lastSeparator) {
48  sb.Append(separator);
49  }
50  }
51  sb.Append(")");
52  }
53  }
54 }