Since we already have a generic class with a defined type parameter, let's add a non-generic method to see them working together:
- Open up InventoryList and update the code as follows:
public class InventoryList<T>
{
// 1
private T _item;
public T item
{
get { return _item; }
}
public InventoryList()
{
Debug.Log("Generic list initialized...");
}
// 2
public void SetItem(T newItem)
{
// 3
_item = newItem;
Debug.Log("New item added...");
}
}
- Go into GameBehavior and add an item to inventoryList:
public class GameBehavior : MonoBehaviour, IManager
{
// ... No changes needed ...
void Start()
{
Initialize();
InventoryList<string> inventoryList = new
InventoryList<string>();
// 4
inventoryList.SetItem("Potion");
Debug.Log(inventoryList...