Referencing a struct/class From Another Script

I have been developing an inventory system and am curious now on how I should store the actual items. Not looking for a solution for a lazy person or anything, I like to learn.

The way my inventory works so far, is basically a 2D array which has a coordinate that corresponds to the value that is stored in the array parameters.

20894-a.png

20895-b.png

At the moment the boxes only store ints. I want them to store structs or classes that hold the data for objects.
I want to know if I create another script that contains the list of struct/classes that has the objects, could I somehow use that struct/class as a type for the array holding the objects?
Simple example:

//Item script
public class Items : MonoBehaviour {
     struct Item {
          string name;
          int value;
          GameObject item_mesh;
     }

     //List here, etc.     
}


//Inventory script
public class Inventory : MonoBehaviour {
     Item[,] storage; //Item from the Items script
     //rest of inventory stuff here
}

It shouldn’t be a problem as long as both classes are in the same namespace. If not, you’ll have to include the class you want to use in the other script. In your case you would have

using [Namespace].Item;

in your inventory script.

struct Item { … }

That struct is private within Items scope. If the struct were public, you could use it from another class as

Items.Item myItem = new Items.Item();

It might even be nicer to just have the struct outside the scope of the Items class so you can use it as

Item myItem = new Item();

How about something like that:

public enum ItemType {    None, Weapon, Tool, Food, Resource, Construction  }

[System.Serializable]
public class Item {
    public string Name;
    public int ID;
    public string Description;
    public int MaxStack;
    public ItemType Type;
 
    public GameObject ItemPrefab;
    public Texture2D Icon;
}

[System.Serializable]
public class ItemStack
{
    public int Size;
    public Item Item;
}

I wrote something up in the forums for a similar question:

http://forum.unity3d.com/threads/220674-Designing-Inventory-managment-and-Inspector-driven-Item-definition-for-Crafting-Game