Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. public abstract class Factory<T> where T : PoolingObject
  2. {
  3.     public List<T> GetItems(int count)
  4.     {
  5.         List<T> lineItems = new List<T>();
  6.         for (int i = 0; i < count; i++)
  7.         {
  8.             lineItems.Add(CreateItem());
  9.         }
  10.  
  11.         return lineItems;
  12.     }
  13.  
  14.     public abstract T CreateItem();
  15.  
  16. }
  17.  
  18. public class PlatformsFactory : Factory<LineItem>
  19. {
  20.     private VerticalLine parent;
  21.     private LineItem prefab;
  22.  
  23.     public PlatformsFactory(VerticalLine parent, LineItem prefab)
  24.     {
  25.         this.parent = parent;
  26.         this.prefab = prefab;
  27.     }
  28.  
  29.     public override LineItem CreateItem()
  30.     {
  31.         LineItem lineItem = GameObject.Instantiate(prefab, parent.transform);
  32.         lineItem.Initialize(parent, GetRandomParametrs());
  33.         return lineItem;
  34.     }
  35.  
  36.     public LineItemParametrs GetRandomParametrs()
  37.     {
  38.         float lenght = Random.Range(4F, 8F);
  39.         int colorId = Random.Range(1, 5);
  40.         LineItemParametrs lineItem = new LineItemParametrs(lenght, colorId);
  41.  
  42.         return lineItem;
  43.     }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement