Search Unity

Sorting items with Category and SubCategory

Discussion in 'Scripting' started by ccgbagnet, Apr 20, 2021.

  1. ccgbagnet

    ccgbagnet

    Joined:
    Oct 3, 2013
    Posts:
    6
    Hello I'm trying to create an Avatar Shop System with items that are sorted by category.

    So far I've made the Category using Enums with Flag attribute going something like this:

    Code (CSharp):
    1. [Flag]
    2. public enum MainCategories
    3. {
    4.     None = 0,
    5.     Hair = 1,
    6.     Top = 2,
    7.     Bottom = 4,
    8.     Shoes = 8,
    9. }
    and then the item just has a "mainCategory" field and when I list all items, I filter based on that field.

    Now I wanted to add subcategories so like the Hair category may be divided into Long Hair, Short Hair, etc. but I'm not sure what's the best way to go.

    I thought of creating a "subCategory" field and make a separate enum for that. But this wouldn't be based on the MainCategories. I hope you can give me some sort of idea on the best way to do this.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,700
    Character customers are some of the most engineering and asset intensive complicated and confusing things possible in the game world. To give yourself the best chance, start from some good tutorials to get ideas of how to simplify stuff. ScriptableObjects are an excellent way to make pre-canned data and have it be generically extensible, but there is still always a ton of work to do with these.
     
    Yoreki likes this.