Last active
January 22, 2018 19:37
-
-
Save KumoKairo/5f6bb2ffe9ebde664a5a9c7ec7aa899c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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