Entitas  0.35.0
Entitas is a super fast Entity Component System (ECS) Framework specifically made for C# and Unity
OldPoolsGenerator.cs
1 using System.Linq;
2 using System;
3 
4 namespace Entitas.CodeGenerator {
5 
6  [Obsolete("Since 0.32.0. It's recommended to use the new PoolsGenerator. Use the OldPoolsGeneratorFor only for existing project.")]
8 
9  const string CLASS_TEMPLATE = @"using Entitas;
10 
11 public static class Pools {{
12 {0}{1}
13 }}";
14 
15  const string ALL_POOLS_GETTER = @"
16  static Pool[] _allPools;
17 
18  public static Pool[] allPools {{
19  get {{
20  if(_allPools == null) {{
21  _allPools = new [] {{ {0} }};
22  }}
23  return _allPools;
24  }}
25  }} ";
26 
27  const string GETTER = @"
28 
29  static Pool _{0};
30 
31  public static Pool {0} {{
32  get {{
33  if(_{0} == null) {{
34  _{0} = new Pool({1}.TotalComponents, 0, new PoolMetaData(""{2}Pool"", {1}.componentNames, {1}.componentTypes));
35  #if(!ENTITAS_DISABLE_VISUAL_DEBUGGING && UNITY_EDITOR)
36  if(UnityEngine.Application.isPlaying) {{
37  var poolObserver = new Entitas.Unity.VisualDebugging.PoolObserver(_{0});
38  UnityEngine.Object.DontDestroyOnLoad(poolObserver.entitiesContainer);
39  }}
40  #endif
41  }}
42 
43  return _{0};
44  }}
45  }}";
46  public CodeGenFile[] Generate(string[] poolNames) {
47  var allPools = string.Format(ALL_POOLS_GETTER,
48  string.Join(", ", poolNames.Select(poolName => poolName.LowercaseFirst()).ToArray()));
49 
50  var getters = poolNames.Aggregate(string.Empty, (acc, poolName) =>
51  acc + string.Format(GETTER, poolName.LowercaseFirst(), poolName.PoolPrefix() + CodeGenerator.DEFAULT_COMPONENT_LOOKUP_TAG,
52  poolName.IsDefaultPoolName() ? string.Empty : poolName.PoolPrefix() + " "));
53 
54  return new [] { new CodeGenFile(
55  "Pools",
56  string.Format(CLASS_TEMPLATE, allPools, getters).ToUnixLineEndings(),
57  GetType().FullName
58  )
59  };
60  }
61  }
62 }