/*================================================================
Product:    GGJ-2017
Developer:  Onur Tanrıkulu
Company:    Onur Tanrikulu
Date:       21/01/2017 14:37

Copyright (c) 2017 Onur Tanrikulu. All rights reserved.
================================================================*/

using UnityEngine;
using System.Collections.Generic;

public class WaveManager
{
   #region Fields
    private List<GameObject> pool;
    private const int poolAmount = 20;
   #endregion
 
   #region Constructors
    public WaveManager()
    {
        GameObject poolParent = new GameObject("pool");
        pool = new List<GameObject>();

        for (int i = 0; i < poolAmount; i++)
        {
            GameObject go = new GameObject(i.ToString(), typeof(WaveController), typeof(SpriteRenderer));
            CapsuleCollider2D collider = go.AddComponent<CapsuleCollider2D>();
            collider.isTrigger = true;
            collider.offset = new Vector2(-2.1f, 0f);
            collider.size = new Vector2(4f, 4f);
            go.transform.SetParent(poolParent.transform);
            go.SetActive(false);
            pool.Add(go);
        }
    }
   #endregion
 
   #region Properties

   #endregion
 
   #region Methods
    public void CreateWave(Vector2 position, Quaternion rotation)
    {
        for (int i = 0; i < poolAmount; i++)
        {
            GameObject go = pool[i];

            if (!go.activeInHierarchy)
            {
                go.transform.localPosition = position;
                go.transform.localRotation = rotation;
                go.transform.localScale = new Vector2(0.1f, 0.1f);
                go.SetActive(true);

                return;
            }
        }
    }
   #endregion
}
