Best way of doing Item class?

Hello! I want to make a good base-class for items so i can easily add new items and itemTypes. I was wondering if there is a way to access different types of data from an item ID, i’m sorry if i’m bad at explaining, maybe if you look at my code you can understand what i mean and maybe point me in the right direction!

What i want to be able to do is write something like this to access the data:


Is what i’m trying to do possible? Am i doing item classes as good as possible or is there better ways to do it?

using UnityEngine;
using System.Collections;

public class itemInfo : MonoBehaviour {
	public int universalStackLimit;
	public int[] IDs;
	public string[] Names;
	public GameObject[] Models;
	public string[] Types;
	public GUIContent[] IconImages;
	public bool[] stackables;

	public void assignItemData(int ID, string Name, GameObject Model, string itemType, GUIContent IconImage, bool stackable)
		IDs[ID] = ID;
		Names[ID] = Name;
		Models[ID] = Model;
		Types[ID] = itemType;
		IconImages[ID] = IconImage;
		stackables[ID] = stackable;
	public void readItemData(int ID)

You probably want to use a class or a struct for this instead.


struct Item
  public int ID,
  public string Name,
  public Model GameObject,
  public string Type,
  public GUIContent IconImage,
  public bool Stackable

Store the structs in a list using generics…

List<Item> items = new List<Item>();

Add one to the list…

Item item = new Item {
  ID = 10,
  Name = "AnItem",
  Model = someModelReference,
  Type = "Test",
  IconImage = someIconImageReference,
  Stackable = true


And so on. Look up generic arrays and structs for more info. You could also use a class rather than a struct and things would look mostly the same. Depends on your needs.