Search Unity

Inventory Item Database Help

Discussion in 'Scripting' started by chosendeath, Apr 17, 2014.

  1. chosendeath

    chosendeath

    Joined:
    Jun 26, 2013
    Posts:
    20
    So I'm working on creating an Editor GUI for an item database, and the way I have my inventory item system set up is that there are 3 types of items: equipment items, active items, and passive items. Passive items are the base item, and both equipment items and active items extend from the base item. So I need my Editor GUI to be able to distinguish between these types of items.
    So the plan right now for me is to use
    Code (csharp):
    to check the type of the item. Is this bad practice and should I therefore instead cache the item type and use that? Or does anyone know an even better way to make an inventory item system?

    Thanks in advance guys!
     
  2. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    first, I could explain that you can get the types and reference them against eachother...

    Code (csharp):
    1.  
    2. string typeName = "Passive";
    3. if(obj.GetType() == Type.GetType(Passive)) typeName = "Active";
    4. if(obj.GetType() == Type.GetType(Equipment)) typeName = "Equipment";
    5.  
    but a much simpler solution is to add typeName as a public string variable in the class. Then all you have to do is get the string rather than put references to types in scripts.