Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public abstract class ObjectPool<T> where T : PoolingObject
- {
- protected List<T> objects;
- public List<T> Objects => objects;
- protected Factory<T> factory;
- protected void Initialize(int count)
- {
- objects = factory.GetItems(count);
- }
- public virtual T GetObject()
- {
- if(objects.Count == 0)
- {
- objects.Add(factory.CreateItem());
- }
- T obj = objects[0];
- objects.RemoveAt(0);
- obj.GetFromPool();
- return obj;
- }
- public void ReturnObject(T obj)
- {
- objects.Add(obj);
- obj.ReturnToPool();
- }
- }
- public class LineItemPool : ObjectPool<LineItem>
- {
- public LineItemPool(VerticalLine parent, LineItem prefab, int count)
- {
- factory = new PlatformsFactory(parent, prefab);
- Initialize(count);
- }
- public LineItemParametrs GetNewParametrs()
- {
- return (factory as PlatformsFactory).GetRandomParametrs();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement