Skip to content

Instantly share code, notes, and snippets.

@KumoKairo
Last active January 22, 2018 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KumoKairo/5f6bb2ffe9ebde664a5a9c7ec7aa899c to your computer and use it in GitHub Desktop.
Save KumoKairo/5f6bb2ffe9ebde664a5a9c7ec7aa899c to your computer and use it in GitHub Desktop.
class EcsComponentPool<T> : IEcsComponentPool where T : class, new ()
{
public static readonly EcsComponentPool<T> Instance = new EcsComponentPool<T> ();
private Func<T> _factory;
public void MapFactory(Func<T> factory)
{
_factory = factory;
}
public int GetIndex () {
... всякая мишура
...
T item;
if(_factory != null)
{
item = _factory();
}
else
{
item = new T();
}
Items[_itemsCount++] = item;
return id;
}
}
...
public class SomeInitializeSystem
{
public void Initialize()
{
EcsComponentPool<MySuperComponent>.Instance.MapFactory(() => new MySuperComponent());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment