using UnityEngine;
using System.Collections.Generic;

public class Register<T> {
    private static Dictionary<int, IRegisterable> items = new Dictionary<int, IRegisterable>();
	
    private static int lastKey = 0;

    public static int RegisterItem(IRegisterable item)
    {
        int thisKey = ++lastKey;
        items.Add(thisKey, item);
        Debug.Log(typeof(T) + " registered");
        return thisKey;
    }

    public static void RegisterItem(int key, IRegisterable item)
    {
		items.Add(key, item);
		Debug.Log (typeof(T) + " registered");
	}
	
	public static void RemoveItem(int key) {
		if(items.ContainsKey(key)) {
			items.Remove(key);
		}
	}

    public static void RemoveAllItems()
    {
        items.Clear();
    }

    public static T GetInstance(int key)
    {
        return (T)items[key];
    }
}
